Working on linux, sending data to the serial port at 115200 bauds using:
echo -e "\x1B\x11\x00\x00" > /dev/ttyAMA0
The receiver side is reading the following data:
\xF8\x1B\x11\x00\x00\x0D\x0A
I dont want \\xF8
as starting byte and \\x0D\\x0A
as tails (carriage return and new line bytes). How could I remove them? So far all I found is
stty raw -F /dev/ttyAMA0
This deactivates the \\x0D
, but i want to get rid of \\xF8
and \\x0A
and no other options have worked for me.
You can eliminate the newline with echo -en
. Or use printf
instead.
Are you sending from a raspberry pi? It seems to be a known issue that 0xF8
is sent each time the connection is opened (eg by calling echo
). I don't know if there's a fix but you can keep the connection open to prevent further 0xF8
's by using a serial terminal program.
There's an example in the third post here that shows how to keep the connection using a redirection in bash: exec 9> /dev/ttyAMA0
http://www.raspberrypi.org/forums/viewtopic.php?t=34528&p=293067
The underlying problem:
Some say it's a driver issue (see this answer ) but as far as i understand, the following indicates that it's hardware related:
http://elinux.org/RPi_Serial_Connection#Glitch_when_opening_serial_port
When the serial port is opened the voltage on TXD pulses negative for approximately 32 us (regardless of the baud rate). This pulse may be interpreted as a transmission by a device connected to the TXD pin, which could have unintended effects.
This also means that the garbage you receive is dependant on the baud rate. I wouldn't rely on a fix and look for a workaround instead.
If you have control over the receiver, you could make it wait for a self-defined sequence of bytes and only start operating after this sequence has been received.
The link to elinux.org above could give you some other ideas.
EDITED*
what about using stty to change how your device terminal is interpreting carriage return and newline character?
link
http://www.computerhope.com/unix/ustty.htm
********************OLD ANSWER*******************
What about using sed to remove "\\xF8" and "\\x0D\\x0A"?
sed -e 's/\\x0D\\x0A$//g' -e 's/^\\xF8//g' my_file > new_file
pratical example?
echo '\xF8\x1B\x11\x00\x00\x0D\x0A' |sed -e 's/\\x0D\\x0A$//g' -e 's/^\\xF8//g'
output
\x1B\x11\x00\x00
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.