[Tinyos-help] Sending characters from Java appln to Mote

Urs Hunkeler urs.hunkeler at epfl.ch
Wed Nov 17 04:16:57 PST 2010


Hi Venkat,

I don't see where the problem could be. Maybe there is a problem with 
multiple definitions of classes. Sometimes old versions exist and the 
make system does not realize it should recreate/regenerate some of the 
files. I usually make sure to recompile everything by removing all 
unnecessary files first. Best approach is to add all the generated files 
to the list of files to be deleted by "make clean". If you don't already 
have something like this I recommend you add a line like the following 
to your Makefile:

CLEAN_EXTRA = *.class TestSerialMsg.java

Then to compile your application, clean your build directory and compile 
everything:

make clean && make tmote

(Of course you'll have to replace "tmote" with whatever platform you're 
using).

If this still doesn't help, try renaming the array and see whether you 
get a different error. You can also look at the generated 
TestSerialMsg.java file and verify that it indeed has a method called 
"set_counter(int[] something)". If so, also verify that the variable 
you're passing in your Java code is indeed an array. You could for 
instance add a line like this:

// ...
while (flag) {
   // add a line to print some debugging information
   // if the variable "counter" is for some obscure
   // reason not an array here, it will cause a compile
   // error already at the print statement and we know
   // the problem is in the code here and not in the
   // TinyOS code:
   System.out.println(">> Debugging: Counter[0] is " + counter[0]);
   payload.set_counter(counter);
   moteIF.send(0, payload);
// ...

Cheers,
Urs

PS: Please copy your messages also to the tinyos-help mailing list so 
others who might have similar problems or better solutions can also read 
and contribute.

On 11/17/2010 11:16 AM, Venkat wrote:
> Hi ,,
>
> I still have the same problem.
>
> my nesC header file myapp.h is
>
> *typedef nx_struct test_serial_msg {
> nx_uint16_t counter[6];
> } test_serial_msg_t;*
>
>
> My Makefile MIG rule is
> *mig java -target=null $(CFLAGS) -java-classname=TestSerialMsg myapp.h
> test_serial_msg -o $@*
>
> My java Application code is
>
> *public void sendPackets() {
> int counter[] = new int[6];
> int newarray[] = new int[6];
> int length = 0;
> String intervalS = fieldInterval.getText().trim();
> length = intervalS.length();
> try {
> for (int i =1; i<=length; i++){
> newarray[i] = intervalS.charAt(i);
> if (newarray[i] > 999999) throw new NumberFormatException();
> counter[i] = newarray[i];
> }
> }
> catch (NumberFormatException e) {
> //Reset field when value is bad
> fieldInterval.setText("" + counter);
> }
> TestSerialMsg payload = new TestSerialMsg();
> try {
> while (flag) {
> payload.set_counter(counter);
> moteIF.send(0, payload);
> flag = false;
>
> //catch (InterruptedException exception) {}
> }
> }*
>
> I get the following error.
>
> *TestSerial.java:56: set_counter(int[]) in TestSerialMsg cannot be
> applied to (int)
> payload.set_counter(counter);
> ^
> 1 error
> make: *** [MyApp.class] Error 1*
>
> Could you kindly help me with it?
>
> Thank you ,
>
> Regards,
> Venkat.
>
> On Wed, Nov 17, 2010 at 10:39 AM, Venkat <v.venkatasubramanian at gmail.com
> <mailto:v.venkatasubramanian at gmail.com>> wrote:
>
>     Thank you for the reply. I have already gone thro the tutorials. But
>     I dint know that the MIG tool uses the msg structure type that is
>     specified in the make file to automatically create a class that
>     sends packet objects of the specified format. Now i think i got my way.
>     thank you very much.
>
>     Regards,
>     Venkat.
>
>     On Wed, Nov 17, 2010 at 10:23 AM, Urs Hunkeler <urs.hunkeler at epfl.ch
>     <mailto:urs.hunkeler at epfl.ch>> wrote:
>
>         Hi Venkat,
>
>         The tutorials explain how to create your own message format in
>         the radio communications tutorial:
>         http://docs.tinyos.net/index.php/Mote-mote_radio_communication
>
>         In your own message format you can specify arrays, e.g., as
>         "nx_uint8_t myArray[20];". The unsigned 8-bit integer is
>         probably the closest you get to a char array (or string). You
>         might have to copy the contents of the array to a local
>         structure before you can use it on the mote.
>
>         To use this message format with Java, you can (automatically)
>         create a Java class handling your message format. This is
>         described in the serial communications tutorial (the tool is
>         called "mig"):
>         http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder
>
>         There are also other interesting tutorials available. Have a
>         look at the tutorials page:
>         http://docs.tinyos.net/index.php/TinyOS_Tutorials
>
>         Cheers,
>         Urs
>
>
>         On 11/17/10 8:35 AM, Venkat wrote:
>
>             Hi,
>             I am running a java GUI application on my pc to send packets
>             ( random
>             integer) to the mote via serial port. I was just wondering
>             how to send
>             characters over the serial port to the mote? I modified the
>             testserial.java application for my GUI. However, the
>             Testserial.java has
>             method to send only integers over the serial port. It doesnt
>             have a
>             method call for sending arrays. I was thinking if i cud
>             convert the
>             characters into hex and send it. but, still, if i want to
>             send a string,
>             it will again be an array of integers. I am quite new to
>             tinyos and nesc
>             programming. Could some one help me with this ?
>
>             Thanks,
>             Venkat
>
>
>
>             _______________________________________________
>             Tinyos-help mailing list
>             Tinyos-help at millennium.berkeley.edu
>             <mailto:Tinyos-help at millennium.berkeley.edu>
>             https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
>
>
>
>
>
>



More information about the Tinyos-help mailing list