Skip to content
Snippets Groups Projects
Commit 70e67cf0 authored by ilo21's avatar ilo21
Browse files

Added read serial funvtion to python code

parent 4f925641
No related branches found
No related tags found
No related merge requests found
No preview for this file type
import serial
import serial.tools.list_ports
import numpy as np
import time
import struct
......@@ -19,6 +20,32 @@ x = 270
my_serial = None
def get_hair_puller_connection():
ports = serial.tools.list_ports.comports(include_links=False)
for port in ports :
print('Checking port '+ port.device)
try:
ser = serial.Serial(port.device)
if ser.isOpen():
print("closing",port.device)
ser.close()
ser = serial.Serial(port.device, BAUDRATE, timeout=0.5)
ser.flushInput()
ser.flushOutput()
testmessage = ser.readline().decode('utf-8')
print("Response:", testmessage[-1])
except:
print("Problem with",port.device)
def read_my_serial(serial):
getData=str(serial.readline())
data=getData[0:][:-2]
# get read of leading byres character and ending r character
# create row string
row_string = data[2:-3]+"\n"
try:
my_serial = serial.Serial(COM, baudrate= BAUDRATE, timeout = 2)
print("Device found")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment