A Simple Handshake

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

A Simple Handshake

Postby win1for » Fri Mar 12, 2010 6:28 pm

Hi Everybody,

I am developing a GUI simulation application in Lejos. Before the actual communication between the GUI and the Robot starts, i would like to implement a simple handshake whereby the GUI and the Robot willexchange a simple message.

That is the GUI will send a simple message to the robot and it will acknowledge the message, then afterwards they can begin the actual conversation. I want to implement it so that each one can know that the other is ready for communication.

I need help how it can be implemented.


Thanks.
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

Postby lawrie » Sat Mar 13, 2010 10:16 am

How do you plan to send commands to the robot? You can use data streams like the pcsamples BTSend sample does, or you can use a NXTCommand connection like The TachoCount sample does.

The first of these methods is the most flexible. If you use that, all you need to do is send a message over the data output stream and receive one back from the robot on the data input stream. The message could be an integer of a fixed numbers of bytes or characters. You would use methods such as writeInt or writeByte or writeChar and flush on the data output stream, and readInt, readByte or readChar on the data input stream.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Postby win1for » Sat Mar 13, 2010 11:59 am

Thanks for all your replies. I indeed appreciate it.

I was searching the stream methods if it is possible to send an object over the stream, but i couldn't find any of the stream methods for sending objects.
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

Postby burti » Sat Mar 13, 2010 1:49 pm

win1for wrote: I was searching the stream methods if it is possible to send an object over the stream, but i couldn't find any of the stream methods for sending objects.

As far as I know, there is no serialization support in lejos for objects.
(The Serializable interface exists but it was used to satisfy jikes which is a java compiler).
Unless there is no reflect library you cannot program a generic serialization solution which works for all classes.
I solved the issue of serialization by using json. It's lightweight and based on strings.
I adapted a json library which can read and write json strings for lejos without the need of java reflect.
So you have only to implement the "fromJSonString" and the "toJSonString" methods for a class you want to make serializable.
"toJSonString" can use a class called "jsonstringer" which is a simple builder for json strings. You pass it the attributes you want to put in the json string (i.e. which are serialized by that) and give each a unique name under which they can be found when you deserialize your message again.
If you are interested in this solution, let me know.
burti
Novice
 
Posts: 61
Joined: Thu Jun 25, 2009 11:41 pm

Postby win1for » Sat Mar 13, 2010 2:55 pm

Yes i am interested so if you have any additional information for me then kindly let me know.

I have a some questions concerning reading and writing from the input and output streams;

My project requires that i can send many commands to the robot at the same time, so that it can execute them one after the other.

My questions are :

1)
How can i send many commands (a list of commands) to the robot since the data streams read single values of integers, strings, floats?

How can i also construct the list of commands into a single list and send it?

2)
If the lists of commands reaches the robot how can i read them one after the other to give to the robot to execute them?

3)
Let say i want to read the status of the Color sensor and the Light sensor at the same time, how can i do that?

4)
If the robot is executing those tasks and let say i want to replace those tasks with new once, is there a way i can flush out the old tasks and replace them with new one?


I appreciate your help.

Thanks a lot
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm


Return to NXJ Projects

Who is online

Users browsing this forum: Adrianne and 1 guest

more stuff