Jump to content
Excelsior Forums
Sign in to follow this  
mustang80

Something wrong, but on which side?

Recommended Posts

Hi, I use xFunction and everything was ok to now...

I have function which was written in C:

BOOL GxSetTrigger(GX_LEVELTRIG* ptrig)

The struct looks like bellow:

typedef struct {

? ? ?DWORD ? ? ? ? ? ?andor;
? ? ?BYTE ? ? ? ? ? ?status[128];
? ? ?BYTE ? ? ? ? ? ?percent[128];
? ? ?GX_TRIGGERBIT* ptrbit;

} GX_LEVELTRIG;
typedef struct {

     BYTE            andor[128];
     BYTE            diobit[128][16];

} GX_TRIGGERBIT;

So I wrote code in Java which should calls this function:

GX_LEVELTRIG.class

import com.excelsior.xFunction.*;

class GX_LEVELTRIG extends Structure
{
? ?long andor; ? ? ? ? ? ? //Setting of AND/OR condition
? ?char[] status; ? ? ? ? ?//Setting of ignore/up/down/bit condition
? ?char[] persent; ? ? ? ? //Setting of a trigger level
? ?Pointer ptrbit; ? ? ? ? // Setting of a trigger for each bit
? ?
? ?public String defineLayout()
? ?{
? ? ? ?return "long andor, char[128] status, char[128] persent, GX_TRIGGERBIT* ptrbit";
? ?}
? ?public GX_LEVELTRIG()
? ?{
? ? ? ?status = new char[128];
? ? ? ?persent = new char[128];
? ? ? ?try
? ? ? ?{
? ? ? ? ? ?ptrbit = Pointer.create("GX_TRIGGERBIT*");
? ? ? ?}
? ? ? ?catch(Exception e)
? ? ? ?{
? ? ? ? ? ?throw new ExceptionInInitializerError(e);
? ? ? ?}
? ?}
}

and test.java:

public int GxSetTrigger(long l_andor, char[] ch_status, char[] ch_persent) throws xFunctionException 
? ?{
? ? ? ?xFunction gx_set_trigger = new xFunction("Gx02", "int GxSetTrigger(GX_LEVELTRIG*)");
? ? ? ?Gx_LevelTrig.andor = l_andor;
? ? ? ?for(int i = 0; i < 16; i++)
? ? ? ?{
? ? ? ? ? ?Gx_LevelTrig.status[i] = ch_status[i];
? ? ? ? ? ?Gx_LevelTrig.persent[i] = ch_persent[i];
? ? ? ?}
? ? ? ?int GxSetTrigger_result = ((Integer)gx_set_trigger.invoke(Pointer.createPointerTo(Gx_LevelTrig))).intValue();
? ? ? ?if (GxSetTrigger_result == 1)
? ? ? ?{
? ? ? ? ? ?return GxSetTrigger_result;
? ? ? ?}
? ? ? ?else
? ? ? ?{
? ? ? ? ? ?return GxGetLastError();
? ? ? ?}
? ?}

arguments for this example lokks like following:

char[]  status = new char[16];
char[] percent = new char[16];
for(int i=0;i<16;i++)
{
   status[i] = 1;
   percent[i] = 30;
}
andor = 2;

I omit pointer to GX_TRIGGERBIT because I don't need use it.

This function should sets my channels from 0 to 15.

Also should sets this channels on level 30%(trigerring).

But the problem is that this function sets only channels from 4 to 15 and omit 4 channels (always 0,1,2,3). It loses 4 bajts but where???  Another function works fine.

dll from I invoke this function is use also by another program wrote in C and everything is ok(trigerring works). Wher could be a problem?:huh:

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  

×