Using the Picoscope SDK with Visual Basic 2010 express.

Post any questions you may have about our current range of oscilloscopes
Post Reply
bevis
Newbie
Posts: 0
Joined: Sun Sep 26, 2010 10:31 am

Using the Picoscope SDK with Visual Basic 2010 express.

Post by bevis »

Hi all,

How do I make the API available to a VB 2010 program? just can't seem to add the descriptions etc. to VB 2010.

I am probably missing something very simple. The scope I want to use is a 2204.

Bevis

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

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by Chris »

Take a look at the example in the SDK

Download from

http://www.picotech.com/download.html

You'll need the

ps2000.vbp - project file
ps2000.bas - procedure prototypes
ps2000.frm - form and program

This eample was written for VB6, but it will convert to VB.NET to show you how the API calls are made.

-Chris.

bevis
Newbie
Posts: 0
Joined: Sun Sep 26, 2010 10:31 am

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by bevis »

Chris,

I have the SDK, the bit I am being daft about is how to open/convert it. VBNET hasn't an option of opening a vbp file as fas as I can see.

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

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by Chris »

I see what you mean with express.

See attached zip file.

Open ps2000.sln

-Chris
Attachments
VB.zip
(63.41 KiB) Downloaded 747 times

bevis
Newbie
Posts: 0
Joined: Sun Sep 26, 2010 10:31 am

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by bevis »

Chris

OK I get an error when I try to start sampling, something to do with paths I am sure, but I can open the 'scope it's relays click. Thank you very much.

Bevis

bevis
Newbie
Posts: 0
Joined: Sun Sep 26, 2010 10:31 am

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by bevis »

So I put the ps2000 dll in c:\ as this is where the code says it looks for it, all well so far. The 'fast' button works, i.e. I get a few readings but when I use the stert streaming button this error happens

FatalExecutionEngineError was detected
Message: The runtime has encountered a fatal error. The address of the error was at 0x66f6e0e5, on thread 0x2fc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

On this line...

mv_a = voltage_range(cboVoltageA.SelectedIndex)

oddly if I comment out the end and make mv_a = 0 thus
mv_a = 0 'voltage_range(cboVoltageA.SelectedIndex)
it still happens.

Any ideas?

Bevis

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

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by Chris »

The problem is on the previous line

no_of_values = ps2000_get_values(ps2000_handle, Values_a(0), 0, 0, 0, overflow, no_of_values)

using 0 for ByRef buffer_b, ByRef buffer_c, & ByRef buffer_d

Changed to
no_of_values = ps2000_get_values(ps2000_handle, Values_a(0), Values_b(0), Values_c(0), Values_d(0), overflow, no_of_values)

& declared

Dim Values_b(1024) As Short
Dim Values_c(1024) As Short
Dim Values_d(1024) As Short

-Chris.

bevis
Newbie
Posts: 0
Joined: Sun Sep 26, 2010 10:31 am

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by bevis »

Chris,

Brilliant! Works a treat.

No wonder the error had me stumped, VB was indicating the folllowing line.

Picoscope can now put this up as the 'new' VB example.

Bevis

bevis
Newbie
Posts: 0
Joined: Sun Sep 26, 2010 10:31 am

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by bevis »

Yet more...

I want to use the signal generator so I have added

Declare Function ps2000_set_sig_gen_built_in Lib "c:\ps2000.dll" (ByVal handle As Short, ByVal offsetVoltage As Long, ByVal pkToPk As ULong, ByVal waveType As PS2000_WAVE_TYPE, ByVal startFrequency As Single, ByVal stopFrequency As Single, ByVal increment As Single, ByVal dwellTime As Single, ByVal sweepType As PS2000_SWEEP_TYPE, ByVal sweeps As Long) As Short

Is there a reference or something to PS2000_WAVE_TYPE and PS2000_SWEEP_TYPE. Or will I have to declare these manualy, if so what type are they?

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

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by Chris »

In C, waveType & sweepType are enumerated, so ...

0 = PS2000_SINE sine wave
1 = PS2000_SQUARE square wave
2 = PS2000_TRIANGLE triangle wave
3 = PS2000_RAMP_UP rising sawtooth
4 = PS2000_RAMP_DOWN falling sawtooth
5 = PS2000_DC_VOLTAGE DC voltage



0 = PS2000_UP,
1 = PS2000_DOWN,
2 = PS2000_UPDOWN,
3 = PS2000_DOWNUP,


Note: in your declarations...
In VB6.0 etc.... Long = 32 bit
In VB.NET Long = 64 bit

Therefore use Integer in place of all Long declarations.

bevis
Newbie
Posts: 0
Joined: Sun Sep 26, 2010 10:31 am

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by bevis »

Chris wrote:
Note: in your declarations...
In VB6.0 etc.... Long = 32 bit
In VB.NET Long = 64 bit

Therefore use Integer in place of all Long declarations.
????? Thanks Microsoft!

That stopped the error, thank you.

There is bound to be more but I have nearly all I need.

Bevis

pipiak

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by pipiak »

Hi, sry that i can help by myself...but please can someone convert this example to c#.

A have something like that>
ps2000_handle = OpenUnit();
if (ps2000_handle > 0)
{
SetChannel(ps2000_handle, 0, 1, 1, 8);
int timex=0;
short timey=0;
int maxsample=0;
short timebase=GetTimebase(ps2000_handle, 0, 1, ref timex, ref timey, 1, ref maxsample);
int timeindiposed=0;
RunBlock(ps2000_handle, timex, timebase, 1, ref timeindiposed);
while (Ready(ps2000_handle) < 0)
{
System.Threading.Thread.Sleep(10);
}

short[] chanelA = new short[20000];
short chanelB = 0;
short chanelC = 0;
short chanelD = 0;
short overflow = 0;
GetValues(ps2000_handle, ref chanelA, ref chanelB, ref chanelC,ref chanelD, out overflow, timex);

MessageBox.Show("ps2000 opened");
}
else
{
MessageBox.Show("Unable to open");
}

But i cannog get values, in this example i think is used arrays of short variables, but i didnt see it declared in ps2000.dll , so how i have to do:((

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

Re: Using the Picoscope SDK with Visual Basic 2010 express.

Post by Chris »

Please contact support@picotech.com

Post Reply