Test and Measurement Forum

VB 2010 Express: pl1000SetInterval :AccessViolationException

Post your VB and VBA discussions here

VB 2010 Express: pl1000SetInterval :AccessViolationException

Postby sphericle » Mon Mar 31, 2014 7:31 am

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
sphericle
Newbie
 
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby Hitesh » Mon Mar 31, 2014 12:45 pm

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,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby sphericle » Mon Mar 31, 2014 2:59 pm

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[size=85]
[/size]

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
sphericle
Newbie
 
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby Hitesh » Tue Apr 01, 2014 8:52 am

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.
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby sphericle » Wed Apr 02, 2014 7:28 am

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 ?
sphericle
Newbie
 
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby Hitesh » Wed Apr 02, 2014 1:24 pm

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.
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby sphericle » Fri Apr 04, 2014 1:36 pm

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
sphericle
Newbie
 
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby Hitesh » Wed Apr 09, 2014 9:38 am

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
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby sphericle » Thu Apr 17, 2014 2:15 pm

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

vb2010.PNG
VB 2010
sphericle
Newbie
 
Posts: 0
Joined: Fri Mar 28, 2014 4:14 pm

Re: VB 2010 Express: pl1000SetInterval :AccessViolationExcep

Postby Hitesh » Tue Apr 22, 2014 8:20 am

Hi sphericle,

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

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

Best wishes,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to VB and VBA (Excel, Access)

Who is online

Users browsing this forum: No registered users and 0 guests