cannot read uart from SFM10 using python

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

cannot read uart from SFM10 using python

Jump to solution
391 Views
Magnus73
Contributor I

 

I am trying to read data from the SFM10, using the simple hello world example,

It works in powershell but not using python

The following code works for an arduino

import serial

# Set a 5 second timeout
port = serial.Serial('COM6', 115200, bytesize=8, parity='N', stopbits=1, timeout=5)

try:
line = port.readline().decode('utf-8')
print(line)
except serial.SerialTimeoutException:
print("No data received within timeout period")
finally:
port.close()

0 Kudos
1 Solution
324 Views
Magnus73
Contributor I

Hi again, today I got a really good help from synchronicIT, see condensed solution below

import time
import serial

running = 0

ser = serial.serial_for_url('COM6', do_not_open=True)
ser.baudrate = 115200
ser.bytesize = 8
ser.parity = 'N'
ser.stopbits = 1
ser.rtscts = False
ser.xonxoff = False

ser.open()

# START

ser.rts = False
ser.dtr = True

time.sleep(0.02)

ser.rts = True
ser.dtr = False

time.sleep(0.01)
test=ser.readline()
time.sleep(0.02)
ser.write(b'the text\n')

test2=ser.readline()

print(test2)

ser.close()

View solution in original post

0 Kudos
1 Reply
325 Views
Magnus73
Contributor I

Hi again, today I got a really good help from synchronicIT, see condensed solution below

import time
import serial

running = 0

ser = serial.serial_for_url('COM6', do_not_open=True)
ser.baudrate = 115200
ser.bytesize = 8
ser.parity = 'N'
ser.stopbits = 1
ser.rtscts = False
ser.xonxoff = False

ser.open()

# START

ser.rts = False
ser.dtr = True

time.sleep(0.02)

ser.rts = True
ser.dtr = False

time.sleep(0.01)
test=ser.readline()
time.sleep(0.02)
ser.write(b'the text\n')

test2=ser.readline()

print(test2)

ser.close()

0 Kudos