DLL problem

Everything else that doesn't fall into one of the other PB categories.
sverrips
User
User
Posts: 22
Joined: Thu Sep 09, 2010 8:47 am

DLL problem

Post by sverrips »

I have a Pico DataLogger and I try read a DLL.

There is a function in the DLL, named HRDLGetUnitInfo.
The funtion needed this:

handle
String
Stinglength

And:

info

If I call the function with 0, string.s, 4, 0 It's must let me now the driver version.

But how I do that ?
I have try something:

Prototype.l ProtoMessageBox(handle.l, string.s, stringlengte, info, Flags.l = 0)

If OpenLibrary(0, "PicoHRDL.dll")

; 'MsgBox' is a variable with a 'ProtoMessageBox' type
;
HRDLGetUnitInfo.ProtoMessageBox = GetFunction(0, "HRDLGetUnitInfo")

Debug HRDLGetUnitInfo(0,string.s, 4, 0)
Debug Len(string.s)
EndIf

But, It don't work. It give me an empty string.s with stringlength 0.
What it must do, is give me the driver version in string.s

I can't find what to do ?

Stephan
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: DLL problem

Post by Trond »

1. You say the function takes four parameters, but your prototype has five parameters:

Code: Select all

Prototype.l ProtoMessageBox(handle.l, string.s, stringlengte, info, Flags.l = 0)
Remove the flags.

2. You say the function takes a string and a string length. This is wrong, it takes a pointer to a string, and a string length.

3. You pass an empty string, and a string length of 4. Obviously this is not going to work. If you pass a string length of 4, the string must be 4 characters long.

Try something more like this instead:

Code: Select all

Prototype.l ProtoHRDLGetUnitInfo(handle.l, *string.character, stringlengte, info)

If OpenLibrary(0, "PicoHRDL.dll")

  HRDLGetUnitInfo.ProtoHRDLGetUnitInfo = GetFunction(0, "HRDLGetUnitInfo")

  MyString.s = Space(10) ; Make the string 10 characters long
  MyStringLength = 10 ; The length must match the actual length
  Debug HRDLGetUnitInfo(0, @MyString, MyStringLength, 0) ; Pass the address of your string and the correct length
  Debug MyString
  Debug Len(MyString)
EndIf
sverrips
User
User
Posts: 22
Joined: Thu Sep 09, 2010 8:47 am

Re: DLL problem

Post by sverrips »

Trond wrote:1. You say the function takes four parameters, but your prototype has five parameters:

Code: Select all

Prototype.l ProtoMessageBox(handle.l, string.s, stringlengte, info, Flags.l = 0)
Remove the flags.

2. You say the function takes a string and a string length. This is wrong, it takes a pointer to a string, and a string length.

3. You pass an empty string, and a string length of 4. Obviously this is not going to work. If you pass a string length of 4, the string must be 4 characters long.

Try something more like this instead:

Code: Select all

Prototype.l ProtoHRDLGetUnitInfo(handle.l, *string.character, stringlengte, info)

If OpenLibrary(0, "PicoHRDL.dll")

  HRDLGetUnitInfo.ProtoHRDLGetUnitInfo = GetFunction(0, "HRDLGetUnitInfo")

  MyString.s = Space(10) ; Make the string 10 characters long
  MyStringLength = 10 ; The length must match the actual length
  Debug HRDLGetUnitInfo(0, @MyString, MyStringLength, 0) ; Pass the address of your string and the correct length
  Debug MyString
  Debug Len(MyString)
EndIf

Many thanks,

This works ! :

Prototype.l ProtoHRDLGetUnitInfo(handle.l, *string.character, stringlengte, info)

If OpenLibrary(0, "PicoHRDL.dll")

HRDLGetUnitInfo.ProtoHRDLGetUnitInfo = GetFunction(0, "HRDLGetUnitInfo")

MyString.s = Space(1024) ; Make the string 10 characters long
MyStringLength = Len(MyString.s) ; The length must match the actual length
Debug HRDLGetUnitInfo(0, @MyString, MyStringLength, 0) ; Pass the address of your string and the correct length
Debug MyString
Debug Len(MyString)
EndIf
sverrips
User
User
Posts: 22
Joined: Thu Sep 09, 2010 8:47 am

Re: DLL problem

Post by sverrips »

Now... I try to read the analog channel 1 of the pico datalogger:




Prototype.l ProtoHRDLOpenUnit(handle.l)
Prototype.l ProtoHRDLSetMains(handle.l, sixtyHertz)
Prototype.l ProtoHRDLSetAnalogInChannel(handle.l, channel, enabled, range, singleEnded)
Prototype.l ProtoHRDLGetSingleValue(handle.l, channel, range, conversionTime, singleEnded, overflow, valu.l)
Prototype.l ProtoHRDLCloseUnit(handle.l)

If OpenLibrary(0, "PicoHRDL.dll")
HRDLOpenUnit.ProtoHRDLOpenUnit = GetFunction(0, "HRDLOpenUnit")
HRDLSetMains.ProtoHRDLSetMains = GetFunction(0, "HRDLSetMains")
HRDLSetAnalogInChannel.ProtoHRDLSetAnalogInChannel = GetFunction(0, "HRDLSetAnalogInChannel")
HRDLGetSingleValue.ProtoHRDLGetSingleValue = GetFunction(0, "HRDLGetSingleValue")
HRDLCloseUnit.ProtoHRDLCloseUnit = GetFunction(0, "HRDLCloseUnit")

Debug HRDLOpenUnit(0)
Debug HRDLSetMains(0, 0)
Debug HRDLSetAnalogInChannel(0, 1, 1, 12 ,1)
Debug HRDLGetSingleValue(0, 1, 12, 100, 1,overflow, valu.l)
Debug valu.l
Debug HRDLCloseUnit(0)
EndIf
End


The analog channel is in the valu.l, but I think...... I do something wrong, but what ?
The value of value.l is 0 and there is +5 V on the channel.

What's wrong ? There is something wrong with the variables.

Stephan
Last edited by sverrips on Fri Sep 10, 2010 2:10 pm, edited 1 time in total.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: DLL problem

Post by Trond »

I can't help you very much because I never used this software and don't even know what it's for, but I do know you're not following the user manual.

You need to find the manual and read up on the functions you want to use.

The manual tells you the type of each parameter, and what kind of value you should pass for each parameter. For example, it says that all parameters of HRDLSetAnalogInChannel() are shorts and the return value is a short as well. You declared the return value as long, the second parameter as a pointer and the other parameters as long.
This is more correct:

Code: Select all

Prototype.w ProtoHRDLSetAnalogInChannel(handle.w, channel.w, enabled.w, range.w, singleEnded.w)
It also says that the first parameter is the handle returned by HRDLOpenUnit(). You pass 0. If you look up on HRDLOpenUnit() you see that 0 is the value that means an error occured. So this simply can't be a valid handle.

I can't keep reading the manual for you for two, three, five or even ten years. You must read it.
sverrips
User
User
Posts: 22
Joined: Thu Sep 09, 2010 8:47 am

Re: DLL problem

Post by sverrips »

Thanks, I Understand it. I Try to read the manual and I'm new of PureBasic. I come from Quick Basic 4.5 and switch to the Windows/Linux version.

I take a look to the manual.

Stephan
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: DLL problem

Post by Trond »

Feel free to ask more specific questions if you have problems with knowing what C type names are in PB and so on (short = .w for instance). :)
Post Reply