pico-test.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import numpy as np
  2. from enum import Enum
  3. import socket
  4. import struct
  5. probe = Enum('probe', [('10mV', 0),
  6. ('20mV', 1),
  7. ('50mV', 2),
  8. ('100mV', 3),
  9. ('200mV', 4),
  10. ('500mV', 5),
  11. ('1V', 6),
  12. ('2V', 7),
  13. ('5V', 8),
  14. ('10V', 9),
  15. ('20V', 10),
  16. ('50V', 11),
  17. ('100V', 12),
  18. ('200V', 13)])
  19. # # # # # # # 3 # # # # # #
  20. # CONFIGURATION PARAMETERS #
  21. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  22. # Sample rate in MHz
  23. sample_rate = np.float32(10.0)
  24. # Total measurement time in seconds
  25. total_measure_time = np.float32(0.01)
  26. # Get the number of samples by multiplying sample rate by total measurement time
  27. num_samples = np.uint32(sample_rate * total_measure_time * 1e6)
  28. # Number of channels
  29. nchannels = np.uint32(2)
  30. # Channel ranges in volts, represented as an array of uint8
  31. channel_ranges = np.array([probe['1V'].value, probe['500mV'].value], dtype=np.uint8)
  32. # Number of expected signals
  33. num_trigger = np.uint32(64)
  34. # Trigger direction: 1 for rising edge, 0 for falling edge
  35. trig_dirrection = np.int32(1)
  36. # Trigger pre-measurement time in percentage of the total measurement time
  37. trig_premeasure = np.uint32(100)
  38. # Trigger channel, 0 for channel 1, 1 for channel 2, etc.
  39. trig_channel = np.uint8(0)
  40. # Trigger threshold (0 is 0V and 32767 is max of channel range)
  41. trig_threshold = np.int16(32767)
  42. # Auto trigger time in milliseconds
  43. auto_trigger_time = np.int16(10000)
  44. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  45. # # # # # # # #
  46. # MAIN PROGRAM #
  47. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  48. client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  49. client_socket.settimeout(5.0)
  50. client_socket.connect(('localhost', 5002))
  51. # Open device
  52. msg = struct.pack('<BB', 0xAA, 0x01)
  53. client_socket.sendall(msg)
  54. # Set sample rate
  55. msg = struct.pack('<BBI', 0xAA, 0x07, np.uint32(sample_rate * 1e6))
  56. client_socket.sendall(msg)
  57. # Set number of samples
  58. msg = struct.pack('<BBI', 0xAA, 0x17, num_samples)
  59. client_socket.sendall(msg)
  60. # Configure channels
  61. msg = struct.pack('<BBIsBiHh', 0xAA, 0x09, nchannels, channel_ranges.tobytes(), trig_channel, trig_dirrection, trig_threshold, auto_trigger_time)
  62. client_socket.sendall(msg)
  63. # Set pre-measure time
  64. msg = struct.pack('<BBI', 0xAA, 0x28, trig_premeasure)
  65. client_socket.sendall(msg)
  66. # Set trigger number
  67. msg = struct.pack('<BBI', 0xAA, 0x19, num_trigger)
  68. client_socket.sendall(msg)
  69. # Start measurement
  70. msg = struct.pack('<BB', 0xAA, 0x1B)
  71. client_socket.sendall(msg)