byte array pointer Problem

Vitaliy Vdovychenko <[email protected]> Sun, 27 Aug 2006 16:54:48 -0400
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <LISTSERV%[email protected]>
Hello Morten, i've tryed to register my [email protected] mail adress on the
jawin mailing list, but it doesn't bring any results, i've tryed it again
with  gmx.de and it's ok now:-)

i'm working ower one Java Project , i need to wrap one c++ dll and i have
chousen Jawint for it. I've made 85% of my work, but i have a problem with
byte array, you have obviously mutch more experiance with it, maybe you can
give me an advise?? So now i try to deskribe a problem:

the native xlCanMessage function looks like this:


int xlCanTransmit (int portHandle, int accessMask, int int *messageCount,
void pMessages)
Description:

The function sends CAN messages on the selected channels. It is possible to
send more messages
with one xlCanTransmit call (see Example).

Input Parameters:
portHandle - The port handle retrieved by xlOpenPort.

accessMask - Mask specifying which channels shall be used with this port.

messageCount - Points to the amount of messages, which should be send and
return the number of

transmitted messages, this value returns a this pointer so I,ve taken "A"
instruction

pMessages - Points to user buffer !!!!!! with messages to be send. At least
the buffer must have the size
of messageCount. At this stage I have a main problem, I don't understand
which pointer should i use to declare byte [] as input ???

In the native function this pMessafges is a structure, i have translated
this structure in a row byte[] !!!!!,  i'm tryind to represent it not as a
structure but as a byte []!!!!

This is a native Example - Send 100 CAN messages with the ID =3D 4
XLevent xlEvent[100];
int nCount =3D 100;
for (i=3D0; i
xlEvent[i].tag =3D XL_TRANSMIT_MSG;
xlE
vent[i].tagData.msg.id =3D 0x04;
xlEvent[i].tagData.msg.flags =3D 0;
xlEvent[i].tagData.msg.data[0] =3D 1;
xlEvent[i].tagData.msg.data[1] =3D 2;
xlEvent[i].tagData.msg.data[2] =3D 3;
xlEvent[i].tagData.msg.data[3] =3D 4;
xlEvent[i].tagData.msg.data[4] =3D 5;
xlEvent[i].tagData.msg.data[5] =3D 6;
xlEvent[i].tagData.msg.data[6] =3D 7;
xlEvent[i].tagData.msg.data[7] =3D 8;
xlEvent[i].tagData.msg.dlc =3D 8;
}
xlStatus =3D xlCanTransmit(portHandle, accessMask, &nCount, xlEvent);
!!!!!!!!!!!!!xlEvent at this stage!!


xlEvent is a structure and it looks like this in my c++ dll:
struct s_xl_event {
XLeventTag tag;
unsigned char chanIndex;
unsigned short transId;
unsigned short portHandle;
unsigned short reserved;
XLuint64 timeStamp;
union s_xl_tag_data tagData;
};

union s_xl_tag_data {
struct s_xl_can_msg msg;
struct s_xl_chip_state chipState;
union s_xl_lin_msg_api linMsgApi;
struct s_xl_sync_pulse syncPulse;
struct s_xl_daio_data daioData;
struct s_xl_transceiver transceiver;
};

so it was a complex structure of c++ dll library, I've tryed to solve this
problem that i wrote this structins in Java, then i wrote some classes that
transrom this structures in byte[], in my case it means i write as [in]
parameter not a sructure but a byte[] of this tructure, so I need some
sollutions that makes it possible to write a byte [] to the native method, I=

think it can be possible with P or M instructions, but i'm not sure how i
shoud pass them.
So, my Java function looks like this:

public static int JxlCanTransmit(int portHandle, int accessMask, int
messageCount, byte [] pMessages)throws Exception
{
FuncPtr jct =3D null;
try
{
jct =3D new FuncPtr ("vxlapi.dll", "xlCanTransmit");
NakedByteStream nbs =3D new NakedByteStream();
LittleEndianOutputStream leos =3D new LittleEndianOutputStream(nbs);



leos.writeInt(portHandle); [in]
leos.writeInt(accessMask); [in]

leos.writeInt(messageCount); return a pointer!!!!!!!!!!!!

for (int loop =3D0; loop
{
leos.writeByte(pMessages[loop]); the Instruction for my byte [], i think i
wrote it correct...???
}

String marshal =3D"IIA"+"M"+pMessages.length+":I:L4L4n4" ;


byte[] result=3Djct.invoke(marshal,24,nbs,null,ReturnFlags.CHECK_HRESULT);

LittleEndianInputStream leis =3D new LittleEndianInputStream(new
ByteArrayInputStream(result));
//1x[retval]
int XLStatus =3D leis.readInt(); [funktion RETVAL] is an Int



}
catch (COMException e) {
// handle exception
e.printStackTrace();
throw e;
} finally {
if ( jct !=3D null) {
try {
jct.close();
} catch (COMException e) {
// handle fatal exception
e.printStackTrace();
throw e;
}
}
}
}

nach oben -  vorherige - n=E4chste Nachricht

I'll be very grateful to you if you'll be able to give me an advise about my=

problem.
Best regards,
Vitaliy V.

> -----Original Message-----
> From: Discussion of Java/Win32/COM integration with Jawin
> [mailto:[email protected]] On Behalf Of Morten Andersen
> Sent: Thursday, August 24, 2006 1:10 PM
> To: [email protected]
> Subject: Re: [JAWIN] FW: Jawin, P instruction
>
> Hi Vitaliy and Sean,
>
> Mcnamara, Sean D wrote:
> > Posting this for Vitaliy due to his issues with registering for the
> mailing list. He can use the web interface for read access, so if anyone
> replies, I'll just send him an e-mail reminder.
> >
> [SNIP]
> >
> > # I have some dll as bin formated, so i can't change it.
> > # I have a function, the function has an input parameter - byte [],
> this byte[] is converted from a structure, this byte[] will be then
> filled up by the function and I need now read a pointer which points to
> this byte[] wit a new data by the native function .
> > # the native function looks like this:
> >
> > xlCanTransmit(XLportHandle, xlAccessMask, int *messageCount, void
> > *pMessages)
> >
> > XLportHandle - is an Integer [in]
> > xlAccessMask - is an Integer [in]
> > *messageCount - int Points to the amount of messages, which schould be
> send and return the number of transmited messages, I ve used "A" string
> and "n4" to read a pointer.
> > *pMessages - points to user buffer with messages to be send. Al least
> the buffer must have the size oj messageCount. here i've used "P", but i
> havnt have any idea how can i read back this pointer to byte[].
> >
> >
> > pMessages is a structure which looks like this:
> >
>
>
> I am a little bit in doubt about how "pMessages" is allocated/filled in
> the [out] part of your native xlCanTransmit-method.
>
> So is the following correct, when sending *1* message, and receiving
> *3*:
>
> - Calling like: xlCanTransmit(handle, mask, 1, byte[..])
>
> Where the [in] byte[..] is the size of 1 x xl_event struct, and contains
> the data to send?
>
> - when returning, will the [out]-values of:
> *messageCount* be 3?
> and
> what size will the *pMessages* be? will it be the size
> we allocated when calling the function? And then contain the first (or
> last) of the 3 received messages? How do you get the other 2 received
> messages then?
>
> or
> will the pMessages be size 3 x xl_event struct?
>
> When you answer these, hopefully we can help you as to whether Jawin can
> support this (and how).
>
> Best Regards
> Morten