PS3000a.dll with VB.NET

Post your .Net discussions here
Post Reply
bikertt
Newbie
Posts: 0
Joined: Tue Jun 05, 2012 7:18 pm

PS3000a.dll with VB.NET

Post by bikertt »

Hello,

today I tried to connect from a VB.NET application via API-functions of the PS3000a.dll to a PicoScope 3204A.
Unfortunately without success.

Is there an example how to connet a PicoScope 3204A to a VB.NET application? I found a lot of examples in the SDK, but not for VB.NET. By the way, the C#-Example works fine.
Do I really need the PS3000a.dll or is there an .NET class to use?

Any help is appreciated,

Michael

bikertt
Newbie
Posts: 0
Joined: Tue Jun 05, 2012 7:18 pm

Re: PS3000a.dll with VB.NET

Post by bikertt »

Hello,

in the meantime I figured out how to connect to the PicoScope 3204A via PS3000a.dll. :D

Now I try to to Get Values and started to work with API "GetValues" and aigain it doesn't work so far.
I don't know how to declarate this API-Funktion in VB.NET.
I just want to get 1 measurement value when I click a button in the VB.NET application

So I ask again. Is there an example VB.NET with PS3000a.dll?

Thank you, Michael

Hitesh

Re: PS3000a.dll with VB.NET

Post by Hitesh »

Hi Michael,

Please try the following line of code:

Code: Select all

Declare Function ps3000aGetValues Lib "ps3000a.dll" (ByVal handle As Short, ByVal startIndex As Integer, ByRef numSamples As Integer, ByVal downSampleRatio As Integer, ByVal downSampleRatioMode As Integer, ByVal segmentIndex As Integer, ByRef overflow As Integer) As Integer
Please also refer to the following Knowledge Base article:

http://www.picotech.com/support/kb/PicoScopeSDK-kb244

Please note that Strings have to be pre-allocated and passed 'ByVal'.

We don't have .NET examples I'm afraid - we have ported VBA code into MS Visual Studio Express 2008 and 2010.

I hope this helps,

bikertt
Newbie
Posts: 0
Joined: Tue Jun 05, 2012 7:18 pm

Re: PS3000a.dll with VB.NET

Post by bikertt »

Hello,

thank you for your replay.

I have tried your declaration of ps3000aGetValues.

Unfortunately I get an error message "System.AccessViolationException" when I use it.

Can you please provide a little bit more code showing how to get a value?

Thank you, Michael

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

Re: PS3000a.dll with VB.NET

Post by Martyn »

Can you post your code for us to look at.
Martyn
Technical Support Manager

bikertt
Newbie
Posts: 0
Joined: Tue Jun 05, 2012 7:18 pm

Re: PS3000a.dll with VB.NET

Post by bikertt »

PICO_BUFFERS_NOT_SET.

What's wrong with my code?


Thank you very much for your help, Michael

here you can see my coding:


