BerryScript: Change serial port parity on the fly #22272
Replies: 3 comments 5 replies
-
You are not supposed to recreate the serial object repeatedly, it has some deep consequences for the underlying layers. If it's about changing the parity, let me explore if there are other options possible |
Beta Was this translation helpful? Give feedback.
-
Yes, I need change the serial port parity settings without to recreate the serial() object. |
Beta Was this translation helpful? Give feedback.
-
Good news is esp-idf does have a function |
Beta Was this translation helpful? Give feedback.
-
I'm trying to emulate 9-bits RS-485 communication using parity bit.
The communication's rule is simple: first byte is address byte, it should be sent with first bit set (i.e. 1+8-bits byte)
Next bytes should be sent with first bit clear (0+8-bits byte).
The well known method to do this is to use 8-bits communication, but use parity bit as 9th information bit.
So, the code looks like this:
`var parity=[
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0]
def write(buf)
var ch
var ser
ch = buf[0]
if parity[ch] == 0
ser = serial(-1, 39, 9600, serial.SERIAL_8O1)
else
ser = serial(-1, 39, 9600, serial.SERIAL_8E1)
end
ser.write(ch)
ser.flush()
ser.close()
end`
The code works, but only for some calls of the output() function, then, after 20-30 calls of the output() every 1 sec,
the esp32-s2 hangs up.
I guess that is because of full recreating the serial object very often.
Is there any methods to change the serial settings (i.e. parity) in Berry script without to recreate the entire serial object?
Beta Was this translation helpful? Give feedback.
All reactions