VB 2010 Express: pl1000SetInterval :AccessViolationException

Post your VB and VBA discussions here
Post Reply
sphericle
Newbie
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

VB 2010 Express: pl1000SetInterval :AccessViolationException

Post by sphericle »

Visual Basic 2010 Express, Win7 64 Bit, pl1000.dll (10.0.3.170)
Can't get rid of this AccessViolationException when calling pl1000SetInterval.
same DLL with Excel 2013 works fine.

order of calling the function:

status = pl1000OpenUnit(handle)
status = pl1000MaxValue(handle, maxValue)
Call pl1000SetTrigger(handle, False, 0, 0, 0, 0, 0, 0, 0)
until here: no error

this is the function raising the Exception:
status = pl1000SetInterval(handle, us_for_block, nValues, channels(0), 16)

next steps will do:
status = pl1000Run(handle, nValues, 1)
status = pl1000GetValues(handle, values(0), nValues, overflow, triggerIndex)


I tryed many (almost every) hint in this Forum.

Any idea what I must do to get this to work?
Thanx in advance

Hitesh

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by Hitesh »

Hi sphericle,

How have you defined the 'Declare Function' line for the pl1000SetInterval function in VB 2010 Express?

Please check the data types as per http://www.picotech.com/support/kb/PicoScopeSDK-kb244

Regards,

sphericle
Newbie
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by sphericle »

Hello Hitesh
I changed all Long datatypes to integer.

This is the declaration:

Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Integer) As Integer
Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByVal handle As Integer) As Integer
Declare Function pl1000GetUnitInfo Lib "pl1000.dll" (ByVal handle As Integer, ByVal S As String, ByVal lth As Integer, ByRef requiredSize As Integer, ByVal info As Integer) As Integer
Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByVal handle As Integer, ByVal enabled As Integer, ByVal enable_auto As Integer, ByVal auto_ms As Integer, ByVal channel As Integer, ByVal dir As Integer, ByVal threshold As Integer, ByVal hysterisis As Integer, ByVal delay As Single) As Integer
Declare Function pl1000SetInterval Lib "pl1000.dll" (ByVal handle As Integer, ByRef us_for_block As Integer, ByVal ideal_no_of_samples As Integer, channels As Integer, ByVal No_of_channels As Integer) As Integer
Declare Function pl1000GetValues Lib "pl1000.dll" (ByVal handle As Integer, ByRef values As Integer, ByRef no_of_values As Integer, ByRef overflow As Integer, ByRef triggerIndex As Integer) As Integer
Declare Function pl1000Run Lib "pl1000.dll" (ByVal handle As Integer, ByVal no_of_values As Integer, ByVal method As Integer) As Integer
Declare Function pl1000Ready Lib "pl1000.dll" (ByVal handle As Integer, ByRef ready As Integer) As Integer
Declare Function pl1000MaxValue Lib "pl1000.dll" (ByVal handle As Integer, ByRef maxValue As Integer) As Integer


Resulting Error:

System.AccessViolationException wurde nicht behandelt.
HResult=-2147467261
Message=Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf, dass anderer Speicher beschädigt ist.

StackTrace:
bei CorroLog.Module1.pl1000SetInterval(Int32 handle, Int32& us_for_block, Int32 ideal_no_of_samples, Int32 channels, Int32 No_of_channels)



order of calling the function without the SetInterval function.

status = pl1000OpenUnit(handle)
status = pl1000MaxValue(handle, maxValue)
Call pl1000SetTrigger(handle, False, 0, 0, 0, 0, 0, 0, 0)
' now, do not call this function: commanded out
' status = pl1000SetInterval(handle, us_for_block, nValues, channels(0), 16)

status = pl1000Run(handle, nValues, 1)
status = pl1000GetValues(handle, values(0), nValues, overflow, triggerIndex)

-> no Error occurs, ... but of course no data is collected...

Regards,
sphericle

