Why does the Picoscope DLL keep crashing my program?

Post your VB and VBA discussions here
Post Reply
Ben321
User
User
Posts: 5
Joined: Tue May 23, 2017 8:09 am

Why does the Picoscope DLL keep crashing my program?

Post by Ben321 » Fri Mar 09, 2018 11:45 pm

Ok, I finally figured out how to set up my program in VB6. My code gets the device's handle, etc, and everything works up to the point that it calls the function to start streaming, which is ps2000_run_streaming_ns. But then my program crashes with a Divide By Zero error. The line of code that calls the function is

Code: Select all

If ps2000_run_streaming_ns(hPS2000, 1000, PS2000_Microseconds, 1000, False, 1, 1000) = 0 Then Exit Sub
The parameters I have passed have the following meaning:
the handle to the PS2000 device,
1000 time units per sample (which means 1ms per sample, given that the time unit is us),
the unit is microseconds,
the number of samples to record is 1000 (one second of samples, given that each sample is 1ms) and will be stored in PC memory,
do not use AutoStop,
number of samples to include per aggregate is 1 (in effect, don't use any aggregation, just send me raw samples),
and use a 1000 sample buffer in-hardware (in the Picoscope itself), which I set to be the same as on the PC memory side of the USB transfer, which should make for a smoother transfer.
The function declaration in my program is as follows.

Code: Select all

Private Declare Function ps2000_run_streaming_ns Lib "ps2000.dll" (ByVal Handle As Integer, ByVal SampleInterval As Long, ByVal TimeUnits As Long, ByVal MaxSamples As Long, ByVal AutoStop As Boolean, ByVal NumberOfSamplesPerAgregate As Long, ByVal OverviewBufferSize As Long) As Integer
Note that in VB6, an Integer is the same as a short in C or C++, and a Long in VB6 is the same as an int in C or C++. Note also in VB6 a Boolean is the size of an Integer (short in C), where True is represented by -1 (twos compliment 0xFFFF) and false is represented by 0. I'm not sure what the function is expecting for the value passed to that parameter for True (is it looking for 1 (0x0001) or -1 (0xFFFF)), but it shouldn't matter as I'm setting it to false (which is 0 in all cases).

In any case, after calling this function, an error box pops up saying "Runtime error '11': Division by zero". Obviously my code contains no mathematical operations, such as division by 0. Therefore it seems your DLL's code somewhere is crashing.


Note that my system is Windows 10 64bit, and that I'm using VB6 (a 32bit programming language) to write my program.

Martyn
Site Admin
Site Admin
Posts: 3333
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Why does the Picoscope DLL keep crashing my program?

Post by Martyn » Sat Mar 10, 2018 7:34 am

Can you post your complete code here, or email it to support@picotech.com, I an guessing you may not have set up the channels and matching buffers correctly.
Martyn
Technical Support Manager

Ben321
User
User
Posts: 5
Joined: Tue May 23, 2017 8:09 am

Re: Why does the Picoscope DLL keep crashing my program?

Post by Ben321 » Sat Mar 10, 2018 9:56 am

Martyn wrote:Can you post your complete code here, or email it to support@picotech.com, I an guessing you may not have set up the channels and matching buffers correctly.
Finally got it to work. Internally in VB6, when you use True with type Boolean, what VB6 converts that to is -1 being passed to Signed Short (or what VB6 calls an Integer). I assumed that the Picoscope API accepted any non-zero value as True, and zero as false. It turns out that the Picoscope API functions expect a 1 specifically to be passed for True. So I had to redefine my DLL function declarations to be Integers in VB6, and then pass 1 to represent True. With that done, it now works.


Now that I got it working, I've been experimenting with different buffer size and sample rate combinations in fast streaming mode, to see which combinations work. Unfortunately, it seems that for any very low sample rate (basically anything below 5 samples per second), the fast streaming mode take about several seconds to stop when the ps2000_stop command is issued, up to about 40 seconds required to stoop when the sample rate is set to 1 sample per second (sample duration is set to 1000000 microseconds). It doesn't matter how big or small I set the buffer or overview buffer, or the number of samples to use to generate aggregate data. In all cases, it takes a longer-than-acceptable amount of time for low sample rates.

Post Reply