import os import termios import serial import time import sys # Description -------------------------------------------------------------------------------------------------------------- # Classes for serial, usb, tcp/ip communications. # # Name: channels.py # Author: W. Hetherington # Created: 2009/03/18 # Modified: 2009/03/18 # Copyright: (c)2009 # License: No restrictions #--------------------------------------------------------------------------------------------------------------------------- class SerialUSB : def __init__(self, t) : if t == 0 : t = 0.1 try: self.connect = serial.Serial('/dev/ttyUSB0',115200,rtscts=0,timeout=t) print('Open USB serial connection:') print '\t',self.connect except: print('USB error: Perhaps the controller or operator is unplugged.') sys.exit(2) def Write(self, s) : self.connect.write(s) def ReadLines(self) : return self.connect.readlines() def ReadLine(self) : return self.connect.readline() def Read(self, bytes) : return self.connect.read(bytes) #--------------------------------------------------------------------------------------------------------------------------- # Execute #if __name__ == '__main__': #Test()