Hitesh

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by Hitesh »

Hi spherical,
Declare Function pl1000SetInterval Lib "pl1000.dll" (ByVal handle As Integer, ByRef us_for_block As Integer, ByVal ideal_no_of_samples As Integer, channels As Integer, ByVal No_of_channels As Integer) As Integer
I noticed that you've missed ByRef in front of 'channels As Integer'

You can use Short for the parameters defined as 'short' for VB .NET i.e.

Code: Select all

Declare Function pl1000SetInterval Lib "pl1000.dll" (ByVal handle As Short, ByRef us_for_block As Integer, ByVal ideal_no_of_samples As Integer, ByRef channels As Short, ByVal No_of_channels As Short) As Integer
It might be possible to defined the unsigned long and PICO_STATUS values as UInteger in VB .NET as well.

Hope this helps.

sphericle
Newbie
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by sphericle »

Hello Hitesh
Thank you for your help.

almost the half way down:

that's it.
ByRef in front of 'channels As Integer

no more Exceptions!

Now, the PicoLog still Returns no values.
here are the status-Returns of the functions:

pl1000open Unit: status / handle : 0 / 16384
pl1000maxValue: status / handle / maxValue : 0 / 16384 / 4095
pl1000SetTrigger: status / handle : 0 / 16384
pl1000SetIntervall: status / handle / us_for_block / nValues : 0 / 16384 / 10000 / 1
pl1000Run: status / handle / nValues : 0 / 16384 / 1
pl1000ready: status / handle / ready : 0 / 16384 / 0
pl1000GetValues: status / handle / nValues / overflow / triggerindex: 0 / 16384 / 0 / 0 / -1
pl1000CloseUnit: status / handle : 0 / 16384

As we can see, all returned stati are of value 0 : ok.
But GetValues returns 0 (Zero) nValues

This is the code so far: (partial)

Code: Select all

... public...
Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Integer) As Integer
Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByVal handle As Integer) As Integer
Declare Function pl1000GetUnitInfo Lib "pl1000.dll" (ByVal handle As Integer, ByVal S As String, ByVal lth As Integer, ByRef requiredSize As Integer, ByVal info As Integer) As Integer
Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByVal handle As Integer, ByVal enabled As Integer, ByVal enable_auto As Integer, ByVal auto_ms As Integer, ByVal channel As Integer, ByVal dir As Integer, ByVal threshold As Integer, ByVal hysterisis As Integer, ByVal delay As Single) As Integer

Declare Function pl1000SetInterval Lib "pl1000.dll" (ByVal handle As Integer, ByRef us_for_block As Short, ByVal ideal_no_of_samples As Integer, ByRef channels As Short, ByVal No_of_channels As Integer) As Integer
 
Declare Function pl1000GetValues Lib "pl1000.dll" (ByVal handle As Integer, ByRef values As Short, ByRef no_of_values As Integer, ByRef overflow As Integer, ByRef triggerIndex As Integer) As Integer
Declare Function pl1000Run Lib "pl1000.dll" (ByVal handle As Integer, ByVal no_of_values As Integer, ByVal method As Integer) As Integer
Declare Function pl1000Ready Lib "pl1000.dll" (ByVal handle As Integer, ByRef ready As Integer) As Integer
Declare Function pl1000MaxValue Lib "pl1000.dll" (ByVal handle As Integer, ByRef maxValue As Integer) As Integer

 

Public values(200) As Short
Public channels(16) As Short
Public nValues As Integer
Public maxValue As Integer

Public ready As Integer
Public requiredSize As Integer



...  local Sub...
Dim handle As Integer
Dim us_for_block As Short
Dim triggerIndex As Integer
Dim overflow As Integer
.
.
.
status = pl1000OpenUnit(handle)
status = pl1000MaxValue(handle, maxValue)
status = pl1000SetTrigger(handle, False, 0, 0, 0, 0, 0, 0, 0)

