Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- These class is used to communicate with an Arduino.
- It requires the pySerial library.
- """
- import time, serial
- class init(object):
- #open port
- def create (self, port, channel):
- arduino = serial.Serial(port, channel)
- check = self.check(arduino)
- return arduino, check
- #checks whether it worked or not
- def check (self, arduino):
- print(arduino.isOpen())
- return arduino.isOpen()
- #closes the port
- def close (self, arduino):
- check = self.check(arduino)
- if check == True:
- arduino.close()
- self.check(arduino)
- class read_write(object):
- #readline
- def readAline(self, arduino):
- text = arduino.readline()
- print(text)
- return text
- #readline without /r/n, and b at the beginning
- def readASline(self, arduino):
- text = self.readAline(arduino)
- text = text.decode('ascii')
- text = text.replace("\n", "")
- text = text.replace("\r", "")
- print(text)
- return text
- #write
- def write(self, arduino, text):
- arduino.write(text)
- #write with non-byte format string
- def writeASCII(self, arduino, text):
- text = text.encode()
- self.write(arduino, text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement