1

With tinyos there is SerialForwarder which forwards the data to a socket. I have tried to open socket with host:"localhost",,port="9001" ,, but this will always return two bytes ="T!" !!

Then I try to open a TCP connection with same properties but I got this warning :

warning unsuccessful read a timeout occurred before the terminator was reached

How to read the data from SerialForwarder?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
Hana90
  • 943
  • 5
  • 17
  • 37

1 Answers1

0

You have to read thoroughly the serial stack...its not very easy but its do able.

You can directly read from serial port. You don't need serial forwarder in this case. There are few things to take care of.

For example if you want to read a serial message that is being send to serial port of your PC (usb sensorboards just work like serial, since they are using usb to serial converters lik FTDI chip).

in C# (same for Java, etc...) you can read byte streams that are coming in the serial port. You can parse this byte streams to extract a standard serial message of tinyos.

This is somehow explained in TEP #113 although it has some problems, but you should be able to find those problems and make your program work.

As it stated in TEP 113, a standard serial packet is something like:

7e 40 09 00 be ef 05 7d 5d 06 01 02 03 04 05 7e

That means, a packet starts with hex 7E ( I believe its 126 or 127) and ends also with 7E. The last 2 bytes are CRC of the packet. So you can in your c# program start reading from serial port when you encounter 7E and stop reading when you reach the next 7E in the stream. Everything in between will be your packet.

You have to be careful of escaping that is if a 7E is part of your packet content, to be not be confused with start and end dilimeters, it will be escaped to something else...that's also is explained in that TEP 113.

I believe there were some C++ code fro calculating the CRC that you can easily convert it to C# or Java code.

Also check the source code of Serial.h which contains some details about how a serial packet is being formed in TinyOS.

Dumbo
  • 13,555
  • 54
  • 184
  • 288