Test and Measurement Forum

Visual Basic help pc4424

Post any questions you may have about our current range of oscilloscopes

Visual Basic help pc4424

Postby rdang16 » Thu Sep 30, 2010 12:52 am

Hello, I have some questions regarding programming the pc4424 in visual basic:

1. does anybody know if there is visual basic examples for the 4000 series? The programming guide found at: http://www.imex.ie/files/u3/ps4000pg_en_pdf_31123.pdf
seems to indicate that one exists, but i have not been unable to locate it.

2. I know that there is an excel example for the 4000, but for some reason I am having problems applying the same techniques to VB. More specifically I cannot even get open the device when using ps4000OpenUnit(handle) command.

Sorry if this post is poorly worded, but basically I am just lost and am new to this, so any help or direction would be much appreciated. Thanks
rdang16
Newbie
 
Posts: 0
Joined: Thu Sep 30, 2010 12:43 am

Re: Visual Basic help pc4424

Postby Chris » Thu Sep 30, 2010 1:10 pm

Hello

We do not have a VB example in the sdk.

As you have pointed out, the Excel example uses VBA, so it is a good place to start from.

There are a few changes required though....i.e. changing some of the function declaration's types to ByRef.

Also, if using VB.NET, the Long type needs to be changed to Integer, as

VB.Net Long = 64 bit
vb Long = 32 bit

Attached is a VB.Net modification of the ps4000.xls GetData function.

Hope this helps

-Chris
Attachments
Module1.zip
(1.67 KiB) Downloaded 125 times
Chris
Site Admin
Site Admin
 
Posts: 169
Joined: Tue Aug 17, 2010 9:00 am
Location: St. Neots

Re: Visual Basic help pc4424

Postby rdang16 » Thu Sep 30, 2010 4:59 pm

Thank you for your prompt reply.

I am using Visual Basic6, I am trying to model my program very closely to the 4000.xls example. But I cannot seem to get the device to open (using the OpenUnit(handle) command). It always returns 0. Also every time I stop the program VB6 force closes, I dont know if this is related or not. Do you think u can take a look at what I have so far and offer advice?
I feel like if I can just get past this issue ill be ok...
thanks
Attachments
4424.zip
(2.1 KiB) Downloaded 112 times
rdang16
Newbie
 
Posts: 0
Joined: Thu Sep 30, 2010 12:43 am

Re: Visual Basic help pc4424

Postby Chris » Fri Oct 01, 2010 3:01 pm

The first thing is to check that the unit is visible to the pc.....if you run Picoscope6 does it find the unit?

Next, the likely cause of the problem is that the handle is being passed ByVal when it should be passed ByRef.


make sure the declaration for ps4000OpenUnit is declared as......

Declare Function ps4000OpenUnit Lib "ps4000.dll" (ByRef handle As Short) As Short

Then make sure all functions that have * parameter are declared as ByRef

-Chris.
Chris
Site Admin
Site Admin
 
Posts: 169
Joined: Tue Aug 17, 2010 9:00 am
Location: St. Neots

Re: Visual Basic help pc4424

Postby rdang16 » Tue Oct 05, 2010 12:36 am

the scope works when using Picoscope6. I made the changes you suggested and the result is still the same. I am unable to open the device and when stopping the program visual studio force quits. Am I supposed to add the ps4000.dll as a reference somehow?

Because when I try i get an error message ("unable to add reference to specified file")
rdang16
Newbie
 
Posts: 0
Joined: Thu Sep 30, 2010 12:43 am

Re: Visual Basic help pc4424

Postby Chris » Tue Oct 05, 2010 7:21 am

Could you send me some code and I will have a look to see what's wrong.

-Chris.
Chris
Site Admin
Site Admin
 
Posts: 169
Joined: Tue Aug 17, 2010 9:00 am
Location: St. Neots

Re: Visual Basic help pc4424

Postby rdang16 » Tue Oct 05, 2010 4:41 pm

Here is some of my code. I have only changed the openUnit function using Byref for now. Also there is no short in VB 6 so I used integer.

thanks
-Richard
Attachments
PS4000.zip
This is just a modified version of the ps3000 example. I am only trying to get the "open" function working right now.
(3.73 KiB) Downloaded 122 times
4424.zip
This is similar to ps4000.xsl example. Again, Im still just trying tot get the device to open for now.
(2.11 KiB) Downloaded 119 times
rdang16
Newbie
 
Posts: 0
Joined: Thu Sep 30, 2010 12:43 am

Re: Visual Basic help pc4424

Postby gruntman » Tue Oct 05, 2010 6:41 pm

Rdang16,

I tried out the 4424.zip program that you posted and it opens the unit fine. Most likely the program isn't referencing the ps4000.dll correctly, be sure to either place the ps4000.dll in the same folder as your project or reference the full path of the driver.

The reason for the crashing when attempting to close the software is due to you never calling the ps4000CloseUnit function. Once I added that to the end of your program is closed without any issues. On the function also change it to:

Declare Function ps4000CloseUnit Lib "ps4000.dll" (ByVal handle As Integer) As Integer

Regards,

Richard Boyd
Crag Technologies, Inc
http://www.pc-oscilloscopes.com
gruntman
Guru
Guru
 
Posts: 109
Joined: Thu Sep 28, 2006 3:50 pm


Return to USB PC Oscilloscopes

Who is online

Users browsing this forum: No registered users and 1 guest