cannot read uart from SFM10 using python

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

cannot read uart from SFM10 using python

跳至解决方案
1,398 次查看
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 项奖励
回复
1 解答
1,331 次查看
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 项奖励
回复
1 回复
1,332 次查看
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 项奖励
回复