I’m trying to send a serial string of 16 bits. This string is made up of the status of switches 1 to 16.
If all the switches are on I want to send:
1111111111111111
If switch 1 and 5 were on and the others are off I want to send:
1000100000000000
I understand the serial binding and how to send a command to it to transmit. However I do not know how to package up the status of the 16 switches into an array. I only need to send it on received update. I would add all switches to a group and use “when gSwitches received update”
Caution with that; Groups can record multiple update events for a single member Item updating.
"when Member of gSwitches received update” will give a singular rule run, or of course “changed” is available.
The rule used for “Writing packed bits” here might form the basis of something.
It’s not very clear if you want to transmit two bytes or sixteen ascii “0”/“1” characters etc. but building a string is much the same.
I think the “binary” channel of the serial bridge is meant for this purpose?
From the docs
Channel for sending/receiving data in Base64 format to/from the serial port. The channel will update its state to a StringType which is the string representation of a RawType that contains the data received from the serial port. A command sent to this channel must be encoded as the string representation of a RawType, e.g. “data:application/octet-stream;base64,MjA7MDU7Q3Jlc3RhO0lEPTI4MDE7VEVNUD0yNTtIVU09NTU7QkFUPU9LOwo=”