Thanks for the compliment... I'm told I look better in real-life than in the photo...
Code:
CommsPort var PortE.0
SEROUT CommsPort,t9600,[REP $00\16,13,10,"Z-"]
CheckDigit=0
For CounterA=0 to 8
CheckDigit=CheckDigit ^ MyWordArray.Lowbyte(CounterA)
SEROUT CommsPort,t9600,[HEX2 MywordArray.Lowbyte(CounterA)]
Next CounterA
SEROUT CommsPort,t9600,[HEX2 CheckDigit,13,10]
Quickly thrown together...
The first SEROUT flushes any trash out of the receiving buffer (if there is one) and provides a unique qualifier to lock up on which is unlike any possible Data combination... If you're transmitting by wireless, that Lead-In also wakes up the Data-Slicer.
The For-Next Loop transmits your Data Array and doubles in creating a CheckDigit...
The last SEROUT transmits the CheckDigit (so the receiver can verify a good Data packet has been received) and terminates the packet with a Return/Line-Feed combination (again forcing any remaining Data out of the Receivers buffers if Hardware USARTS are being employed).
The bonus here is that you can "break-in" to the transmission and make a connection say to Hyperterminal and "see" the transmitted packet and check each Byte manually if you need to do any Debugging. You don't see the Lead-In, and each packet of Data is on a unique Line on the display on it's own, prefixed with a 'Z-'.
The receiver captures the string of Hex (you don't need to bother capturing the CR/LF - 13/10 - at the end), verifies good Data against the Transmitted CheckDigit and reconstructs the Word Array from the Hex. Simple and Safe.
Bookmarks