I build home automation system run with Nick Gammon Rs485 non blocking library. Current communication protocol is event based. Each event generate byte of array which contained address,command etc.. like
Full code would help understand what you mean but remember that the Nextion appends its default end-of-command bytes (0xFF 0xFF 0xFF) to the payload
Is it possible that your RS485 protocol does not expect them, so the buffer contains more than 4 bytes and your receiver code gets out of sync quickly (after the first message) and your comparisons fail ?
I think issue is here: (Referance from library page)
Uses a "begin packet" character (Start of Text, STX, 0x02) to reliably indicate that a packet is starting.
Uses an "end packet" character (End of Text, ETX, 0x03) to reliably indicate that a packet is ending.
Each data byte (other than STX/ETX) is sent in a "doubled/inverted" form. That is, each nibble (4 bits) is sent twice, once normally, and once inverted. Thus the only valid values for each nibble are:
Please explain what you mean by adding a leading zero to your values 01 01 ...?
This leading zero notation is reserved for octal numbers. It's doesn't matter for number between 0-7, but for 8 and above the result will be syntax error or incorrect number.
For example, the constant "010" will be interpreted as 8 in decimal rather than 10.
what I meant is that if you use printh 01 01 01 03 in a Nextion event, the bytes actually sent on the serial line are 0x01, 0x01, 0x01, 0x03 followed by the three standard end-of-command bytes 0xFF, 0xFF, 0xFF.
So the full sequence on the UART is 0x01 0x01 0x01 0x03 0xFF 0xFF 0xFF
As we don't see your code, I don't know what you really mean and what your setup is, but if your code is reading in some ways the incoming bytes, you should expect and handle the end-of-command bytes.
in Nextion Editor the printh command uses the hexadecimal notation without the 0x, so 01 01 01 03 is interpreted as four raw bytes with values 0x01, 0x01, 0x01, 0x03.
I think to remember that the leading 0 is not mandatory in Nextion printh commands. You can write printh 1 1 1 3 and it will send the same bytes 0x01, 0x01, 0x01, 0x03. The leading zero is just a common convention to indicate a hexadecimal byte
Are you trying to connect the Nextion display using RS485 and expecting it to be compatible with the data format used by the Nick Gammon RS485 library?
I don't think there is any way you can get the Nextion display to send data in the format used by the Nick Gammon RS485 library, if that is what you are wanting to do.
As long as the Gammon library can ignore the ending 0xff bytes from the Nextion display, then it may work. The data would just need to be encoded properly.
that was my point, I did think it was automatically added to events, but it does not seem to be the case (reading the doc).
it would appear printh sends only the exact bytes you specify in hexadecimal and nothing else, even if triggered by a touch event. So printh 01 01 01 03 sends exactly 0x01 0x01 0x01 0x03, with no extra bytes.
Would be worth trying with what nick's library really expected.
Each data byte (other than STX/ETX) is sent in a "doubled/inverted" form. That is, each nibble (4 bits) is sent twice, once normally, and once inverted.
I guess it would be easy to write a sample code with Nick Gammon Rs485 non blocking library to send 1,1,1,3 and write a small piece of code just printing out the bytes as they come on the other side
Its actually a lot simpler than that. Since the library can use hardware Serial, all that is needed is to replace the contents of the fWrite() function to print out the hex value instead of writing the hex value directly.