Getting started example Excel code 3406DMSO

Post your VB and VBA discussions here
davewilliams
Newbie
Posts: 0
Joined: Wed Feb 10, 2016 9:28 pm

Getting started example Excel code 3406DMSO

Post by davewilliams »

Hello,

I'm having a problem getting started with the example VBA spreadsheet.

I have a Picoscope 3406DMSO, I'm using SDK version: "PicoSDK_64_10.6.10.22.exe" running Excel (Office 365) on Windows 10.

I have tried the following:

- Running the code in C:\PicoSDK\PS3000\ExcelPS3000.xls, I get the message-box error: "Unit not opened"
- Clickling "Get Block" in C:\PicoSDK\PS3000A\Excel\PS3000aV2.xlsm and also C:\PicoSDK\PS3000A\Excel\PS3000aV2_x64.xlsm
The debugger returns the error "File not found ps3000aWrap.dll"
The spreadsheet does get populated with "PS3000a Device Opened" and the table says Driver 1.4.5.43, USB version 3, Hardware version 1, Variant 3406DMSO, Batch/Serial CQ921/110, Cal date 05-Oct-15, Kernel version 1, Digital H/W Ver. 1, Analogue H/W/ Ver. 1), and it reports that the
The debugger says it failed on on this line: status = initWrapUnitInfo(handle, deviceIndex).
I placed the following into both C:\Windows\SysWOW64\ and C:\Windows\System32\ (from C:\Program Files\Pico Technology\SDK\lib)
- ps3000a.dll and .lib,
- ps3000aWrap.dll and .lib,
- ps3000.dll and .lib,
- ps3000Wrap.dll and .lib
- picoipp.dll

So...I'm stuck, please could you suggest something? At least the PS3000aV2.clsm communicates, even though the 'scope is a 3406DMSO (ie not an A series).

Hope you can help?

Dave

Hitesh

Re: Getting started example Excel code 3406DMSO

Post by Hitesh »

Hi Dave,

If you are using a 32-bit version of Microsoft Excel (verify this from via the File menu) then you will need to use the 32-bit SDK installer which will provide 32-bit versions of the ps3000a, picoipp and ps3000aWrap dll files.

The PS3000aV2.xlsm file is the correct one to use as the PicoScope 3000D and 3000D MSO products use the API functions provided by the ps3000a driver.

You will also require the Visual C++ 2010 Redistributable x86 version if that is the case, although this should be installed by the 32-bit SDK installer.

Have you tried copying the ps3000aWrap.dll file to the C:\Windows\System32 folder if it is a 64-bit version of Excel?

Regards,

davewilliams
Newbie
Posts: 0
Joined: Wed Feb 10, 2016 9:28 pm

Re: Getting started example Excel code 3406DMSO

Post by davewilliams »

Thanks very much Hitesh, the Picoscope 3406DMSO now works!

Task manager reported that my Excel/Office 365 in Windows 10 is running 32 bit, so I installed the 32-bit Picoscope SDK as you suggested and it now works.
Just so anyone else reading the forum knows, the files are in a slightly different place, I copied picoipp.dll, ps3000a.dll, ps3000aWrap.dll from C:\Program Files (x86)\Pico Technology\SDK\lib to C:\Windows\System32.
Then you must reboot (before I rebooted, the previous error persisted).

Thanks again, Hitesh!

Dave

Hitesh

Re: Getting started example Excel code 3406DMSO

Post by Hitesh »

Hi Dave,

Good to hear that worked :D

The location where the driver files are installed to is added to the Windows PATH environment variable so it should be possible for the macro to pick up the drivers in that location.

Regards,

davewilliams
Newbie
Posts: 0
Joined: Wed Feb 10, 2016 9:28 pm

Re: Getting started example Excel code 3406DMSO

Post by davewilliams »

Hi Hitesh,

Thanks, I'm afraid this problem was only solved for a while, I'm still having a few problems, hope you can help?

I wrote my own spreadsheet (attached) based very closely on PS3000aV2.xlsm.
This program is giving strange results and your PS3000aV2.xlsm now crashes when run.

I cannot get the unit to properly exit from ps3000ASetSimpleTrigger(). Upon exiting ps3000aSetSimpleTrigger() the IsReady() function only returns zero saying that the device is never ready again.

Also, I'm using the document PicoScope3000SeriesAApiProgrammersGuide.pdf for reference, this tells me the enumerated value names but doesn't tell me the values that they are enumerated to, should I be reading a different document?
The example gives the voltage range 8 to be ±5V, does this mean that the range of values is 2 to 10? In the attached spreadsheet, I am using the following line to determine the range of the number that's passed (from cell C40) is this correct?

=IF(C40=2,"±50 mV", IF(C40=3,"±100 mV",IF(C40=4,"±200 mV",IF(C40=5,"±500 mV",IF(C40=6,"±1 V",IF(C40=7,"±2 V",IF(C40=8,"±5 V",IF(C40=9,"±10 V",IF(C40=10,"±20 V")))))))))

After ps3000aGetValues() the returned status value is 37, I don't know if that helps.

To run my spreadsheet program, after looking at the values please click on the buttons in order, 1) Clears the values in the table that are populated by VBA, 2) gets the scope data, then scroll so that the count is visible (ie row 80 is on the screen) then press 3) to get the data.

Hope you can help?

David
Attachments
14-Feb-16_ReadingData_J.xlsm
Based closely on PS3000aV2.xlsm
(67.67 KiB) Downloaded 681 times

Hitesh

Re: Getting started example Excel code 3406DMSO

Post by Hitesh »

Hi Dave,

Looking at your code, it appears to be missing the call to the RunBlock() function in the wrapper dll (which in turn calls the driver's ps3000aRunBlock() function) after the call to ps3000aSetSimpleTrigger().

It is the ps3000aRunBlock() function that causes the channel and trigger settings to be written down to the device and sets it collecting data (waiting for a trigger event if required).

With regards to enumeration values, these are defined in the ps3000aApi.h header file (installed to the C:\Program Files (x86)\Pico Technology\SDK\inc directory). Typically, the first enumeration value defined in a set corresponds to 0 unless defined otherwise so for the PS3000A_RANGE enumerations:

Code: Select all

typedef enum enPS3000ARange
{
  PS3000A_10MV,
  PS3000A_20MV,
  PS3000A_50MV,
  PS3000A_100MV,
  PS3000A_200MV,
  PS3000A_500MV,
  PS3000A_1V,
  PS3000A_2V,
  PS3000A_5V,
  PS3000A_10V,
  PS3000A_20V,
  PS3000A_50V,
  PS3000A_MAX_RANGES,
} PS3000A_RANGE;
The first entry corresponds to 0 (although the +/-10mV range is not supported, it makes the definition consistent with our other drivers) and the +/-20mV range is 1 and so on (the +/-2V range is 7).

With regards to the error status code values returned, these are defined in the PicoStatus.h header file as hexadecimal values so 37 is 0x25 (PICO_NO_SAMPLES_AVAILABLE). This is correct as no samples are available given that the ps3000aRunBlock() function was not called.

I hope this helps.

Regards,

davewilliams
Newbie
Posts: 0
Joined: Wed Feb 10, 2016 9:28 pm

Re: Getting started example Excel code 3406DMSO

Post by davewilliams »

Thanks very much Hitesh, that was immensely helpful.

Attached is the updated code which now works, the worksheet "Chart" shows a 1MHz sine wave and 100kHz sawtooth that I captured (I only plot the first 5000 datapoints to save on spreadsheet space, the acquisition size was 1,001,000 points, I was testing long captures and pre and post-trigger data points).

Included in this spreadsheet is a function, picoscope_status(), which provides the status string, I thought that might be useful to someone.

I have a much more minor problem now and I wonder if you might be able to suggest a solution?

Presently I cannot gracefully recover from a status=3 (PICO_NOT_FOUND). I need to close excel in order to get excel to see the scope again. When I do, it crashes. I now check for status=3 and do not attempt to call ps3000agetUnitInfo() if a status=3 was reported, but the problem persists.

I have noticed the following:
After a status=3, if I unplug the USB plug to the scope then the computer makes a decending-pitch 3-note sound. If I plug it in again it makes an ascending-pitch 3-note sound, as you might expect. Then, when I next try to call ps3000aOpenUnit() with my 'Verify communications' button, the decending-pitch 3-note sound is made again and the scope then reports status 3.

It's a minor point, but if you could suggest a more graceful way to recover from a status=3 (PICO_NOT_FOUND) than having to use task manager to close excel, that would be very nice.

Thanks again for your very helpful answers!

Dave

Attached, code that successfully acquires a trace from the 3406DSMO, it includs picoscope_status() that converts from a status number into text.
Attachments
16-Feb-16_ReadingData_L_pre_and_post.xlsm
Working program.
(297.07 KiB) Downloaded 750 times

Hitesh

Re: Getting started example Excel code 3406DMSO

Post by Hitesh »

Hi Dave,

Are you connecting the PicoScope 3406D MSO via a USB 3.0 cable to a USB 3.0 port or are you using a single/dual-headed USB cable to a USB 2.0 port? Is the power adaptor being used?

I ran your example with Excel 2013 and I've not been able to get it to lock-up so I am wondering as to the cause of the device not being detected.

When you try to call ps3000aOpenUnit() does the device disappear and reappear in the Windows Device Manager?

Regards,

davewilliams
Newbie
Posts: 0
Joined: Wed Feb 10, 2016 9:28 pm

Re: Getting started example Excel code 3406DMSO

Post by davewilliams »

Thanks very much for checking this out Hitesh!

The device does not disappear and reappear in the USB devices list. However, I checked this a lot of times and I previously noted the audible beeps, when I retried the computer made no such beeps, so the behaviour has changed a little, I don't know why.

I believe that my program is causing the problem, i.e. I believe this is user error (my fault). The excel crashing behavior occurs when I click on "verify communication" several times and also if I click on another button without first clicking on "verify communications".

I suspect I am not being thorough enough about opening and closing the connection to the device, and that is the root cause of my problems.

I'll repost when I have figured out what I have done wrong.

Thanks for checking it out!

Yours

David

Hitesh

Re: Getting started example Excel code 3406DMSO

Post by Hitesh »

Hi Dave,

If you manage to narrow down the cause, please post back here.

Thanks,

davewilliams
Newbie
Posts: 0
Joined: Wed Feb 10, 2016 9:28 pm

Re: Getting started example Excel code 3406DMSO

Post by davewilliams »

Thanks Hitesh, yes, I'll do that.
Dave

davewilliams
Newbie
Posts: 0
Joined: Wed Feb 10, 2016 9:28 pm

Re: Getting started example Excel code 3406DMSO

Post by davewilliams »

Hi Hitesh,

I believe the problem of excel crashing is solved:

When I first communicate I do:
status = ps3000aOpenUnit(handle, 0)
deviceIndex = 0
status = initWrapUnitInfo(handle, deviceIndex)

When I exit I must do:
status = decrementDeviceCount(deviceIndex)
Call ps3000aCloseUnit(handle)
status = resetNextDeviceIndex()

If my program exists without calling the three functions and just start communicating again, then I find that eventually excel will crash (I'm using 32 bit Excel for Office 365 running on Windows 10). In the previously attached excel program, if I click "verify communication" enough times, it will crash.

So, this happened a fair amount when debugging, because each time it exits by crashing, it isn't exiting gracefully. When trapping errors, I'm careful to run those three exit commands.

Yours,

Dave

Hitesh

Re: Getting started example Excel code 3406DMSO

Post by Hitesh »

Hi Dave,

The wrapper dll for the PicoScope 3000 Series using the ps3000a driver was changed a while back to support up to a maximum of 4 devices (particularly to deal with cases of multiple units collecting data in streaming mode).

Once a device is disconnected, the decrementDeviceCount() function should be called, and when the exiting the application, the resetNextDeviceIndex() should be called.

You can find descriptions of each function in the Programmer's Guide or in the ps3000aWrap.c source code file located in the src\PS3000A\C wrapper folder in the SDK installation directory.

Regards,

davewilliams
Newbie
Posts: 0
Joined: Wed Feb 10, 2016 9:28 pm

Re: Getting started example Excel code 3406DMSO

Post by davewilliams »

Thanks Hitesh,

Here's a few more details on the crashing behavior...

While programming, after a crash in VBA (caused by an error in my program), you enter the debugger. You still have control over the spreadsheet, so you can save the file, it is the act of "resetting the debugger" (which you need to do before you can re-run the code) that causes excel to hang and need to be restarted.

I'm not so sure that a fix exists, but I'd certainly be interested if anyone knows a remedy.

David

Hitesh

Re: Getting started example Excel code 3406DMSO

Post by Hitesh »

Hi David,

Do you have an example file that can cause a crash? I'd be happy to take a look to see if there is an issue with the interaction with the wrapper.

The other problem might be that if the ps3000aCloseUnit() function is not called then the driver still has a lock on the device, in which case you need to unplug the USB cable, restart Excel and then reconnect the device.

Regards,

Post Reply