I have the need for an applet that allows run time defined baud rate, stop bit, parity etc to be used with my Raspberry Pi 3 application.
I have coded the applet using fixed parameters, and got the applet working just as I need, I then coded to gather the runtime values as required successfully but cannot find how to invoke the serial port using variables rather than fixed values.
This is the bit of my code for opening the serial port that I need help with
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=38400,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
What I am looking for in pseudo code is
mybaud = "38400"
myparity = "serial.PARITY_NONE"
mystop = "serial.STOPBITS_ONE"
mybyte = "serial.EIGHTBITS"
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=mybaud,
parity=myparity,
stopbits=mystop,
bytesize=mybyte
)
Any advice would be appreciated.