Receiving raw hex or binary from serial port in Linux shell
Receiving raw hex or binary from serial port in Linux shell
(OP)
I am working with some AXIS network cameras (namely the AXIS 221 and the AXIS 2420). The cameras contain a web server using an ETRAX 100(LX) CRIS processor running ELinux. I can use Telnet to access the shell (mish) as root.
I would like to interface a Dallas Semiconductor 1-Wire temperature sensor (most likely the DS18B20) via the serial port. I am using the DS9097U-009 RS-232 to 1-Wire adapter as the interface between the camera and the temperature sensor. The adapter contains a DS2480B serial 1-Wire line driver.
I am able to successfully transfer commands to the 1-Wire adapter using:
echo -n "\[three-digit octal number]" >/dev/ttyS1
Incidentally, the following does not output the intended hexadecimal number:
echo -n "\x[two digit hexadecimal number]" >/dev/ttyS1
It outputs \xFF. But I have already converted all of the required 1-Wire commands to octal.
The temperature sensor outputs a 16-bit code through the 1-Wire adapter to represent the temperature. However, I cannot seem to find a way to receive the raw 16-bit number. I am currently using the following command to receive the data:
dd if=/dev/ttyS1 bs=1 count=2
The input is converted into ASCII before being displayed or saved. How can I receive the 16-bit number that I can later convert to a decimal number?
Thank you in advance!
P.S. I have not had much experience with Linux. Most of my programming has been for Microchip PIC microcontrollers.
I would like to interface a Dallas Semiconductor 1-Wire temperature sensor (most likely the DS18B20) via the serial port. I am using the DS9097U-009 RS-232 to 1-Wire adapter as the interface between the camera and the temperature sensor. The adapter contains a DS2480B serial 1-Wire line driver.
I am able to successfully transfer commands to the 1-Wire adapter using:
echo -n "\[three-digit octal number]" >/dev/ttyS1
Incidentally, the following does not output the intended hexadecimal number:
echo -n "\x[two digit hexadecimal number]" >/dev/ttyS1
It outputs \xFF. But I have already converted all of the required 1-Wire commands to octal.
The temperature sensor outputs a 16-bit code through the 1-Wire adapter to represent the temperature. However, I cannot seem to find a way to receive the raw 16-bit number. I am currently using the following command to receive the data:
dd if=/dev/ttyS1 bs=1 count=2
The input is converted into ASCII before being displayed or saved. How can I receive the 16-bit number that I can later convert to a decimal number?
Thank you in advance!
P.S. I have not had much experience with Linux. Most of my programming has been for Microchip PIC microcontrollers.
---------------------------------------------------------
Operation Radiation: http://www.mrkenneth.com





RE: Receiving raw hex or binary from serial port in Linux shell
Turn off the canatonical processing of the incoming serial
data stream and use the read function to read the 4 bytes
of data. Optionally, you might have to read the carriage
return and line feed (so the read will be 6 characters in
length, not four). Then it is a simple procedure to
convert the binary to hex, octal, or whatever.
You might want to point your browser to:
http
and/or
http://www.win.tue.nl/~aeb/linux/lk/lk-11.html
and, although I haven't looked at it in detail you might
also like:
ht
Hope that these help!
Cheers,
Rich S.