Re: problem with handing over pointers and generic invoke

Alex Kotchnev <[email protected]>
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <OF0E1A51B0.77300F7B-ON85256F93.00743EAF-85256F94.000FFECE@divintech.com>
Benjamin, 

   I had used Jawin in a few projects, and what I was going to suggest was 
to get some examples going maybe with win32 functions that have a similar 
signature to what you are trying to invoke (so that you are confident in 
the way you are invoking the native function). That way, you will be sure 
if the problem is in the way you call the native function, or the problem 
is with the actual board. Another approach that I would suggest is to 
actually write a few lines of C and to try to get your board going with 
that (to eliminate the possibility that you are not using the board 
interface incorrectly).

        Looking at the way you invoke your functions: 
        1. It doesn't seem right that you pass a string into 
"setChannelConfig.invoke_I(0,"0x00", ReturnFlags.CHECK_W32);". The utility 
invoke function you are using becomes invoke_I(int, String, ReturnFlags), 
instead of invoke_I(int, int, ReturnFlags) - the native function signature 
indicates that it should get a WORD (which is an int if I'm not mistaken), 
not some kind of a string. 
        2. I'm don't think this would matter, but it appears that your 
"polling.invoke("A:I:n4", 16, nbs, null, ReturnFlags.CHECK_W32)" call is a 
little off as well .. Why is your stack size 16 ? The only thing you are 
passing is a pointer, so it seems to me that the stack size should be 4. 

I have a feeling that by the time you read this, you would have solved the 
problem, but anyway.. I hope this is helpful. 

Alex K

> 
> Date:    Sun, 23 Jan 2005 23:18:06 +0100
> From:    Benjamin Sommerfeld <[email protected]>
> Subject: problem with handing over pointers and generic invoke
> 
> Hi guys,
> 
> I already wrote to this list about my problem and after weeks of reading
> the latest documentation and trying out the latest development edition
> of Jawin I decided to write you guys again, cause I just can't manage to
> get the right result.
> 
> Here are the C-functions from the DLL I want to use with Jawin:
> 
> P100X_SetChannelConfig
> 
> Description :
> This subroutine will set the AD channel’s configuration code. This
> subroutine will set the active AD channel for P100X_AdPolling,
> P100X_AdsPolling and P100X_AdsPacer. This function will refer to the
> current active PCI-1002 board. Use the P100X_ActiveBoard(….) to select
> the active board.
> 
> Syntax :
> WORD P100X_SetChannelConfig(WORD wChannel, WORD wConfig);
> 
> Parameter:
> wChannel : [Input] AD channel number
> wConfig : [Input] Configuration code. Refer to Sec. 3.1 for details.
> 
> Return:
> P100X_NoError : OK
> P100X_ExceedBoardNumber : invalidate board number
> P100X_FindBoardError : cannot find the PCI-1002 board
> P100X_AdControllerError : MagicScan controller
> hardware handshake error
> 
> 
------------------------------------------------------------------------------
> 
> P100X_Polling
> Description :
> Performs a single A/D conversion on the active channel by software
> polling. The P100X_SetChannelConfig subroutine can be used to change
> channel or configuration code. Use the P100X_ActiveBoard(….) to select
> the active board.
> 
> Syntax :
> WORD P100X_Polling(word *wAdVal);
> 
> Parameter:
> wAdVal : [Output] address of wAdVal, which store the AD data
> Data is returned as an integer value in the range 0-4095.
> 
> Return:
> P100X_NoError : OK
> P100X_ExceedBoardNumber : invalidate board number
> P100X_FindBoardError : cannot find the PCI-1002 board
> P100X_AdPollingTimeOut : hardware timeout error
> 
> 
----------------------------------------------------------------------------
> 
> My java code looks like this:
> 
> public void start() {
> int result = 9999;
> try {
> String wTotalBoards = "0";
> FuncPtr driverInit = new FuncPtr("P100X.DLL", "P100X_DriverInit");
> result = driverInit.invoke_I(wTotalBoards, ReturnFlags.CHECK_NONE);
> System.out.println("DriverInit: "+result);
> 
> FuncPtr activeBoard = new FuncPtr("P100X.DLL", "P100X_ActiveBoard");
> result = activeBoard.invoke_I(0, ReturnFlags.CHECK_NONE);
> System.out.println("ActiveBoard: "+result);
> 
> FuncPtr setChannelConfig = new FuncPtr("P100X.DLL",
> "P100X_SetChannelConfig");
> result = setChannelConfig.invoke_I(0,"0x00", ReturnFlags.CHECK_W32);
> System.out.println("SetChannelConfig: "+result);
> 
> NakedByteStream nbs = new NakedByteStream();
> FuncPtr polling = new FuncPtr("P100X.DLL", "P100X_Polling");
> byte[] a = polling.invoke("A:I:n4", 16, nbs, null, 
ReturnFlags.CHECK_W32);
> LittleEndianInputStream leis = new LittleEndianInputStream(new
> ByteArrayInputStream(a));
> try {
> int retVal = leis.readInt();
> System.out.println(retVal);
> short bla = leis.readShort(); //wether i use readShort or readInt and
> "bla" is an int - the result is the same
> System.out.println(bla);
> } catch (IOException e) {}
> 
> FuncPtr driverClose = new FuncPtr("P100X.DLL", "P100X_DriverClose");
> driverClose.invoke_I(ReturnFlags.CHECK_NONE);
> } catch (COMException e) {
> e.printStackTrace();
> }
> 
> 
> 
---------------------------------------------------------------------------------------------------
> 
> the problem is: i always get the wrong result for "bla". Maybe it's
> because of the configuration code in "setChannelConfig" which i hand
> over as a string?
> In the documentation it is said, that I should use "0x00" in C for
> setting +/-10V as Channel Configuration.
> 
> "bla" is always 2300 although it should be some value around 500.....
> 
> Can anybody help me?
> 


Regards,

Alex Kotchnev
Developer / Systems Analyst
Diversified Information Technologies

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CONFIDENTIALITY NOTICE: If you have received this e-mail in error, please 
immediately notify the sender by e-mail at the address shown.  This e-mail 
transmission may contain confidential information.  This information is 
intended only for the use of the individual(s) or entity to whom it is 
intended even if addressed incorrectly.  Please delete it from your files 
if you are not the intended recipient.  Thank you for your compliance.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.