ps5000SetEtsTimeBuffer (64-bit) and VB.net

Post your .Net discussions here
Post Reply
Jay H
Newbie
Posts: 0
Joined: Wed Mar 31, 2010 2:13 pm

ps5000SetEtsTimeBuffer (64-bit) and VB.net

Post by Jay H »

I am having an issue with this function that is used to setup the ETS time buffers on 64-bit languages like .NET stuff. The problem is my buffer which is defined to be in VB.NET

Dim buffer() as long

I get an "Arithmetic operation resulted in an overflow." exception upon the call to ps5000SetEtsTimeBuffer.

I have used the 32-bit buffer function ps5000SetEtsTimeBuffers without a problem and ETS mode works but kind of curious to see what others have experienced with VB.NET and this function.

As far as I can tell, everything that I pass to the function is valid, I get a valid PICO_OK status from ps5000SetEts and I get the ETS time sample returned fine.

The function does work in the sample PICO Console App that was provided by PicoTech and written in C...

Jay

markB
Site Admin
Site Admin
Posts: 83
Joined: Tue Mar 27, 2007 9:43 am
Location: Cambridgeshire,UK

Re: ps5000SetEtsTimeBuffer (64-bit) and VB.net

Post by markB »

Hellow Jay

It doesnt sound like you are doing anything wrong. It could be your function prototype causing you the problem. PicoScope 6 also calls this funtion so we know it is possible to call it from .net. Here is our prototype (C#):

Code: Select all

      [DllImport(_DRIVER_FILENAME, EntryPoint = "ps5000SetEtsTimeBuffer")]
      public static extern uint SetEtsTimeBuffer(short handle, long[] buffer, int bufferLth);
If this doesnt help, could you post a code snippet so that I can see what is going wrong.
Regards

Mark

Jay H
Newbie
Posts: 0
Joined: Wed Mar 31, 2010 2:13 pm

Re: ps5000SetEtsTimeBuffer (64-bit) and VB.net

Post by Jay H »

Vb.NET (Visual Studio 2008)

Code: Select all

	
        'Dim buffer() As Long
.
.
.
.
.

            'Check if ETS is turned on (Fast or Slow)
            If (VB6.GetItemData(Sample_Program.Cbox_ETS, Sample_Program.Cbox_ETS.SelectedIndex) <> PS5000_ETS_MODE.PS5000_ETS_OFF) Then

                'ReDim Buffer(gc_BUFFER_SIZE)
                ReDim bufferHigh(gc_BUFFER_SIZE)
                ReDim bufferLow(gc_BUFFER_SIZE)
                Status = ps5000SetEts(unit.handle, VB6.GetItemData(Sample_Program.Cbox_ETS, Sample_Program.Cbox_ETS.SelectedIndex), 20, 4, ets_sampletime)
                If g_DEBUG Then Call dStatus("ps5000SetEts", Status)
                Sample_Program.WriteText("ETS is ON : ETS Sample time is " & ets_sampletime & vbNewLine)
                offset = CInt((gc_BUFFER_SIZE / 10) - 5)
                'Status = ps5000SetEtsTimeBuffer(unit.handle, buffer(0), CLng(gc_BUFFER_SIZE))
                Status = ps5000SetEtsTimeBuffers(unit.handle, bufferHigh(0), bufferLow(0), gc_BUFFER_SIZE)
                If g_DEBUG Then Call dStatus("ps5000SetEtsTimeBuffers", Status)
            Else
                Status = ps5000SetEts(unit.handle, PS5000_ETS_MODE.PS5000_ETS_OFF, 0, 0, 0)
                If g_DEBUG Then Call dStatus("ps5000SetEts", Status)
            End If
gc_BUFFER_SIZE is a global constant = 1024

You can see that I currently have the ps5000SetEtsTimeBuffer call commented out...

In my .vb file:

Code: Select all

   Declare Function ps5000SetEtsTimeBuffers Lib "PS5000.dll" (ByVal handle As Short, ByRef timeUpper As Integer, ByRef timeLower As Integer, ByVal bufferLth As Integer) As Integer

    Declare Function ps5000SetEtsTimeBuffer Lib "PS5000.dll" (ByVal handle As Short, ByRef buffer As Long, ByVal bufferLth As Long) As Long
I have basically tried to replicate your picoconsoleapp as a VB.NET application. As it is a .NET application, I had no doubt that it works but can't figure out why I'm bombing out. This application was converted from a VB6 application so you'll see some old VB6 converter class usage with the old style ComboBoxs...

Jay

markB
Site Admin
Site Admin
Posts: 83
Joined: Tue Mar 27, 2007 9:43 am
Location: Cambridgeshire,UK

Re: ps5000SetEtsTimeBuffer (64-bit) and VB.net

Post by markB »

It looks like the third parameter is the culprit. bufferLth should be an Integer.

You should also be careful with the return type - this needs to be an Integer too, otherwise your return values may look odd.

Hope this helps
Regards

Mark

Jay H
Newbie
Posts: 0
Joined: Wed Mar 31, 2010 2:13 pm

Re: ps5000SetEtsTimeBuffer (64-bit) and VB.net

Post by Jay H »

Ah, that was it... Since I am working with both VB6 and .NET applications, I copied the Declare from my VB6 project and a LONG in VB6 is an INTEGER in .NET which I didn't catch.

Visual Studio will migrate the datatypes, but unfortunately, I did this after I migrated my VB6 project to a VB.NET solution and unfortunately, my Declare did get migrated, but copied.. Oops.

Jay

Post Reply