MIG is only an auto class generator that makes methods for any struct that
contains the payload, so you can work with methods rather than accessing
and converting the bytes. Nothing else. To communicate through
serialforwarder (TCP-IP) or directly through the serial port is transparent
at this point.
I have not used for many months...
Be sure to get familiar with the tutorials checking that you are able to
transmit and receive data from the PC to the mote, writing directly in the
serial port and through serialforwarder.
What I suggest is 1) to send any packet to the mote, 2) blink a led
indicating that the mote got something, i.e. whenever the serial active
message has been received, and 3) printf whatever it has understood.
What I did to transmit to the mote was:
import net.tinyos.message.*;
public class TinyOS2mote implements MessageListener {
private MoteIF moteIF;
// Register channels listened in the PC coming from the mote, in the
constructor of your class
this.moteIF.registerListener(new TinyOSControlANSMsg(), this);
this.moteIF.registerListener(new TinyOSLogMsg(), this);
this.moteIF.registerListener(new TinyOSOutputResultMsg(), this);
this.moteIF.registerListener(new TinyOSParametersMsg(), this);
this.moteIF.registerListener(new TinyOSCalibrationMsg(), this);
public void messageReceived(int to, net.tinyos.message.Message message) {
String str;
int value;
int amType = message.amType();
switch (amType) {
....
}
public void sendOrder(){
TinyOSControlCMDMsg msg = new TinyOSControlCMDMsg();
try{
msg.set_instruction ( (short) instruction );
msg.set_nodeId ( (short) nodeId );
moteIF.send(MoteIF.TOS_BCAST_ADDR, msg);
System.out.print("Sending COMMAND to serial port\n");
} catch(Exception ioexc) {
...
}
}
Then, when you launch the java class point to the serialforwarder:
java TinyOSconsole -comm sf@localhost:9002
That is it. I am not sure whether this is what you are looking for...
Cheers!
Sergio
On Mon, May 7, 2012 at 2:30 AM, Behdad aminian <[email protected]>wrote:
>
> Dear Sergio,
>
> Thanks for your reply.
> I have a Labview program which sends the mentioned hex string
> ("00FFFFFFFF02000B0000") directly to the SerialForwarder and data will
> received by motes. But I cannot send this string via my java program.Now
> some questions:
>
> 1) Is it needed to use MIG while I want to send my data via
> SerialForwarder? because as I could understand from tutorials, MIG will be
> used to communicate directly with the serial port of a mote not
> communicating via SerialForwarder. (Am I right?)
>
> 2) I could not understand the 3rd section of your explanation. Do you mean
> that, I should run my java code and send this string from my java
> application to SF? If so, this is exactly what I did, but it doesn't work.
>
> Here is part of my code:
>
> byte[] test=new byte[10];
> test[0]=0x00;
> test[1]=(byte)0xff;
> test[2]=(byte)0xff;
> test[3]=(byte)0xff;
> test[4]=(byte)0xff;
> test[5]=0x02;
> test[4]=0x00;
> test[5]=0x0B;
> test[6]=0x00;
> test[7]=0x00;
>
> Socket client=new Socket("localhost",902);
> DataOutputStream DOS= new DataOutputStream(client.getOutputStream());
>
> DOS.write(test, 0, test.length);
> DOS.flush();
>
> I will be thankful if you can help me about sending this data to a mote
> via SF.
>
> Best,
> Behdad
>
>
> On Sun, May 6, 2012 at 2:08 PM, Sergio Valcarcel <[email protected]>wrote:
>
>> I have not used it for almost one year, but the serial communication is
>> quite straightforward.
>>
>> 1) You make and compile a Java program able to communicate through serial
>> port. Optionally you could use the classes generated by MIG
>>
>> 2) Launch SerialForwarder
>> java net.tinyos.sf.SerialForwarder -comm serial@/dev/ttyUSB1:intelmote2
>> 3) Launch each of the applications attaching them to serial forwarder
>> (I say applications in plural because the possibility of sharing the serial
>> port for many threads is the main utility I found for serialforwarder)
>> java TinyOSconsole -comm sf@localhost:9002
>> java TinyOS2mote -comm sf@localhost:9002
>>
>> And that is all!
>>
>> Good luck!
>> Sergio
>>
>>
>> On Sat, May 5, 2012 at 9:59 PM, Behdad aminian
>> <[email protected]>wrote:
>>
>>> Hi all,
>>>
>>> I Need to send a very simple hex data "00FFFFFFFF02000B0000" from a java
>>> program via the SerialForwarder to a tinyos mote (Basestation).
>>> I have convert this string to its hex value and save it in a byte array
>>> and send to the port of serial forwarder via tcp connection, but the
>>> serialforwarder does not receive any data and disconnect the connection
>>> when I try to send a data.
>>> (I wrote a simple tcp server for testing and I ma able to receive data
>>> in my server but not in serial forwarder.)
>>>
>>> Should I do any thing special?
>>> I do not know what is wrong and what should I do and I will
>>> be appreciated if some one help me or at least give me some hints.
>>>
>>>
>>> Best,
>>> Behdad
>>>
>>> _______________________________________________
>>> Tinyos-help mailing list
>>> [email protected]
>>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>>
>>
>>
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help