How do I read data from a serial port? python
Hi please my main question as I am new to python.
I am trying to read data from a serial port. Basically a serial port is a USB port converted to a serial port practically. I am using arduino.
I tried this code first:
while(True):
ser=serial.Serial('COM6',9600)
bytoread=ser.inWaiting()
val=ser.read(bytoread)
But it gave me an error.
Permission Error(13,Access is denied, none 5)
But when I changed my code to
while(True):
ser=serial.Serial()
ser.baudrate=19600
ser.port='COM6'
ser
ser.open()
bytoread=ser.inWaiting()
val=ser.read(bytoread)
No permission error occurred, but the program is always busy connecting the port. I waited for many minutes, but he never moved forward. What am I doing wrong here?
+3
source to share