Hi I am trying to write a wrapper around the USBXpress driver SiUSBXp.dll
I have successfully been able to talk to one of the functions within this driver but I am unable to get the SI_Write function to work. below is the wrapper funciton
// function SI_Write (Handle: THandle; Buffer: LPVOID; NumBytesToWrite:
// dword; var NumBytesWritten: dword; lpOverlapped: POverlapped):
// TSI_Status; stdcall external 'SiUSBXp.dll';
public static long SI_Write(Handle handle, Pointer Buffer_LPVOID, UInt32 int32, Pointer pointer,
Void void1) {
Function add = USBXPRESS_LIB.getFunction("SI_Write");
ULongInt result = new ULongInt();
Parameter[] params = { handle, Buffer_LPVOID, int32, int32, void1 };
add.invoke(result, params);
// add.invoke(result,Handle_THandle,Buffer_LPVOID,NumBytesToWrite_dword,NumBytesWritten_dword,lpOverlapped_POverlapped);
return result.getValue();
}
and here is how I call this function within my code.
public void write(String command) throws USBXpressException {
AnsiString cmd = new AnsiString(command);
Pointer cmdp = new Pointer(cmd);
UInt32 bytesWritten = new UInt32();
UInt32 numberOfBytesToWrite = new UInt32(cmdp.getAlignedLength());
long ss;
ss=USBXpressDLL.SI_Write(this.handle, new Pointer.OutOnly(cmdp), numberOfBytesToWrite, new Pointer(bytesWritten), new Pointer.Void(0));
//assert(bytesWritten=dword(length(s)));
//this.write=bytesWritten;
if(ss!=USBXpressDLL.SI_SUCCESS){ throw new USBXpressException("Error Writing");}
}
the command that I am sending requires to have a chr 13 value sent at the end I am having a feeling that the driver is looking for this character.
when I look at the pointer size it does not reflect the orginal string size of the command being sent.
What am I doing wrong?
I have done some more debugging and have found that the code is returning and error of Invalid parameter so the jniwrapper is calling the function correctly but I am passing an invalid parameter.
how do I find out what parameter is incorrect
here is a excert from the SiUSBXp.dll programers guide
DWORD *NumBytesWritten, OVERLAPPED* o = NULL)
Parameters: 1. Handle—Handle to the device to write as returned by SI_Open.
2. Buffer—Address of a character buffer of data to be sent to the device.
3. NumBytesToWrite—Number of bytes to write to the device (0–4096 bytes).
4. NumBytesWritten—Address of a DWORD which will contain the number of bytes actually
written to the device.
5. (Optional) o—Address of an initialized OVERLAPPED object that can be used for
asynchronous writes.
I am sure i have the first 4 parameters setup correctly but am not sure how to represent the 5 param. (This param is always set to nil )
Any suggestions?