Tags:
create new tag
, view all tags
After the device has been programmed and reset the operating system should recognise it as a communications port. In order to find what port it has been assigned to, open the terminal and type:
ls /dev/ttyACM

The following should show on the screen:

f1-3.png Figure - Ports listed in terminal

In the example above the port is located at “/dev/ttyACM0”. Depending on what is connected to the computer, more than one port may be displayed. Simple testing is required to determine which one the Smart Packet Radio is connected to. Once the port is determined it can simply be written to using the appropriate packet format and the data will be sent. It should also receive data but will only display it on the screen when the serial read command is used.

Example Python Script

As Python was the language intended to be used with the boards, an example script for transmitting and a separate script for receiving have been written. In order to use the script, it is required that the ‘serial’ header file is downloaded. This can be acquired by typing:

sudo apt-get install python-serial

Once it has been downloaded, the sample code for transmission is as follows: Note: The port must be edited depending on which port the device is connected.

#!/usr/bin/env python
import serial
import sys
import time
device=serial.Serial('/dev/ttyACM'+sys.argv[1],115200)
for i in range(500):
device.write(chr(0xff)+chr(0xaa)+chr(0x07)+'1234567')
print 'Sending packet %d'%

The port determined in the previous step is used as an input argument when running the code. The above code sends the 500 packets which are 10 bytes long, and returns the total time taken to send the packets. Note that the format used is ‘Destination address’, ‘Don’t care’ (as the source address is inserted by the firmware), ‘Payload length’, followed by the payload which is 7 bytes in length.

The sample code for receiving is as follows:

#!/usr/bin/env python
import serial
import sys
import time
device=serial.Serial('/dev/ttyACM'+sys.argv[1],115200)
device.read(20)
start=time.time()
device.read(1020)
print time.time()-start

The above code reads 1000 bytes and prints the time taken to receive the data. This was useful for determining the practical transmission rate of the device. This is how the Smart Packet Radio is used. Obviously the Python script can be expanded on greatly to include packet handling and can be used to implement any desired routing algorithm

-- XiaohongWu - 2012-01-30

Topic revision: r2 - 2012-01-31 - XiaohongWu
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback