Jan-31-2019, 03:12 AM
Learning to read/write serial using back to back USB to serial boards (X-cross TX & RX) started writing to a port and monitoring the other using Putty. All looks good as expected but when I read and write to both ports (not using Putty at all) I get the quotes and the "b" from the write. ie. ser3.write( b'->this way') when I do text = ser4.read(100) then print it out I get b'->this way' quotes and apostrophe not sure why!?!?! Any help or clues greatly appreciated.
Please see result following code snippet.
1b'->This way >>>>> Writen to Serial 3 >>>>>'// The read from com4
1b'->That way <<<<< Writen to Serial 4 <<<<<'\The read from com3
2b' etc., etc., etc.
Why am I getting the b and enclosing apostrophes? I don't see this when monitoring port using Putty.
Thanks in advance for answer or clue!
Dave Z. (dlizimmerman)
Please see result following code snippet.
import serial def Serial_Port_Function(selection): print("Serial Port Function selection = " + selection ) n = 9 for counter in range (1, n+1): if 'hello' in selection: print ( "howdy!" ) elif '1' in selection: ser3.write( b"->Sent:ATZbdEFGhijkloputrew<<" ) elif '2' in selection: ser4.write( b'->Sent:ZIGGYziggyZIGGYzoooo<<' ) elif '3' in selection: ser3.write( b"->This way >>>>> Writen to Serial 3 >>>>>" ) text = ser4.read(100) print( str(counter) + str(text) + '//The read from com4 ' + '\r\n' ) ser4.write( b'->That way <<<<< Writen to Serial 4 <<<<<' ) text = ser3.read(100) print( str(counter) + str(text) + '\\The read from com3 ' + '\r\n' ) else: print ( 'nope' ) return( selection ) # This is the Main Function -------------------------------------------------------### print( "enter \n1. for output to com4\n2. for output to com3\n3. for bi-directional\n" ) input_text = input( '-->' ) print ( input_text ) if 'hello' in input_text: print ( input_text ) elif '1' in input_text: print ( input_text + ' output to com4' ) input( "Open Serial 4 with Putty press enter when ready" ) ser3 = serial.Serial("com3", timeout=0.07) # open serial port3 print(ser3.name) # check which port was really used elif '2' in input_text: print ( input_text + " output to com3" ) input( "Open Serial 3 with Putty press enter when ready" ) ser4 = serial.Serial("com4", timeout=0.07) # open serial port4 print(ser4.name) # check which port was really used elif '3' in input_text: print ( input_text + ' is bi-directional' ) input( "Ensure All Putty ports are closed, press enter when ready" ) ser3 = serial.Serial("com3", timeout=0.1) # open serial port3 print(ser3.name) # check which port was really used ser4 = serial.Serial("com4", timeout=0.1) # open serial port4 print(ser4.name) # check which port was really used # ser3.close() # ser4.close() else: print ( 'nope' ) ret_val = Serial_Port_Function( input_text ) print( "Returned value =>",ret_val ) #quit() [icode][/icode]What I get for output is:
1b'->This way >>>>> Writen to Serial 3 >>>>>'// The read from com4
1b'->That way <<<<< Writen to Serial 4 <<<<<'\The read from com3
2b' etc., etc., etc.
Why am I getting the b and enclosing apostrophes? I don't see this when monitoring port using Putty.
Thanks in advance for answer or clue!
Dave Z. (dlizimmerman)