Structured message over bluetooth

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Structured message over bluetooth

Postby maxdd » Sun Jul 06, 2014 9:14 am

Hello there,
Im trying to send a structured message over BT but i saw that the Serializable interface is not implemented.

Is there a common way to do that with LeJOS?

thanks
maxdd
New User
 
Posts: 14
Joined: Fri May 23, 2014 6:58 am

Re: Structured message over bluetooth

Postby skoehler » Sun Jul 06, 2014 1:35 pm

Which class doesn't implement Serializable but should? What is a structured message?
skoehler
leJOS Team Member
 
Posts: 1418
Joined: Thu Oct 30, 2008 4:54 pm

Re: Structured message over bluetooth

Postby maxdd » Mon Jul 07, 2014 7:51 pm

I admit that maybe im saying bullshit but what i mean is to create an object with some fields and then transmits the entire object via bluetooth, as far as i know to do that you need java.io.serializable which from http://www.lejos.org/nxt/nxj/api/index.html seems not to be implemented.

I was used to do that in C/C++ with a C structure and then printf it in a file, is it possibile to do that here?... if not what should be the best way to send multiple structured information?

edit: Can i just use a byte array?
maxdd
New User
 
Posts: 14
Joined: Fri May 23, 2014 6:58 am

Re: Structured message over bluetooth

Postby skoehler » Mon Jul 07, 2014 9:29 pm

Serialization is something much much different from sending the contents of a struct. Serialization is not supported by the JVM for the NXT brick. Hence, the Serializable interface is not supported. Use a DataOutputStream to send data from one computer to another. The ints and longs are automatically converted to network byte order (big endian) and can be read on the other side via the DataInputStream. Sending a "struct" is basically equivalent by calling the DataOutputStream's write-methods for each member.

BTW: Simply taking the memory backing a struct and sending it over the network is bad practice. This doesn't work across platforms (ppc vs. x86, possibly x86 vs. amd64).
skoehler
leJOS Team Member
 
Posts: 1418
Joined: Thu Oct 30, 2008 4:54 pm


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests

more stuff