Jump to content
Excelsior Forums
Sign in to follow this  
mustang80

Problem with unsigned char

Recommended Posts

Hi everyone

I write a program which calls Gx02.dll (writeen in C++). There is a function which I try call:

GxSetEachAmp(UINT nCh, GX_EACHAMP* pAmp);

where:

-nCh ... channel number

-pAmp ... pointer to the GX_EACHAMP

When I try run my program I have an error:

Exception in thread "main" com.excelsior.xFunction.IllegalSignatureException: Il

legal type to make an Argument: byte

       at com.excelsior.xFunction.xFunction.parseSignature(xFunction.java:209)

       at com.excelsior.xFunction.xFunction.<init>(xFunction.java:30)

       at Start.main(Start.java:7)

This function is declared in defdll.h:

#define GXAPI extern "C" __declspec(dllimport)

GXAPI BOOL WINAPI GxSetEachAmp(UINT nCh, GX_EACHAMP* pAmp);

where:

typedef struct {

     BYTE            range;

     BYTE            sample;

     BYTE            use;

     BYTE            misc1;

     WORD            misc2;

     WORD            misc3;

     double            xpc;

} GX_EACHAMP;

and:

#define BYTE unsigned char

#define WORD unsigned short

#define BOOL bool

My program looks like below:

Start.java:

import com.excelsior.xFunction.*;

public class Start

{

     public static void main(String[] args) throws xFunctionException

     {

           xFunction GxSetEachAmp = new xFunction("Gx02", "int GxSetEachAmp(int,GX_EACHAMP*)");

             GX_EACHAMP Gx_EachAmp = new GX_EACHAMP();

           //GxSetEachAmp

           Gx_EachAmp.range = 0;

           Gx_EachAmp.sample = 6;

           Gx_EachAmp.use = 0;

           Gx_EachAmp.misc1 = 8;

           Gx_EachAmp.misc2 = 3;

           Gx_EachAmp.misc3 = 0;

           Gx_EachAmp.xpc = 2.1;

           

           int Gx_SetEachAmp_result = ((Integer)GxSetEachAmp.invoke(new Argument(0),Pointer.createPointerTo(Gx_EachAmp))).intValue();

     }

}

and

GX_EACHAMP.java:

import com.excelsior.xFunction.*;

class GX_EACHAMP extends Structure

{

     byte range;                  // Range information

     byte sample;            // Sampling frequency information

     byte use;                  // Channel ON/OFF information

     short misc1;            // Other information 1

     short misc2;            // Other information 2

     short misc3;            // Other information 3

     double xpc;                  // Coefficient information      (write only)

     public String defineLayout()

     {

           return "byte range, byte sample, byte use, short misc1, short misc2, short misc3, double xpc";

     }

     public GX_EACHAMP() {}

}

Who could help me, and tell me why I have this error???

Any help will by apprieciate

I use WindowsXP and j2sdk1.4.2_04

Share this post


Link to post
Share on other sites

Use 'char' instead of 'byte'. I.e.:

class GX_EACHAMP extends Structure 
{ 
char range;   // Range information 
char sample;  // Sampling frequency information 
char use;   // Channel ON/OFF information 
short misc1;  // Other information 1 
short misc2;  // Other information 2 
short misc3;  // Other information 3 
double xpc;   // Coefficient information  (write only) 
 
public String defineLayout() 
{ 
 return "char range, char sample, char use, short misc1, short misc2, short misc3, double xpc"; 
} 
public GX_EACHAMP() {} 
} 

Share this post


Link to post
Share on other sites

Thank You for replay.

I write program in Java which contorls electrical device (this device can recording vibration signal from 16 channel). I have to call functions from DLL. For examlpe:

#define GXAPI extern "C" __declspec(dllimport) 
GXAPI BOOL WINAPI GxSetEachAmp(UINT nCh, GX_EACHAMP* pAmp); 
where: 
// dlldef.h ?
typedef struct { 
BYTE ?range; 
BYTE ?sample; 
BYTE ?use; 
BYTE ?misc1; 
WORD ?misc2; 
WORD ?misc3; 
double ?xpc; 
} GX_EACHAMP; 

In specyfication is written that:

? #define BYTE unsigned char

? #define WORD unsigned short

? #define BOOL bool

File Gx02.dll (file where are functions to control GX-1 device) was compiled in C or C++

So:

in C type: unsigned char ? ?has ? ?8 bits

in Java type: ? ? ? ? ? ?char ? ?has ? ?16bits

? ?and ?type: ? ? ? ? ? ?byte ? ?has ? ?8 bits

thus I wanted use byte type.

How You think, if I use "char" instead of "byte" it is going to works???

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×