SHARE
TWEET

ps4000

al6675 Jul 25th, 2017 (edited) 37 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PICO__STATUS = {
  2.     0   :   "PICO_OK",  \
  3.     1   :   "PICO_MAX_UNITS_OPENED",    \
  4.     2   :   "PICO_MEMORY_FAIL", \
  5.     3   :   "PICO_NOT_FOUND",   \
  6.     4   :   "PICO_FW_FAIL", \
  7.     5   :   "PICO_OPEN_OPERATION_IN_PROGRESS",  \
  8.     6   :   "PICO_OPERATION_FAILED",    \
  9.     7   :   "PICO_NOT_RESPONDING",  \
  10.     8   :   "PICO_CONFIG_FAIL", \
  11.     9   :   "PICO_KERNEL_DRIVER_TOO_OLD",   \
  12.     10  :   "PICO_EEPROM_CORRUPT",  \
  13.     11  :   "PICO_OS_NOT_SUPPORTED",    \
  14.     12  :   "PICO_INVALID_HANDLE",  \
  15.     13  :   "PICO_INVALID_PARAMETER",   \
  16.     14  :   "PICO_INVALID_TIMEBASE",    \
  17.     15  :   "PICO_INVALID_VOLTAGE_RANGE",   \
  18.     16  :   "PICO_INVALID_CHANNEL", \
  19.     17  :   "PICO_INVALID_TRIGGER_CHANNEL", \
  20.     18  :   "PICO_INVALID_CONDITION_CHANNEL",   \
  21.     19  :   "PICO_NO_SIGNAL_GENERATOR", \
  22.     20  :   "PICO_STREAMING_FAILED",    \
  23.     21  :   "PICO_BLOCK_MODE_FAILED",   \
  24.     22  :   "PICO_NULL_PARAMETER",  \
  25.     23  :   "PICO_ETS_MODE_SET",    \
  26.     24  :   "PICO_DATA_NOT_AVAILABLE",  \
  27.     25  :   "PICO_STRING_BUFFER_TO_SMALL",  \
  28.     26  :   "PICO_ETS_NOT_SUPPORTED",   \
  29.     27  :   "PICO_AUTO_TRIGGER_TIME_TO_SHORT",  \
  30.     28  :   "PICO_BUFFER_STALL",    \
  31.     29  :   "PICO_TOO_MANY_SAMPLES",    \
  32.     30  :   "PICO_TOO_MANY_SEGMENTS",   \
  33.     31  :   "PICO_PULSE_WIDTH_QUALIFIER",   \
  34.     32  :   "PICO_DELAY",   \
  35.     33  :   "PICO_SOURCE_DETAILS",  \
  36.     34  :   "PICO_CONDITIONS",  \
  37.     35  :   "PICO_USER_CALLBACK",   \
  38.     36  :   "PICO_DEVICE_SAMPLING", \
  39.     37  :   "PICO_NO_SAMPLES_AVAILABLE",    \
  40.     38  :   "PICO_SEGMENT_OUT_OF_RANGE",    \
  41.     39  :   "PICO_BUSY",    \
  42.     40  :   "PICO_STARTINDEX_INVALID",  \
  43.     41  :   "PICO_INVALID_INFO",    \
  44.     42  :   "PICO_INFO_UNAVAILABLE",    \
  45.     43  :   "PICO_INVALID_SAMPLE_INTERVAL", \
  46.     44  :   "PICO_TRIGGER_ERROR",   \
  47.     45  :   "PICO_MEMORY",  \
  48.     46  :   "PICO_SIG_GEN_PARAM",   \
  49.     47  :   "PICO_SHOTS_SWEEPS_WARNING",    \
  50.     48  :   "PICO_SIGGEN_TRIGGER_SOURCE",   \
  51.     49  :   "PICO_AUX_OUTPUT_CONFLICT", \
  52.     50  :   "PICO_AUX_OUTPUT_ETS_CONFLICT", \
  53.     51  :   "PICO_WARNING_EXT_THRESHOLD_CONFLICT",  \
  54.     52  :   "PICO_WARNING_AUX_OUTPUT_CONFLICT", \
  55.     53  :   "PICO_SIGGEN_OUTPUT_OVER_VOLTAGE",  \
  56.     54  :   "PICO_DELAY_NULL",  \
  57.     55  :   "PICO_INVALID_BUFFER",  \
  58.     56  :   "PICO_SIGGEN_OFFSET_VOLTAGE",   \
  59.     57  :   "PICO_SIGGEN_PK_TO_PK", \
  60.     58  :   "PICO_CANCELLED",   \
  61.     59  :   "PICO_SEGMENT_NOT_USED",    \
  62.     60  :   "PICO_INVALID_CALL",    \
  63.     61  :   "PICO_GET_VALUES_INTERRUPTED",  \
  64.     63  :   "PICO_NOT_USED",    \
  65.     64  :   "PICO_INVALID_SAMPLERATIO", \
  66.     65  :   "PICO_INVALID_STATE",   \
  67.     66  :   "PICO_NOT_ENOUGH_SEGMENTS", \
  68.     67  :   "PICO_DRIVER_FUNCTION", \
  69.     68  :   "PICO_RESERVED",    \
  70.     69  :   "PICO_INVALID_COUPLING",    \
  71.     70  :   "PICO_BUFFERS_NOT_SET", \
  72.     71  :   "PICO_RATIO_MODE_NOT_SUPPORTED",    \
  73.     72  :   "PICO_RAPID_NOT_SUPPORT_AGGREGATION",   \
  74.     73  :   "PICO_INVALID_TRIGGER_PROPERTY",    \
  75.     74  :   "PICO_INTERFACE_NOT_CONNECTED", \
  76.     75  :   "PICO_RESISTANCE_AND_PROBE_NOT_ALLOWED",    \
  77.     76  :   "PICO_POWER_FAILED",    \
  78.     77  :   "PICO_SIGGEN_WAVEFORM_SETUP_FAILED",    \
  79.     78  :   "PICO_FPGA_FAIL",   \
  80.     79  :   "PICO_POWER_MANAGER",   \
  81.     80  :   "PICO_INVALID_ANALOGUE_OFFSET", \
  82.     81  :   "PICO_PLL_LOCK_FAILED", \
  83.     82  :   "PICO_ANALOG_BOARD",    \
  84.     83  :   "PICO_CONFIG_FAIL_AWG", \
  85.     84  :   "PICO_INITIALISE_FPGA", \
  86.     86  :   "PICO_EXTERNAL_FREQUENCY_INVALID",  \
  87.     87  :   "PICO_CLOCK_CHANGE_ERROR",  \
  88.     88  :   "PICO_TRIGGER_AND_EXTERNAL_CLOCK_CLASH",    \
  89.     89  :   "PICO_PWQ_AND_EXTERNAL_CLOCK_CLASH",    \
  90.     90  :   "PICO_UNABLE_TO_OPEN_SCALING_FILE", \
  91.     91  :   "PICO_MEMORY_CLOCK_FREQUENCY",  \
  92.     92  :   "PICO_I2C_NOT_RESPONDING",  \
  93.     93  :   "PICO_NO_CAPTURES_AVAILABLE",   \
  94.     94  :   "PICO_NOT_USED_IN_THIS_CAPTURE_MODE",   \
  95.     259 :   "PICO_GET_DATA_ACTIVE", \
  96.     260 :   "PICO_IP_NETWORKED",    \
  97.     261 :   "PICO_INVALID_IP_ADDRESS",  \
  98.     262 :   "PICO_IPSOCKET_FAILED", \
  99.     263 :   "PICO_IPSOCKET_TIMEDOUT",   \
  100.     264 :   "PICO_SETTINGS_FAILED", \
  101.     265 :   "PICO_NETWORK_FAILED",  \
  102.     266 :   "PICO_WS2_32_DLL_NOT_LOADED",   \
  103.     267 :   "PICO_INVALID_IP_PORT", \
  104.     268 :   "PICO_COUPLING_NOT_SUPPORTED",  \
  105.     269 :   "PICO_BANDWIDTH_NOT_SUPPORTED", \
  106.     270 :   "PICO_INVALID_BANDWIDTH",   \
  107.     271 :   "PICO_AWG_NOT_SUPPORTED",   \
  108.     272 :   "PICO_ETS_NOT_RUNNING", \
  109.     273 :   "PICO_SIG_GEN_WHITENOISE_NOT_SUPPORTED",    \
  110.     274 :   "PICO_SIG_GEN_WAVETYPE_NOT_SUPPORTED",  \
  111.     275 :   "PICO_INVALID_DIGITAL_PORT",    \
  112.     276 :   "PICO_INVALID_DIGITAL_CHANNEL", \
  113.     277 :   "PICO_INVALID_DIGITAL_TRIGGER_DIRECTION",   \
  114.     278 :   "PICO_SIG_GEN_PRBS_NOT_SUPPORTED",  \
  115.     279 :   "PICO_ETS_NOT_AVAILABLE_WITH_LOGIC_CHANNELS",   \
  116.     280 :   "PICO_WARNING_REPEAT_VALUE",    \
  117.     281 :   "PICO_POWER_SUPPLY_CONNECTED",  \
  118.     282 :   "PICO_POWER_SUPPLY_NOT_CONNECTED",  \
  119.     283 :   "PICO_POWER_SUPPLY_REQUEST_INVALID",    \
  120.     284 :   "PICO_POWER_SUPPLY_UNDERVOLTAGE",   \
  121.     285 :   "PICO_CAPTURING_DATA",  \
  122.     286 :   "PICO_USB3_0_DEVICE_NON_USB3_0_PORT",   \
  123.     287 :   "PICO_NOT_SUPPORTED_BY_THIS_DEVICE",    \
  124.     288 :   "PICO_INVALID_DEVICE_RESOLUTION",   \
  125.     289 :   "PICO_INVALID_NUMBER_CHANNELS_FOR_RESOLUTION",  \
  126.     290 :   "PICO_CHANNEL_DISABLED_DUE_TO_USB_POWERED", \
  127.     291 :   "PICO_SIGGEN_DC_VOLTAGE_NOT_CONFIGURABLE",  \
  128.     292 :   "PICO_NO_TRIGGER_ENABLED_FOR_TRIGGER_IN_PRE_TRIG",  \
  129.     293 :   "PICO_TRIGGER_WITHIN_PRE_TRIG_NOT_ARMED",   \
  130.     294 :   "PICO_TRIGGER_WITHIN_PRE_NOT_ALLOWED_WITH_DELAY",   \
  131.     295 :   "PICO_TRIGGER_INDEX_UNAVAILABLE",   \
  132.     296 :   "PICO_AWG_CLOCK_FREQUENCY", \
  133.     297 :   "PICO_TOO_MANY_CHANNELS_IN_USE",    \
  134.     298 :   "PICO_NULL_CONDITIONS", \
  135.     299 :   "PICO_DUPLICATE_CONDITION_SOURCE",  \
  136.     300 :   "PICO_INVALID_CONDITION_INFO",  \
  137.     301 :   "PICO_SETTINGS_READ_FAILED",    \
  138.     302 :   "PICO_SETTINGS_WRITE_FAILED",   \
  139.     303 :   "PICO_ARGUMENT_OUT_OF_RANGE",   \
  140.     304 :   "PICO_HARDWARE_VERSION_NOT_SUPPORTED",  \
  141.     305 :   "PICO_DIGITAL_HARDWARE_VERSION_NOT_SUPPORTED",  \
  142.     306 :   "PICO_ANALOGUE_HARDWARE_VERSION_NOT_SUPPORTED", \
  143.     307 :   "PICO_UNABLE_TO_CONVERT_TO_RESISTANCE", \
  144.     308 :   "PICO_DUPLICATED_CHANNEL",  \
  145.     309 :   "PICO_INVALID_RESISTANCE_CONVERSION",   \
  146.     310 :   "PICO_INVALID_VALUE_IN_MAX_BUFFER", \
  147.     311 :   "PICO_INVALID_VALUE_IN_MIN_BUFFER", \
  148.     312 :   "PICO_SIGGEN_FREQUENCY_OUT_OF_RANGE",   \
  149.     313 :   "PICO_EEPROM2_CORRUPT", \
  150.     314 :   "PICO_EEPROM2_FAIL",\
  151. }
  152.  
  153.  
  154. PicoInfo = {\
  155.     0 : " PICO_DRIVER_VER      ",\
  156.     1 : " PICO_USB_VER         ",\
  157.     2 : " PICO_HW_VER          ",\
  158.     3 : " PICO_VARIANT_INFO    ",\
  159.     4 : " PICO_BATCH_AND_SERIAL",\
  160.     5 : " PICO_CAL_DATE        ",\
  161.     6 : " PICO_KERNEL_VERSION  ",\
  162.     7 : " DIGITAL_HW_VER, N/A  ",\
  163.     8 : " DIGITAL_SW_VER, N/A  ",\
  164.     9 : " PICO_FW_VER_1        ",\
  165.     10: "PICO_FW_VER_2        "\
  166.     }
  167.  
  168.  
  169. ENABLED = True
  170. DISABLED = False
  171. DC = True
  172. AC = False
  173.  
  174. PS4000_CHANNEL_A = 0
  175. PS4000_CHANNEL_B = 1
  176. PS4000_CHANNEL_C = 2
  177. PS4000_CHANNEL_D = 3
  178.  
  179. PS4000_10MV = 0
  180. PS4000_20MV = 1
  181. PS4000_50MV = 2
  182. PS4000_100MV = 3
  183. PS4000_200MV = 4
  184. PS4000_500MV = 5
  185. PS4000_1V = 6
  186. PS4000_2V = 7
  187. PS4000_5V = 8
  188. PS4000_10V = 9
  189. PS4000_20V = 10
  190. PS4000_50V = 11
  191. PS4000_100V = 12
  192.  
  193. from ctypes import *
  194. PS4000_FS = c_uint32(0)
  195. PS4000_PS = c_uint32(1)
  196. PS4000_NS = c_uint32(2)
  197. PS4000_US = c_uint32(3)
  198. PS4000_MS = c_uint32(4)
  199. PS4000_S = c_uint32(5)
  200.  
  201. ABOVE               = 0
  202. BELOW               = 1
  203. RISING              = 2
  204. FALLING             = 3
  205. RISING_OR_FALLING   = 4
  206. ABOVE_LOWER         = 5
  207. BELOW_LOWER         = 6
  208. RISING_LOWER        = 7
  209. FALLING_LOWER       = 8
  210.  
  211.  
  212. TRIG_NOT_ENABLED = c_int16(0)
  213. TRIG_ENABLED     = c_int16(1)
  214.  
  215.  
  216. from time import sleep
  217.  
  218. import ctypes
  219. from ctypes import c_int32 as c_enum
  220. import os
  221. import time
  222. import sys
  223.  
  224.  
  225. # pico dll
  226. os.chdir("F:\\Picoscope\\ctrlpascal\\")
  227. DLL   = ctypes.WinDLL("ps4000.dll")
  228.  
  229. # global variables
  230. # system setup
  231. handle = c_short(0)
  232. pSTAT  = c_long()
  233.  
  234. # flags
  235. gf_ready      = bool(False)
  236. gf_streaming  = bool(False)
  237.  
  238.  
  239. g_index       = 0
  240.  
  241. # sampling/streaming
  242. g_sampleInterval = c_ulong(500)
  243. g_sampleCount    = c_int32(10000)
  244.  
  245.  
  246. #g_ReadySampleCount = c_short(0)
  247. g_ReadySampleCount = 0
  248. g_callbackhandle   = c_short(0)
  249. g_startIndex       = c_uint(0)
  250. g_overflow         = c_short(0)
  251. g_triggerAt        = c_uint(0)
  252. g_triggered        = c_short(0)
  253. g_autoStop         = c_short(0)
  254. g_parameter        = c_uint(0)            
  255.  
  256. # buffers
  257. MAX_BUF_SIZE    = 1000
  258. tmp_buf_A       = (c_short * MAX_BUF_SIZE)(0)
  259. buf_A           = (c_short * MAX_BUF_SIZE)(0)
  260.  
  261. # for debugging
  262. irq_counter = 0
  263.  
  264.  
  265. # Output filename
  266. f_path = "F:\\apo\\Picoscope\\ctrlpascal\\"
  267. f_name = "picodat1.txt"
  268. FILENAME = f_path + f_name
  269.  
  270.  
  271. ###############################################################################################
  272. def picostatus(st):
  273.     for i in PICO__STATUS:
  274.         if st == i:
  275.             return PICO__STATUS[st]
  276.     return "***Error: Device returned UNKNOWN status ***"
  277.  
  278.  
  279.  
  280. ###############################################################################################
  281. def GetDeviceInfo():
  282.  
  283.     print('\ndoing TryGettingInfo')
  284.     requiredSize = c_int16(0)   #: SmallInt
  285.     RInfo        = c_int()      #: PICO_INFO
  286.     HadFailure   = bool(False)
  287.     MyReturnStr = create_string_buffer(15)
  288.  
  289.     print('pico Handle: ', handle)
  290.     for RInfo in range(0,10+1):
  291.         if RInfo == 7 or RInfo == 8: continue
  292.         print('doing GetUnitInfo: ', end='')
  293.         ST = DLL.ps4000GetUnitInfo(handle, byref(MyReturnStr), \
  294.                                     c_int16(len(MyReturnStr)), byref(requiredSize), RInfo)
  295.         print(RInfo, PicoInfo[RInfo], ': ', end='')
  296.         if ST == 0:
  297.             print(MyReturnStr.value, (13-len(MyReturnStr.value))*' ', picostatus(ST))
  298.         else:
  299.             HadFailure = True
  300.             print(hex(ST), 8*' ', picostatus(ST))
  301.  
  302.     return not HadFailure
  303.  
  304.  
  305. ###############################################################################################
  306. # result type as first argument:
  307. callback = CFUNCTYPE(None, c_short, c_int, c_uint, c_short, c_uint, c_short, c_short, c_void_p)
  308.  
  309. ###############################################################################################
  310. def callback_py(callbackhandle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, parameter):
  311.     global gf_ready
  312.     global gf_streaming
  313.     global g_ReadySampleCount
  314.  
  315.     global g_callbackhandle
  316.     global g_startIndex
  317.     global g_overflow
  318.     global g_triggerAt
  319.     global g_triggered
  320.     global g_autoStop
  321.     global g_parameter
  322.  
  323.     # indicate that data packet is ready
  324.     gf_ready = True
  325.     g_ReadySampleCount = noOfSamples
  326.  
  327.     # identifies the scope device returning the samples
  328.     g_callbackhandle = callbackhandle
  329.  
  330.     # indicate if and where a trigger has occured
  331.     g_triggerAt = triggerAt
  332.     g_triggered = triggered
  333.  
  334.     # set of flags that indicate whether an overvoltage has occurred on any of the channels
  335.     g_overflow = overflow
  336.  
  337.     # index to the first valid sample in the buffer.
  338.     g_startIndex = startIndex
  339.  
  340.     # as set in ps4000_RunStreaming()
  341.     g_autoStop = autoStop
  342.     print("\n======> autoStop", g_autoStop, autoStop)
  343.    
  344.     # the  pointer passed from ps4000_GetStreamingLatestValues()
  345.     g_parameter = parameter
  346.     #print(hex(g_parameter), g_parameter)
  347.    
  348.     ### for debugging
  349.     print("callbackhandle =", g_callbackhandle, "   g_ReadySampleCount =", g_ReadySampleCount, \
  350.                  "   startIndex =", g_startIndex, "   overflow =", g_overflow, "   triggerAt =", g_triggerAt, \
  351.                  "   triggered =", g_triggered, "   autoStop =", g_autoStop, "   parameter =", g_parameter)
  352.  
  353.    
  354.     # copy tmp_buf to application buf
  355.     if g_ReadySampleCount:
  356.         print("--->", g_ReadySampleCount)
  357.         for i in range(0,g_ReadySampleCount):
  358.             buf_A[i] = tmp_buf_A[i]
  359.         for i in range(0,10):
  360.             print (i, buf_A[i], tmp_buf_A[i], sep = '__' )
  361.  
  362.     print('\nEntered callback_py, got {} samples: \n'.format(g_ReadySampleCount))
  363.    
  364.     #return
  365.  
  366.  
  367. ###############################################################################################
  368. call_back = callback(callback_py)
  369.  
  370.  
  371.  
  372.  
  373. ###############################################################################################
  374. def StreamingChannelsSetup(active_channels):
  375.  
  376.     chan_A = bool(False)
  377.     chan_B = bool(False)
  378.     chan_C = bool(False)
  379.     chan_D = bool(False)
  380.  
  381.     for chan in active_channels:          
  382.         if chan == 'A':
  383.             ST = DLL.ps4000SetChannel(handle, PS4000_CHANNEL_A, ENABLED, AC, PS4000_10V)
  384.             if ST: print("Error Returned: ", picostatus(ST), "while setting channel A -> ON")
  385.             chan_A = True
  386.        
  387.         if chan == 'B':
  388.             ST = DLL.ps4000SetChannel(handle, PS4000_CHANNEL_B, ENABLED, AC, PS4000_10V)
  389.             if ST: print("Error Returned: ", picostatus(ST), "while setting channel B -> ON")
  390.             chan_B = True
  391.        
  392.         if chan == 'C':
  393.             ST = DLL.ps4000SetChannel(handle, PS4000_CHANNEL_C, ENABLED, AC, PS4000_10V)
  394.             if ST: print("Error Returned: ", picostatus(ST), "while setting channel C -> ON")
  395.             chan_C = True
  396.        
  397.         if chan == 'D':
  398.             ST = DLL.ps4000SetChannel(handle, PS4000_CHANNEL_D, ENABLED, AC, PS4000_10V)
  399.             if ST: print("Error Returned: ", picostatus(ST), "while setting channel D -> ON")
  400.             chan_D = True
  401.    
  402.  
  403.  
  404.  
  405.  
  406.  
  407. ###############################################################################################
  408. def DataStreamingSetup():
  409.     global g_sampleCount
  410.     global handle
  411.     global buf_A
  412.  
  413.     print('\nInto DataStreamingSetup')
  414.     # sampleTime = c_int() # *** check
  415.  
  416.     # setup Channels:  A->ON, BCD->OFF
  417.     ST = DLL.ps4000SetChannel(handle, PS4000_CHANNEL_A, ENABLED, AC, PS4000_10V)
  418.     if ST: print("Error Returned: ", picostatus(ST), "while setting channel A -> ON")
  419.     ST = DLL.ps4000SetChannel(handle, PS4000_CHANNEL_B, DISABLED, DC, PS4000_10V)
  420.     if ST: print("Error Returned: ", picostatus(ST), "while setting channel B -> OFF")
  421.     ST = DLL.ps4000SetChannel(handle, PS4000_CHANNEL_C, DISABLED, DC, PS4000_10V)
  422.     if ST: print("Error Returned: ", picostatus(ST), "while setting channel C -> OFF")
  423.     ST = DLL.ps4000SetChannel(handle, PS4000_CHANNEL_D, DISABLED, DC, PS4000_10V)
  424.     if ST: print("Error Returned: ", picostatus(ST), "while setting channel D -> OFF")
  425.  
  426.  
  427.     # clear trigger mode
  428.     trig_threshold  = c_int16(5)
  429.     trig_delay      = c_uint32(0)
  430.     autoTrigger_ms  = c_int16(1)
  431.  
  432.     # Simple Trigger    
  433.     ST = DLL.ps4000SetSimpleTrigger(handle, TRIG_NOT_ENABLED, PS4000_CHANNEL_A, \
  434.                                                     trig_threshold, ABOVE, trig_delay, autoTrigger_ms)
  435.     if ST: print ("Error: ", picostatus(ST), "while doing SetSimpleTrigger(Channel_A)")
  436.  
  437.  
  438.     # set up buffer for Channel A
  439.     g_sampleCount = 120
  440.     #ST = DLL.ps4000SetDataBuffer(handle, PS4000_CHANNEL_A, byref(tmp_buf_A), g_sampleCount)
  441.     ST = DLL.ps4000SetDataBuffer(handle, PS4000_CHANNEL_A, tmp_buf_A, g_sampleCount)
  442.     if ST: print("Error: ", picostatus(ST), "while doing SetDataBuffers(Channel_A)")
  443.  
  444.    
  445.     print('Setup is done, now will exec RunStreaming')
  446.  
  447.  
  448.  
  449. ###############################################################################################
  450. def StartDataStreaming():
  451.     global handle
  452.     global g_sampleInterval
  453.  
  454.     # start streaming
  455.     ST = DLL.ps4000RunStreaming(handle, byref(g_sampleInterval), PS4000_US, \
  456.                                     c_uint32(0), c_uint32(120) , c_int16(1), c_uint32(1), g_sampleCount)
  457.     print("RunStreaming() ->", picostatus(ST), "handle: ", handle)
  458.  
  459.  
  460.  
  461. ###############################################################################################
  462. def do_while_streaming():
  463.     '''
  464.    Runs continuously after having started the streamning procedure until autostop is triggered or '!' is pressed
  465.    When new data are available through the callback function, it will append them to the output file
  466.    '''
  467.     global handle
  468.     global F    
  469.     global gf_ready
  470.     global g_index
  471.     global g_control
  472.  
  473.  
  474.     g_index = 0
  475.     total_samples = 0                   # holds total no of samples acquired
  476.  
  477.     while not g_autoStop:           # g_autostop <= 0
  478.         gf_ready = False
  479.  
  480.         print('+',sep='',end='')
  481.        
  482.         ST = DLL.ps4000GetStreamingLatestValues(handle, call_back, None)
  483.        
  484.         # sleep(1)
  485.         print(ST,end='')
  486.        
  487.         g_index += 1
  488.         print('_',g_index, sep='',end='')
  489.  
  490.        
  491.         if g_ReadySampleCount > 0:
  492.         # received data from callback
  493.             print ("=> g_ReadySampleCount is :", g_ReadySampleCount)
  494.             if gf_ready:                    # ---> to merge in one if statement
  495.                 total_samples += g_ReadySampleCount
  496.                 print("collected {} samples, index = {}, Total: {} samples".format(g_sampleCount, g_startIndex, total_samples))
  497.  
  498.                 if F.closed:
  499.                     print("File is not open for writing.-")
  500.                 else:
  501.                     print ("******---------*********")
  502.                     for i in range(total_samples-g_ReadySampleCount, total_samples):
  503.                         print (i)
  504.                         print(buf_A[i])
  505.                         F.write(i + '\t' + str(buf_A[i]) + '\n')
  506.                        
  507.                         if i in range (total_samples-g_ReadySampleCount,total_samples-g_ReadySampleCount+10):
  508.                             print(tmp_buf_A[i], buf_A[i])
  509.                
  510.                 gf_ready = False
  511.    
  512.     if not F.closed:        
  513.         F.close()
  514.    
  515.    
  516.        
  517.     print(">>>> [3] >>> end of do_while_Streaming()")
  518.  
  519.  
  520.  
  521. ###############################################################################################
  522. #
  523. #            Main function
  524. #
  525. ###############################################################################################
  526. if __name__ == '__main__':
  527.     print(DLL)
  528.  
  529.     # open file to write into
  530.     F = open(FILENAME, 'w')
  531.     current_time = time.asctime(time.localtime(time.time()))
  532.     F.write("Captured values, time is : " + current_time + "\n")
  533.     print("========================== Captured values, time is : ", current_time, "========================== ")
  534.    
  535.     print()
  536.     print('doing OpenUnit')
  537.     pSTAT = DLL.ps4000OpenUnit(byref(handle))
  538.     if pSTAT:
  539.         print('OpenUnit failed, status=', picostatus(pSTAT), ' handle=', handle)
  540.     else:
  541.         print('OpenUnit ok, handle =', handle)
  542.         if GetDeviceInfo():
  543.             DataStreamingSetup()
  544.             StartDataStreaming()
  545.             do_while_streaming()
  546.  
  547.             F.close()      
  548.             if F.closed: print("-->>> File", FILENAME ," was closed!!! ")  
  549.             else:        print("-->>> Could not close FILE")
  550.  
  551.             print('>>> doing ps4000Stop')
  552.             pSTAT = DLL.ps4000Stop(handle)
  553.             print(">>> ps4000Stop() returned: ", picostatus(pSTAT))
  554.  
  555.             print('>> doing CloseUnit')
  556.             pSTAT = DLL.ps4000CloseUnit(handle)
  557.             if pSTAT == 0: print('>> CloseUnit ok')
  558.             else: print('>> CloseUnit failed, status=', picostatus(pSTAT), ' handle=', handle)
  559.             print("-------- END OF APPLICATION --------")
  560.  
  561.         else:
  562.             print("********** Could not get device info - Streaming will not start **********")
  563.             print("********** Application will now exit with error-code 1 **********")
  564.             sys.exit(1)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top