Skip to content

Instantly share code, notes, and snippets.

@rightson
Created October 31, 2016 15:00
Show Gist options
  • Save rightson/ad543a8719a8f75ee7386e4818ccb56b to your computer and use it in GitHub Desktop.
Save rightson/ad543a8719a8f75ee7386e4818ccb56b to your computer and use it in GitHub Desktop.
config script for RN2483
import serial
class Serial:
BAUDRATE = 57600
TIMEOUT = 1
SERIAL_PORT = '/dev/ttyUSB0'
def __init__(self):
self.ser = serial.Serial(
self.SERIAL_PORT, self.BAUDRATE, timeout=self.TIMEOUT)
print("Device opening: %s" % self.ser.isOpen())
def write(self, data):
self.ser.bytesize = 8
self.ser.parity = "N"
self.ser.stopbits = 1
self.ser.timeout = 5
print('>> %s' % data)
bytestream = bytes(data + "\r\n")
self.ser.write(bytestream)
response = str(self.ser.readline())
print('%s' % response)
return response
def batchWrite(self, commands):
for cmd in commands:
self.write(cmd)
return self
def __del__(self):
self.ser.close()
print("Device closed: %s" % (not self.ser.isOpen()))
s = Serial()
s.batchWrite([
'sys reset',
'sys get hweui',
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment