No, not at all, was just thanking you for the help you've given. Too many times I look the time to search and look up links and info for folks and not even a reply or thank you.
I see it happen to folks here all the time. (like all the modbus questions a few days ago. not a thank you or reply one)
The buffer is a fine idea, I usually do this in low level serial work as well on pc's. For your question, the sync byte is simply a single byte that is the ID of the system it's meant for. When you see it, you either collect 7 more bytes or timeout. After you collect the total of 8 bytes (including the ID) you then first check to see if the last two bytes calculates to the CRC of the message you received. If not, toss it. There are numerous other checks as well.
So, No Start Byte besides the ID,
No terminator, just a silent time to time out on. Usually collect 8 bytes for a valid message depending on mode.
In total it goes something like this.
1)Grab a byte, is it my ID? No, then ignore it. Yes then go to next step.
2) Collect a total of 8 bytes or timeout and clear the buffer.
3) e collected 8 bytes, now get the last two bytes and calc the 16 bit CRC and see if it matches the message. if so next, or ignore message.
4) now check to see if the Function Code is valid or supported, if not, return an error message FC Invalid, else process the request.
5) Return the required Data
The thing is, since it's only 8 bytes of data, it doesn't really take that long and other than gathering a few adc readings there isn't much else going on, so I took the simple route.
I still have to figure out how to use 7,N,1 with the usart by shifting bits for valid data or something. Hadn't played with it, took the software serial routines for that portion but I think with a little logic I could shift 1 bit before storing the 7 bit value in the array and do the same when sending it and making the last bit a 1 for a stop bit.
Something to play with I guess.
Richard
Bookmarks