Code: Select all

    Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest.Click

        Dim status As Short
        Dim handle As Short
        Dim intReturnValue As Integer

        'This call works
        'Declare Function ps3000aOpenUnit Lib "ps3000a.dll" (ByRef handle As Short, ByVal serial As System.Text.StringBuilder) As Short
        status = ps3000aOpenUnit(Handle, Nothing)

        If handle <> 0 Then

            Dim sng As Single
            'Declare Function ps3000aSetChannel Lib "ps3000a.dll" (ByRef handle As Short, ByVal channel As Integer, ByVal enabled As Short, ByVal type As Integer, ByVal range As Integer, ByVal analogueOffset As Single) As Short
            Call ps3000aSetChannel(shthandle, 0, 1, 1, 1, sng)

            Dim channel As Integer
            Dim buffer As Integer
            Dim bufferLth As Integer
            Dim segmentIndex As Integer
            Dim mode As Integer
            buffer = 0
            channel = 0
            bufferLth = 1024
            segmentIndex = 0
            mode = 0

            'This call works
            'Declare Function ps3000aSetDataBuffer Lib "ps3000a.dll" (ByVal handle As Short, ByVal channel As Integer, ByRef buffer As Integer, ByVal bufferLth As Integer, ByVal segmentIndex As Integer, ByVal mode As Integer) As Integer
            intReturnValue = ps3000aSetDataBuffer(handle, channel, buffer, bufferLth, segmentIndex, mode)

            If intReturnValue = 0 Then

                Dim startIndex As Integer
                Dim numSamples As Integer
                Dim downSampleRatio As Integer
                Dim downSampleRatioMode As Integer
                'Dim segmentIndex As Integer
                Dim overflow As Integer
                numSamples = 1024
                downSampleRatioMode = 2

                'Here I get the returnValue 70 (Hex 46) --> PICO_BUFFERS_NOT_SET
                'An attempt was made to get data before a data buffer was defined
                'Declare Function ps3000aGetValues Lib "ps3000a.dll" (ByVal handle As Short, ByVal startIndex As Integer, ByRef numSamples As Integer, ByVal downSampleRatio As Integer, ByVal downSampleRatioMode As Integer, ByVal segmentIndex As Integer, ByRef overflow As Integer) As Integer
                intReturnValue = ps3000aGetValues(handle, startIndex, numSamples, downSampleRatio, downSampleRatioMode, segmentIndex, overflow)

            End If
        End If

    End Sub
-->
Hello,

I continued working on it. Now the problem is the return value of ps3000aGetValues. The returnValue is 70 (Hex 46) --> PICO_BUFFERS_NOT_SET.

What's wrong with my code?


Thank you very much for your help, Michael

here you can see my coding:


Code: Select all

    Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest.Click

        Dim status As Short
        Dim handle As Short
        Dim intReturnValue As Integer

        'This call works
        'Declare Function ps3000aOpenUnit Lib "ps3000a.dll" (ByRef handle As Short, ByVal serial As System.Text.StringBuilder) As Short
        status = ps3000aOpenUnit(Handle, Nothing)

        If handle <> 0 Then

            Dim sng As Single
            'Declare Function ps3000aSetChannel Lib "ps3000a.dll" (ByRef handle As Short, ByVal channel As Integer, ByVal enabled As Short, ByVal type As Integer, ByVal range As Integer, ByVal analogueOffset As Single) As Short
            Call ps3000aSetChannel(shthandle, 0, 1, 1, 1, sng)

            Dim channel As Integer
            Dim buffer As Integer
            Dim bufferLth As Integer
            Dim segmentIndex As Integer
            Dim mode As Integer
            buffer = 0
            channel = 0
            bufferLth = 1024
            segmentIndex = 0
            mode = 0

            'This call works
            'Declare Function ps3000aSetDataBuffer Lib "ps3000a.dll" (ByVal handle As Short, ByVal channel As Integer, ByRef buffer As Integer, ByVal bufferLth As Integer, ByVal segmentIndex As Integer, ByVal mode As Integer) As Integer
            intReturnValue = ps3000aSetDataBuffer(handle, channel, buffer, bufferLth, segmentIndex, mode)

            If intReturnValue = 0 Then

                Dim startIndex As Integer
                Dim numSamples As Integer
                Dim downSampleRatio As Integer
                Dim downSampleRatioMode As Integer
                'Dim segmentIndex As Integer
                Dim overflow As Integer
                numSamples = 1024
                downSampleRatioMode = 2

                'Here I get the returnValue 70 (Hex 46) --> PICO_BUFFERS_NOT_SET
                'An attempt was made to get data before a data buffer was defined
                'Declare Function ps3000aGetValues Lib "ps3000a.dll" (ByVal handle As Short, ByVal startIndex As Integer, ByRef numSamples As Integer, ByVal downSampleRatio As Integer, ByVal downSampleRatioMode As Integer, ByVal segmentIndex As Integer, ByRef overflow As Integer) As Integer
                intReturnValue = ps3000aGetValues(handle, startIndex, numSamples, downSampleRatio, downSampleRatioMode, segmentIndex, overflow)

            End If
        End If

    End Sub