ADC-24 on .NET

Post your .Net discussions here
Post Reply
Budius
Newbie
Posts: 0
Joined: Wed Jul 04, 2012 11:30 am

ADC-24 on .NET

Post by Budius »

Hi,

I just got my brand new ADC-24 and I'm trying to make it work on VB.NET and having a few issues.
All library declarations are done (copied from the VB6 examples) on the header and I can successfully connect to the device (Open returns handler = 1).
I'll be using it for a constant (live-data) measurement, so I thought the option of using HRDLRun and then just keep reading every few ms would be better, I ran into problems with it so I tried using HRDLGetSingleValue without luck as well.
So, I'm coming for help, I'll post both my attempts on a simplified code. The real code I've been checking the return value for each command.

using RUN:

Code: Select all

' Open
mHandle = HRDLOpenUnit()
' Reject 50Hz
 HRDLSetMains(mHandle, 0)
' channel 1, active, +/-39mV, differential
HRDLSetAnalogInChannel(mHandle, 1, 1, 6, 0)
' 400ms total time, 340ms per conversion
HRDLSetInterval(mHandle, 400, 3)
' 5 samples, continuous
HRDLRun(mHandle, 5, 2) '  I'm really not sure what is meant by samples here, I just need to get the latest data, always the latest.
' Waiting for data
While HRDLReady(mHandle) = 0
   Thread.Sleep(50) ' It's running in a BackgrounWorker
End While
While true
   HRDLGetValues(mHandle, val(0), overf, 1)
End While
everything goes nice in this code until the actual GetValues, it's always returning the same value, to actually get a new value I have to stop and re-start from the beginning.
Do I have to call Run again? do I have to wait ready again?

using GetSingleValue:

Code: Select all

' Open
mHandle = HRDLOpenUnit()
' Reject 50Hz
 HRDLSetMains(mHandle, 0)

Dim overf As Short = 0
Dim value As Long = 0

' Channel 1, Range +/39mV, 340ms, differential
HRDLGetSingleValue(mHandle, 1, 6, 3, 0, overf, value)
'GetSingleFails, then I try to see why:
HRDLGetUnitInfo(mHandle, str, 50, 8)
' and it gives me 6: invalid parameters
but what parameters here are invalid? It's all copied from the datasheet.

any help will be much appreciated!
thanks.

Hitesh

Re: ADC-24 on .NET

Post by Hitesh »

Hi Budius,

Which version of the PicoHRDL.dll have you got?

With respect to HRDLRun function, the number of samples is the number that is to be collected per active channel.

Looking at the code, I would suggest changing any use of the 'Long' data type to 'Integer' in both the Run and Get SingleValues cases.

It might be worth taking a look at the HRDL.FRM code as well.

Please send in your code to support@picotech.com so that we can take a look at your declarations.

Best wishes,

marwol
Newbie
Posts: 0
Joined: Tue Jan 07, 2014 5:02 pm

Re: ADC-24 on .NET

Post by marwol »

Hi all,
I have a similar problem. I am using VB .NET in Visual Studio Express 2012 and the ADC20. I use the latest version of PicoHRDL.dll. My code is based on the HRDL.FRM and and HRDL.BAS samples. I have managed to successfully open the logger and initialize it.

The problem begins when I call the function:

Code: Select all

Call HRDLGetSingleValue(hHandle, 1, 0, 1, 0, 0, dx)
, where dx is declared as:

Code: Select all

Public dx As Integer
When this call is made, an Exception is thrown with details as follows:
Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\Users\Mariusz.Wilk\Documents\Visual Studio 2012\Projects\Picolog2\Picolog2\bin\Debug\Picolog2.vshost.exe'.

Additional Information: A call to PInvoke function 'Picolog2!Picolog2.Form1::HRDLGetSingleValue' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
I am not too sure how to solve this problem. I ran this program in VBA version that made the same calls and everything worked as expected.

Any help would be appreciated.

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

Re: ADC-24 on .NET

Post by Martyn »

Parameter declarations are different between .Net and VBA

http://www.picotech.com/support/kb/PicoScopeSDK-kb244
Martyn
Technical Support Manager

Post Reply