Skip to content

BerryScript: Change serial port parity on the fly #22272

Discussion options

You must be logged in to vote

I merged a new feature to change parity.

Now you code should be:

var parityb = bytes('9669699669969669699696699669699669969669966969969669699669969669')
var ser = serial(-1, 39, 9600, serial.SERIAL_8N1)

def write(buf)
  var ch
  var ser
  ch = buf[0]
  if b.setbits(ch, 1) == 0
    ser.config(serial.SERIAL_8O1)
  else
    ser.config(serial.SERIAL_8E1)
  end
  ser.write(ch)
  ser.flush()
end

I took the liberty to optimize your big array of 256 elements takes more than 4KB of RAM (which is huge). You can use a bit-array instead which consumes only 204 bytes in total.

To compute it, you can do:

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

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@s-hadinger
Comment options

@sfromis
Comment options

@s-hadinger
Comment options

Comment options

You must be logged in to vote
1 reply
@Noschvie
Comment options

Comment options

You must be logged in to vote
1 reply
@clinkme4g
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Jason2866
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants