serial port - python send and receive data serially -
i'm trying communicate stm32l152rb board through com port 4 accepts commands com4 , displays result in terminal using code it's not working ... i'm new python please let me know i'm doing wrong.
#global variables ser = 0 def init_serial(): comnum = 4 #enter com port number here. global ser #must declared in each function ser = serial.serial() ser.baudrate = 9600 ser.port = comnum - 1 #com port name start 0 #ser.port = '/dev/ttyusb0' #if using linux #specify timeout in seconds, serialport #doesn't hangs ser.timeout = 10 ser.open() #opens serialport # print port open or closed if ser.isopen(): print 'dis' + ser.portstr init_serial() temp = raw_input('type want send, hit enter:\r\n') ser.write('dis') #writes serialport while 1: bytes = ser.read() #read serial port print 'you sent: ' + bytes #print read port
Comments
Post a Comment