us_for_block = 10000  ; nValues = 1 

status = pl1000SetInterval(handle, us_for_block, nValues, channels(0), 16)
status = pl1000Run(handle, nValues, 0)
status = pl1000Ready(handle, ready)
status = pl1000GetValues(handle, values(0), nValues, overflow, triggerIndex)
...
status = pl1000CloseUnit(handle)
So, there must be something wrong with the channels-array ?

Where can I intercept ?

Hitesh

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by Hitesh »

Hi sphericle,

Looking at your code, you channels buffer should be:

Code: Select all

Public channels(15) As Short
Please note that for pl1000SetInterval and pl1000Run the number of samples to specify is the TOTAL between all channels i.e. for 100 samples per channel for 16 channels, you specify 1600.

When you call pl1000GetValues, you specify the number of samples per channel, so using the example above, nValues would be 100.

I hope this helps.

sphericle
Newbie
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by sphericle »

Hi Hitesh

I tried to get the things done as you proposed.
but I'm having still difficulties to get the right declaration for the functions (Ushort, short, UInteger and so on...)
now it's the SetIntervall function that returnes a Status of "16".

it seems to me that the declarations in the 'programmers guide' pl1000pg.en-1 2009 are different from the declarations in the dll. e.g. like 'no_of_values', 'noOfValues'...

but:
for the next 10 days I'm on holydays :P ...then I will play with the Arrays again.

cu
sphericle

Hitesh

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by Hitesh »

Hi sphericle,

A status code of 16 corresponds to a Hex value of 0x10 indicating an invalid channel.

If you are using VB.NET, you should be able to map the following data types:

short -> Short
unsigned long -> Uinteger
PICO_STATUS -> Uinteger

Enjoy your hols :D

sphericle
Newbie
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by sphericle »

Hi Hitesh

Cruising on the Mediterranean Sea is healthy for the programmers mind:

Back from my holydays, I got the right declarations of the functions and everything works fine.

Thank You for Your help!

This Problem is solved.

This is working for me on Win7 P64Bit

Code: Select all

Declare Function pl1000OpenUnit Lib "pl1000.dll" (ByRef handle As Short) As UInteger

Declare Function pl1000Stop Lib "pl1000.dll" (ByVal handle As Short) As UInteger

Declare Function pl1000CloseUnit Lib "pl1000.dll" (ByVal handle As Short) As UInteger

Declare Function pl1000SetTrigger Lib "pl1000.dll" (ByVal handle As Short, ByVal enabled As UShort, ByVal enable_auto As UShort, ByVal auto_ms As UShort, ByVal channel As UShort, ByVal dir As UShort, ByVal threshold As UShort, ByVal hysterisis As UShort, ByVal delay As Single) As UInteger

Declare Function pl1000SetInterval Lib "pl1000.dll" (ByVal handle As Short, ByRef us_for_block As UInteger, ByVal ideal_no_of_samples As UInteger, ByRef channels As Short, ByVal No_of_channels As Short) As UInteger

Declare Function pl1000GetValues Lib "pl1000.dll" (ByVal handle As Short, ByRef values As UShort, ByRef no_of_values As UInteger, ByRef overflow As UInteger, ByRef triggerIndex As UInteger) As UInteger

Declare Function pl1000Run Lib "pl1000.dll" (ByVal handle As Short, ByVal no_of_values As UInteger, ByVal method As UInteger) As UInteger

Declare Function pl1000Ready Lib "pl1000.dll" (ByVal handle As Short, ByRef ready As Short) As UInteger

Declare Function pl1000MaxValue Lib "pl1000.dll" (ByVal handle As Short, ByRef maxValue As Integer) As UInteger
VB 2010
VB 2010

Hitesh

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Post by Hitesh »

Hi sphericle,

Thank you for posting back to say the issue is resolved.

We're a little way from the sea here... :(

Best wishes,

Post Reply