Examples of reading binary and writing binary from shell command line. It needs
the hexdump command on the target.
The echo shell command can also write binary values. Check the man pages for the
detailed description. With the echo command, we can set the previously configured
output pins “high” by writing 0x0000000F to the device file. The following command
does the trick:
echo –ne “\x00\x00\x00\x0F” > /dev/gpio0
To read out the pin state, the use of the commands less or cat is not adequate
because these applications expect an ASCII string, so the output is neither readable
nor interpretable. For this purpose the dd and hexdump tools are more suitable. To
read out the four bytes, use these commands in following constellation:
dd bs=4 count=1 if=/dev/gpio0 2> /dev/zero | hexdump
The dd program reads out the four bytes (bs=number of bytes, count=how many
times to read out bs bytes) from /dev/gpio0, dumps any error messages to /dev/zero
and pipes the data to hexdump. The hexdump program will print out the four bytes as
a nice hexadecimal value.