PS300_get_unit_info

Post your VB and VBA discussions here
Post Reply
Frank Stone
User
User
Posts: 4
Joined: Tue Jan 02, 2007 12:07 pm

PS300_get_unit_info

Post by Frank Stone »

removed fjs
Last edited by Frank Stone on Thu Jan 04, 2007 9:35 am, edited 1 time in total.

Frank Stone
User
User
Posts: 4
Joined: Tue Jan 02, 2007 12:07 pm

Post by Frank Stone »

What was I doing??

I am trying to use the PS3000_get_unit_info function in VB6.0. When I step into the Call the VB editor is totally deleted.



In the PS3000.xl example, which uses VBA Macro, this call is located in a For-Next loop all of which are Commented-Out. I've change this macro code by un-commenting this code but this booms out as well.

Can anyone help?

ziko
Advanced User
Advanced User
Posts: 1705
Joined: Fri Dec 01, 2006 10:03 am
Location: St Neots

Post by ziko »

Hi and thank you for your post.

We have recently looked into this and to fix this problem you need to change the string length from 255 to 40.

i.e.

Dim S As String * 40

and

j = ps3000_get_unit_info(ps3000_handle, S, 40, i)

hope this helps.

Kind regards
Ziko

Technical Specialist

Frank Stone
User
User
Posts: 4
Joined: Tue Jan 02, 2007 12:07 pm

Post by Frank Stone »

The File PS3000.BAS is issued with a fundamental defect in it:
Declare Function ps3000_get_unit_info Lib "ps3000.dll" (ByVal handle As Integer, str As String, ByVal lth As Integer, ByVal line_no As Integer) As Integer

In Vbasic the str is a named function which returns a String representation of a number. Therefore, it should not be used for the name of any other variable.
By default Vbasic will take the declared str As String, as a ByRef. Which indicates that the argument is passed by reference to the variable name i.e. str

Needless to say Vbasic does not like this at all.

A quick fix is to add the ByVal key word in front thus:- ByVal str as String. Now it is the value of the string passed to it in the call that is used, which of course should be different name like (RetStr) . Of course it should not be the Null String so it must be allocates storage space with fixed-length string statement
[Dim RetStr as string * 255] before it can be used in the call.

Dim RetStr As String * 255, LenRet As Integer, Info As Integer
LenRet = 255 ' or => 12
Info = 0 ' for Driver version
Info = 1 'for USB Version
Info = 2 'for Hardware Version
' to
Info = 5 'for Cal Date
Info = 6 'for Error code

OK = ps3000_get_unit_info(ps3000_handle, RetStr, LenRet, Info)
If OK = 0 Then Error
Text1.text = RetStr + vbcrlf

Post Reply