Scope
This mini guide explains how to append messages with CRCs and send them to a serial port. Operating a serial port from the Linux Bash shell is very obscure and precious few people know how to do it.Once you know the tricks, it is extremely powerful and a big time saver over the more complicated and error prone alternatives.
Also see this: http://www.aeronetworks.ca/2014/07/fletcher-checksum-calculator-in-bash.html
Get a set of CRC utilities from here:
http://www.hampa.ch/misc-utils/index.html
http://www.hampa.ch/misc-utils/misc-utils-0.2.2.tar.gz
Install the tools:
$ cd
$ mkdir misc
$ cd misc
$ wget http://www.hampa.ch/misc-utils/misc-utils-0.2.2.tar.gz
$ tar -zxvf misc-utils-0.2.2.tar.gz
$ ./configure
$ make
$ su
password
# make install
CRC Message Preparation:
Prepare a message step by step:
$ echo -en "\xa5\x10\x01\xca" > msg
$ hex msg
A5 10 01 CA # 00000000 ....
$ crc -g crc16 msg
41cf
Or modify the message file on the fly:
$ crc -b -g crc16 msg >> msg
$ hex msg
A5 10 01 CA 41 CF # 00000000 ....A.
$ echo -en "\xa5\x10\x01\xca" | crc -b -g crc16 - >> msg
Serial Port Tricks
Set the serial port in raw mode and configure it:
# stty -F /dev/ttyUSB0 raw
# stty -F /dev/ttyUSB0 19200
Prepare a message with a CRC16 and send it straight to the serial port:
$ echo -en "\xa5\x10\x01\xca" | crc -b -g crc16 - >> /dev/ttyUSB0
Serial Port Tips
www.aeronetworks.ca/2015/01/serial-port-io.htmlwww.aeronetworks.ca/2014/10/serial-ports-revisited.html
www.aeronetworks.ca/2014/01/crcs-and-serial-ports.html
www.aeronetworks.ca/2013/10/serial-port-tricks.html
www.aeronetworks.ca/2013/05/usb-serial-device-with-unknown-ids.html
www.aeronetworks.ca/2015/10/reading-and-parsing-data-from-serial.html
www.aeronetworks.ca/2013/05/compile-moxa-serial-widget-device.html
La voila!
Herman
Comments
Post a Comment
On topic comments are welcome. Junk will be deleted.