示例#1
0
def main():
    tx_pckt = tos.Packet([('data', 'int', 2)], [])

    AM_ID = 6

    serial_port = tos.Serial("/dev/ttyUSB0", 115200)
    am = tos.AM(serial_port)

    #for i in xrange(10):
    while 1:
        raw_input("Press enter to send serial packet\n")
        am.write(tx_pckt, AM_ID)
示例#2
0
 def __init__(self, port, baudrate, am_channel):
     self.rx_queue = Queue.Queue()
     self.tx_queue = Queue.Queue()
     self.port = port
     self.baudrate = baudrate
     self.am_channel = am_channel
     try:
         self.serial = tos.Serial(self.port, self.baudrate)
         self.am = tos.AM(self.serial)
     except:
         print('Error: ', sys.exc_info()[1])
         sys.exit(1)
     rcv_thread = threading.Thread(target=receiver, args=(self.rx_queue,))
     rcv_thread.setDaemon(True)
     rcv_thread.start()
 
     snd_thread = threading.Thread(target=transmitter, args=(self.tx_queue,))
     snd_thread.setDaemon(True)
     snd_thread.start()
示例#3
0
    import tos
except ImportError:
    import posix, os
    sys.path = [
        os.path.join(posix.environ['TOSROOT'], 'support', 'sdk', 'python')
    ] + sys.path
    import tos

if len(sys.argv) < 2:
    print "no device specified"
    print "example:"
    print "   syncedRadioStats.py /dev/ttyUSB5"
else:
    try:
        #      ser = tos.Serial(sys.argv[1], 115200, flush=True, debug=False)
        ser = tos.Serial(sys.argv[1], 115200)
        am = tos.AM(ser)
    except:
        print "ERROR: Unable to initialize serial port connection to", sys.argv[
            1]
        sys.exit(-1)

    AM_HOST_CONTROLLED_TIMING_MSG = 0x7F
    wpacket = tos.Packet([('msg', 'int', 1)])  #1 byte integer (i.e. uint8_t)
    wpacket.msg = ord('s')
    am.write(wpacket, AM_HOST_CONTROLLED_TIMING_MSG)

    num_received = []
    senders_seen = []
    num_missed = []
    last_count = []
示例#4
0
#!/usr/bin/env python

import sys
import tos

if len(sys.argv) < 3:
    print "Usage:", sys.argv[0], "/dev/ttyUSB0 115200"
    sys.exit()

s = tos.Serial(sys.argv[1], int(sys.argv[2]), debug=False)
am = tos.AM(s)

while True:
    p = am.read()
示例#5
0
#!/usr/bin/env python

import sys
import tos

#application defined messages

tx_pckt = tos.Packet([('type',  'int', 1)],[])

AM_BLINKTORADIO=6

serial_port = tos.Serial("/dev/ttyUSB0",115200)
am = tos.AM(serial_port)

for i in xrange(10):

	am.write(tx_pckt,AM_BLINKTORADIO)
	pckt = am.read(timeout=0.5)
	if pckt is not None:
		print pckt.type
		print pckt.data