How to send data to a serial port and see any answer?
On Linux, I want to send a command string (i.e. some data) to a serial port (containing control characters), and listen to the response (which also usually might contain control characters).
How can I do this as simplest as possible on Linux? An example is appreciated!
serial-port
add a comment |
On Linux, I want to send a command string (i.e. some data) to a serial port (containing control characters), and listen to the response (which also usually might contain control characters).
How can I do this as simplest as possible on Linux? An example is appreciated!
serial-port
you should look at this unix.stackexchange.com/a/116705/53092
– Kiwy
Feb 26 '14 at 12:28
I don't have interceptty installed.
– Alex
Feb 26 '14 at 12:32
nominating for re-opening - it's not a duplicate as suggested.
– peterph
Jul 1 '15 at 7:19
some people are too stupid they just suggest questions as dublicate. First bother reading the questions and answer.
– Dina
Oct 4 at 8:14
add a comment |
On Linux, I want to send a command string (i.e. some data) to a serial port (containing control characters), and listen to the response (which also usually might contain control characters).
How can I do this as simplest as possible on Linux? An example is appreciated!
serial-port
On Linux, I want to send a command string (i.e. some data) to a serial port (containing control characters), and listen to the response (which also usually might contain control characters).
How can I do this as simplest as possible on Linux? An example is appreciated!
serial-port
serial-port
asked Feb 26 '14 at 12:22
Alex
1,724154270
1,724154270
you should look at this unix.stackexchange.com/a/116705/53092
– Kiwy
Feb 26 '14 at 12:28
I don't have interceptty installed.
– Alex
Feb 26 '14 at 12:32
nominating for re-opening - it's not a duplicate as suggested.
– peterph
Jul 1 '15 at 7:19
some people are too stupid they just suggest questions as dublicate. First bother reading the questions and answer.
– Dina
Oct 4 at 8:14
add a comment |
you should look at this unix.stackexchange.com/a/116705/53092
– Kiwy
Feb 26 '14 at 12:28
I don't have interceptty installed.
– Alex
Feb 26 '14 at 12:32
nominating for re-opening - it's not a duplicate as suggested.
– peterph
Jul 1 '15 at 7:19
some people are too stupid they just suggest questions as dublicate. First bother reading the questions and answer.
– Dina
Oct 4 at 8:14
you should look at this unix.stackexchange.com/a/116705/53092
– Kiwy
Feb 26 '14 at 12:28
you should look at this unix.stackexchange.com/a/116705/53092
– Kiwy
Feb 26 '14 at 12:28
I don't have interceptty installed.
– Alex
Feb 26 '14 at 12:32
I don't have interceptty installed.
– Alex
Feb 26 '14 at 12:32
nominating for re-opening - it's not a duplicate as suggested.
– peterph
Jul 1 '15 at 7:19
nominating for re-opening - it's not a duplicate as suggested.
– peterph
Jul 1 '15 at 7:19
some people are too stupid they just suggest questions as dublicate. First bother reading the questions and answer.
– Dina
Oct 4 at 8:14
some people are too stupid they just suggest questions as dublicate. First bother reading the questions and answer.
– Dina
Oct 4 at 8:14
add a comment |
6 Answers
6
active
oldest
votes
All devices on Unix are mapped to a device file, the serial ports would be /dev/ttyS0
/dev/ttyS1
... .
First have a look at the permissions on that file, lets assume you are using /dev/ttyS1
.
ls -l /dev/ttyS1
You will want read.write access, if this is a shared system then you should consider the security consequences of opening it up for everyone.
chmod o+rw /dev/ttyS1
A very simple crude method to write to the file, would use the simple echo
command.
echo -ne '33[2J' > /dev/ttyS1
and to read
cat -v < /dev/ttyS1
You can have cat running in one terminal, and echo in a 2nd.
If everything is gibberish, then baud rate, bit settings might need setting before you start sending. stty
will do that. !! NOTE stty will use stdin as default file descriptor to affect.
Equivilent commands.
stty -speed 19200 < /dev/ttyS1
stty -speed 19200 -f /dev/ttyS1
This might be enough for you to script something and log ? Not sure what you are trying to achieve.
For a more interactive, remembers your default settings approach would be to use
minicom
it is just a program which does everything I've mentioned so far. (similar to hyperterminal in Windows, you might be familiar).
An intermediate solution, would use a terminal program like screen
which will work on a serial device.
screen /dev/ttyS1
man screen
man minicom
man stty
for more information
I'm not getting any output at all. Have any ideas?
– Goldname
Nov 10 at 1:01
Possibly hardware flow control, either switch off with atty command or strap high in serial cable, search for null modem cable.
– X Tian
Nov 10 at 9:37
# stty -speed 38400 -f /dev/ttyUSB1
returnsstty: invalid argument '-speed'
– Pro Backup
Nov 27 at 20:03
add a comment |
All you have to do is open two terminals. In the first terminal you cat
everything from the device, e.g.
cat /dev/ttyS0
in the other terminal, you can send arbitrary hex characters and text to the terminal e.g. as follows:
echo -e "x7Ex03xD0xAF und normaler Text" > /dev/ttyS0
The echo -e
command enables the interpretation of backslash escapes.
One has to make sure of course that (i) the serial settings (speed, word length, flow ctrl, etc) are correct and (ii) the serial device (on the other end) is not blocking.
You have answered this 10 mins after I wrote my answer above and you haven't added any further information at all !
– X Tian
Feb 26 '14 at 15:24
Oh sorry, I did not read your answer completly. I saw that my answer is included in yours, so I will accept your answer as the correct one, as you described just what I have described.
– Alex
Feb 26 '14 at 16:06
I don't know much about COM ports. Could you please explain what does "the serial device (on the other end) is not blocking" mean? Some issue with the firewall?
– Sopalajo de Arrierez
Sep 13 '15 at 15:55
add a comment |
Programs that talk to serial devices:
picocom
minicom
socat
or from shell you can do:
stty -speed 19200 < /dev/ttyS0 # sets the speed of the port
exec 99<>/dev/ttyS0 (or /dev/ttyUSB0...etc)
printf "ATr" >&99
read answer <&99 # this reads just a CR
read answer <&99 # this reads the answer OK
exec 99<>&-
add a comment |
This could be a better approach:
stty -F /dev/ttyUSB0 115200 raw -echo #CONFIGURE SERIAL PORT
exec 3</dev/ttyUSB0 #REDIRECT SERIAL OUTPUT TO FD 3
cat <&3 > /tmp/ttyDump.dat & #REDIRECT SERIAL OUTPUT TO FILE
PID=$! #SAVE PID TO KILL CAT
echo "R" > /dev/ttyUSB0 #SEND COMMAND STRING TO SERIAL PORT
sleep 0.2s #WAIT FOR RESPONSE
kill $PID #KILL CAT PROCESS
exec 3<&- #FREE FD 3
cat /tmp/ttyDump.dat #DUMP CAPTURED DATA
add a comment |
You can read and write to a device simulataneously like so:
cat /dev/cu.usbmodem411 & cat > /dev/cu.usbmodem411
Your message is sent to the second cat
from stdin
, and the first cat
relays the response to stdout
, turning your terminal into a chatroom.
To finish up, ctrl-c
, then run fg
then ctrl-c
again.
add a comment |
@Leonardo Mendoza
THANK YOU so much been palying around with minicom, socat and so on and your small script really solved all my probems..
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f117037%2fhow-to-send-data-to-a-serial-port-and-see-any-answer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
All devices on Unix are mapped to a device file, the serial ports would be /dev/ttyS0
/dev/ttyS1
... .
First have a look at the permissions on that file, lets assume you are using /dev/ttyS1
.
ls -l /dev/ttyS1
You will want read.write access, if this is a shared system then you should consider the security consequences of opening it up for everyone.
chmod o+rw /dev/ttyS1
A very simple crude method to write to the file, would use the simple echo
command.
echo -ne '33[2J' > /dev/ttyS1
and to read
cat -v < /dev/ttyS1
You can have cat running in one terminal, and echo in a 2nd.
If everything is gibberish, then baud rate, bit settings might need setting before you start sending. stty
will do that. !! NOTE stty will use stdin as default file descriptor to affect.
Equivilent commands.
stty -speed 19200 < /dev/ttyS1
stty -speed 19200 -f /dev/ttyS1
This might be enough for you to script something and log ? Not sure what you are trying to achieve.
For a more interactive, remembers your default settings approach would be to use
minicom
it is just a program which does everything I've mentioned so far. (similar to hyperterminal in Windows, you might be familiar).
An intermediate solution, would use a terminal program like screen
which will work on a serial device.
screen /dev/ttyS1
man screen
man minicom
man stty
for more information
I'm not getting any output at all. Have any ideas?
– Goldname
Nov 10 at 1:01
Possibly hardware flow control, either switch off with atty command or strap high in serial cable, search for null modem cable.
– X Tian
Nov 10 at 9:37
# stty -speed 38400 -f /dev/ttyUSB1
returnsstty: invalid argument '-speed'
– Pro Backup
Nov 27 at 20:03
add a comment |
All devices on Unix are mapped to a device file, the serial ports would be /dev/ttyS0
/dev/ttyS1
... .
First have a look at the permissions on that file, lets assume you are using /dev/ttyS1
.
ls -l /dev/ttyS1
You will want read.write access, if this is a shared system then you should consider the security consequences of opening it up for everyone.
chmod o+rw /dev/ttyS1
A very simple crude method to write to the file, would use the simple echo
command.
echo -ne '33[2J' > /dev/ttyS1
and to read
cat -v < /dev/ttyS1
You can have cat running in one terminal, and echo in a 2nd.
If everything is gibberish, then baud rate, bit settings might need setting before you start sending. stty
will do that. !! NOTE stty will use stdin as default file descriptor to affect.
Equivilent commands.
stty -speed 19200 < /dev/ttyS1
stty -speed 19200 -f /dev/ttyS1
This might be enough for you to script something and log ? Not sure what you are trying to achieve.
For a more interactive, remembers your default settings approach would be to use
minicom
it is just a program which does everything I've mentioned so far. (similar to hyperterminal in Windows, you might be familiar).
An intermediate solution, would use a terminal program like screen
which will work on a serial device.
screen /dev/ttyS1
man screen
man minicom
man stty
for more information
I'm not getting any output at all. Have any ideas?
– Goldname
Nov 10 at 1:01
Possibly hardware flow control, either switch off with atty command or strap high in serial cable, search for null modem cable.
– X Tian
Nov 10 at 9:37
# stty -speed 38400 -f /dev/ttyUSB1
returnsstty: invalid argument '-speed'
– Pro Backup
Nov 27 at 20:03
add a comment |
All devices on Unix are mapped to a device file, the serial ports would be /dev/ttyS0
/dev/ttyS1
... .
First have a look at the permissions on that file, lets assume you are using /dev/ttyS1
.
ls -l /dev/ttyS1
You will want read.write access, if this is a shared system then you should consider the security consequences of opening it up for everyone.
chmod o+rw /dev/ttyS1
A very simple crude method to write to the file, would use the simple echo
command.
echo -ne '33[2J' > /dev/ttyS1
and to read
cat -v < /dev/ttyS1
You can have cat running in one terminal, and echo in a 2nd.
If everything is gibberish, then baud rate, bit settings might need setting before you start sending. stty
will do that. !! NOTE stty will use stdin as default file descriptor to affect.
Equivilent commands.
stty -speed 19200 < /dev/ttyS1
stty -speed 19200 -f /dev/ttyS1
This might be enough for you to script something and log ? Not sure what you are trying to achieve.
For a more interactive, remembers your default settings approach would be to use
minicom
it is just a program which does everything I've mentioned so far. (similar to hyperterminal in Windows, you might be familiar).
An intermediate solution, would use a terminal program like screen
which will work on a serial device.
screen /dev/ttyS1
man screen
man minicom
man stty
for more information
All devices on Unix are mapped to a device file, the serial ports would be /dev/ttyS0
/dev/ttyS1
... .
First have a look at the permissions on that file, lets assume you are using /dev/ttyS1
.
ls -l /dev/ttyS1
You will want read.write access, if this is a shared system then you should consider the security consequences of opening it up for everyone.
chmod o+rw /dev/ttyS1
A very simple crude method to write to the file, would use the simple echo
command.
echo -ne '33[2J' > /dev/ttyS1
and to read
cat -v < /dev/ttyS1
You can have cat running in one terminal, and echo in a 2nd.
If everything is gibberish, then baud rate, bit settings might need setting before you start sending. stty
will do that. !! NOTE stty will use stdin as default file descriptor to affect.
Equivilent commands.
stty -speed 19200 < /dev/ttyS1
stty -speed 19200 -f /dev/ttyS1
This might be enough for you to script something and log ? Not sure what you are trying to achieve.
For a more interactive, remembers your default settings approach would be to use
minicom
it is just a program which does everything I've mentioned so far. (similar to hyperterminal in Windows, you might be familiar).
An intermediate solution, would use a terminal program like screen
which will work on a serial device.
screen /dev/ttyS1
man screen
man minicom
man stty
for more information
answered Feb 26 '14 at 14:33
X Tian
7,59711936
7,59711936
I'm not getting any output at all. Have any ideas?
– Goldname
Nov 10 at 1:01
Possibly hardware flow control, either switch off with atty command or strap high in serial cable, search for null modem cable.
– X Tian
Nov 10 at 9:37
# stty -speed 38400 -f /dev/ttyUSB1
returnsstty: invalid argument '-speed'
– Pro Backup
Nov 27 at 20:03
add a comment |
I'm not getting any output at all. Have any ideas?
– Goldname
Nov 10 at 1:01
Possibly hardware flow control, either switch off with atty command or strap high in serial cable, search for null modem cable.
– X Tian
Nov 10 at 9:37
# stty -speed 38400 -f /dev/ttyUSB1
returnsstty: invalid argument '-speed'
– Pro Backup
Nov 27 at 20:03
I'm not getting any output at all. Have any ideas?
– Goldname
Nov 10 at 1:01
I'm not getting any output at all. Have any ideas?
– Goldname
Nov 10 at 1:01
Possibly hardware flow control, either switch off with atty command or strap high in serial cable, search for null modem cable.
– X Tian
Nov 10 at 9:37
Possibly hardware flow control, either switch off with atty command or strap high in serial cable, search for null modem cable.
– X Tian
Nov 10 at 9:37
# stty -speed 38400 -f /dev/ttyUSB1
returns stty: invalid argument '-speed'
– Pro Backup
Nov 27 at 20:03
# stty -speed 38400 -f /dev/ttyUSB1
returns stty: invalid argument '-speed'
– Pro Backup
Nov 27 at 20:03
add a comment |
All you have to do is open two terminals. In the first terminal you cat
everything from the device, e.g.
cat /dev/ttyS0
in the other terminal, you can send arbitrary hex characters and text to the terminal e.g. as follows:
echo -e "x7Ex03xD0xAF und normaler Text" > /dev/ttyS0
The echo -e
command enables the interpretation of backslash escapes.
One has to make sure of course that (i) the serial settings (speed, word length, flow ctrl, etc) are correct and (ii) the serial device (on the other end) is not blocking.
You have answered this 10 mins after I wrote my answer above and you haven't added any further information at all !
– X Tian
Feb 26 '14 at 15:24
Oh sorry, I did not read your answer completly. I saw that my answer is included in yours, so I will accept your answer as the correct one, as you described just what I have described.
– Alex
Feb 26 '14 at 16:06
I don't know much about COM ports. Could you please explain what does "the serial device (on the other end) is not blocking" mean? Some issue with the firewall?
– Sopalajo de Arrierez
Sep 13 '15 at 15:55
add a comment |
All you have to do is open two terminals. In the first terminal you cat
everything from the device, e.g.
cat /dev/ttyS0
in the other terminal, you can send arbitrary hex characters and text to the terminal e.g. as follows:
echo -e "x7Ex03xD0xAF und normaler Text" > /dev/ttyS0
The echo -e
command enables the interpretation of backslash escapes.
One has to make sure of course that (i) the serial settings (speed, word length, flow ctrl, etc) are correct and (ii) the serial device (on the other end) is not blocking.
You have answered this 10 mins after I wrote my answer above and you haven't added any further information at all !
– X Tian
Feb 26 '14 at 15:24
Oh sorry, I did not read your answer completly. I saw that my answer is included in yours, so I will accept your answer as the correct one, as you described just what I have described.
– Alex
Feb 26 '14 at 16:06
I don't know much about COM ports. Could you please explain what does "the serial device (on the other end) is not blocking" mean? Some issue with the firewall?
– Sopalajo de Arrierez
Sep 13 '15 at 15:55
add a comment |
All you have to do is open two terminals. In the first terminal you cat
everything from the device, e.g.
cat /dev/ttyS0
in the other terminal, you can send arbitrary hex characters and text to the terminal e.g. as follows:
echo -e "x7Ex03xD0xAF und normaler Text" > /dev/ttyS0
The echo -e
command enables the interpretation of backslash escapes.
One has to make sure of course that (i) the serial settings (speed, word length, flow ctrl, etc) are correct and (ii) the serial device (on the other end) is not blocking.
All you have to do is open two terminals. In the first terminal you cat
everything from the device, e.g.
cat /dev/ttyS0
in the other terminal, you can send arbitrary hex characters and text to the terminal e.g. as follows:
echo -e "x7Ex03xD0xAF und normaler Text" > /dev/ttyS0
The echo -e
command enables the interpretation of backslash escapes.
One has to make sure of course that (i) the serial settings (speed, word length, flow ctrl, etc) are correct and (ii) the serial device (on the other end) is not blocking.
edited Feb 26 '14 at 15:17
X Tian
7,59711936
7,59711936
answered Feb 26 '14 at 14:43
Alex
1,724154270
1,724154270
You have answered this 10 mins after I wrote my answer above and you haven't added any further information at all !
– X Tian
Feb 26 '14 at 15:24
Oh sorry, I did not read your answer completly. I saw that my answer is included in yours, so I will accept your answer as the correct one, as you described just what I have described.
– Alex
Feb 26 '14 at 16:06
I don't know much about COM ports. Could you please explain what does "the serial device (on the other end) is not blocking" mean? Some issue with the firewall?
– Sopalajo de Arrierez
Sep 13 '15 at 15:55
add a comment |
You have answered this 10 mins after I wrote my answer above and you haven't added any further information at all !
– X Tian
Feb 26 '14 at 15:24
Oh sorry, I did not read your answer completly. I saw that my answer is included in yours, so I will accept your answer as the correct one, as you described just what I have described.
– Alex
Feb 26 '14 at 16:06
I don't know much about COM ports. Could you please explain what does "the serial device (on the other end) is not blocking" mean? Some issue with the firewall?
– Sopalajo de Arrierez
Sep 13 '15 at 15:55
You have answered this 10 mins after I wrote my answer above and you haven't added any further information at all !
– X Tian
Feb 26 '14 at 15:24
You have answered this 10 mins after I wrote my answer above and you haven't added any further information at all !
– X Tian
Feb 26 '14 at 15:24
Oh sorry, I did not read your answer completly. I saw that my answer is included in yours, so I will accept your answer as the correct one, as you described just what I have described.
– Alex
Feb 26 '14 at 16:06
Oh sorry, I did not read your answer completly. I saw that my answer is included in yours, so I will accept your answer as the correct one, as you described just what I have described.
– Alex
Feb 26 '14 at 16:06
I don't know much about COM ports. Could you please explain what does "the serial device (on the other end) is not blocking" mean? Some issue with the firewall?
– Sopalajo de Arrierez
Sep 13 '15 at 15:55
I don't know much about COM ports. Could you please explain what does "the serial device (on the other end) is not blocking" mean? Some issue with the firewall?
– Sopalajo de Arrierez
Sep 13 '15 at 15:55
add a comment |
Programs that talk to serial devices:
picocom
minicom
socat
or from shell you can do:
stty -speed 19200 < /dev/ttyS0 # sets the speed of the port
exec 99<>/dev/ttyS0 (or /dev/ttyUSB0...etc)
printf "ATr" >&99
read answer <&99 # this reads just a CR
read answer <&99 # this reads the answer OK
exec 99<>&-
add a comment |
Programs that talk to serial devices:
picocom
minicom
socat
or from shell you can do:
stty -speed 19200 < /dev/ttyS0 # sets the speed of the port
exec 99<>/dev/ttyS0 (or /dev/ttyUSB0...etc)
printf "ATr" >&99
read answer <&99 # this reads just a CR
read answer <&99 # this reads the answer OK
exec 99<>&-
add a comment |
Programs that talk to serial devices:
picocom
minicom
socat
or from shell you can do:
stty -speed 19200 < /dev/ttyS0 # sets the speed of the port
exec 99<>/dev/ttyS0 (or /dev/ttyUSB0...etc)
printf "ATr" >&99
read answer <&99 # this reads just a CR
read answer <&99 # this reads the answer OK
exec 99<>&-
Programs that talk to serial devices:
picocom
minicom
socat
or from shell you can do:
stty -speed 19200 < /dev/ttyS0 # sets the speed of the port
exec 99<>/dev/ttyS0 (or /dev/ttyUSB0...etc)
printf "ATr" >&99
read answer <&99 # this reads just a CR
read answer <&99 # this reads the answer OK
exec 99<>&-
edited Oct 10 at 18:08
answered Dec 27 '16 at 12:03
Zibri
14016
14016
add a comment |
add a comment |
This could be a better approach:
stty -F /dev/ttyUSB0 115200 raw -echo #CONFIGURE SERIAL PORT
exec 3</dev/ttyUSB0 #REDIRECT SERIAL OUTPUT TO FD 3
cat <&3 > /tmp/ttyDump.dat & #REDIRECT SERIAL OUTPUT TO FILE
PID=$! #SAVE PID TO KILL CAT
echo "R" > /dev/ttyUSB0 #SEND COMMAND STRING TO SERIAL PORT
sleep 0.2s #WAIT FOR RESPONSE
kill $PID #KILL CAT PROCESS
exec 3<&- #FREE FD 3
cat /tmp/ttyDump.dat #DUMP CAPTURED DATA
add a comment |
This could be a better approach:
stty -F /dev/ttyUSB0 115200 raw -echo #CONFIGURE SERIAL PORT
exec 3</dev/ttyUSB0 #REDIRECT SERIAL OUTPUT TO FD 3
cat <&3 > /tmp/ttyDump.dat & #REDIRECT SERIAL OUTPUT TO FILE
PID=$! #SAVE PID TO KILL CAT
echo "R" > /dev/ttyUSB0 #SEND COMMAND STRING TO SERIAL PORT
sleep 0.2s #WAIT FOR RESPONSE
kill $PID #KILL CAT PROCESS
exec 3<&- #FREE FD 3
cat /tmp/ttyDump.dat #DUMP CAPTURED DATA
add a comment |
This could be a better approach:
stty -F /dev/ttyUSB0 115200 raw -echo #CONFIGURE SERIAL PORT
exec 3</dev/ttyUSB0 #REDIRECT SERIAL OUTPUT TO FD 3
cat <&3 > /tmp/ttyDump.dat & #REDIRECT SERIAL OUTPUT TO FILE
PID=$! #SAVE PID TO KILL CAT
echo "R" > /dev/ttyUSB0 #SEND COMMAND STRING TO SERIAL PORT
sleep 0.2s #WAIT FOR RESPONSE
kill $PID #KILL CAT PROCESS
exec 3<&- #FREE FD 3
cat /tmp/ttyDump.dat #DUMP CAPTURED DATA
This could be a better approach:
stty -F /dev/ttyUSB0 115200 raw -echo #CONFIGURE SERIAL PORT
exec 3</dev/ttyUSB0 #REDIRECT SERIAL OUTPUT TO FD 3
cat <&3 > /tmp/ttyDump.dat & #REDIRECT SERIAL OUTPUT TO FILE
PID=$! #SAVE PID TO KILL CAT
echo "R" > /dev/ttyUSB0 #SEND COMMAND STRING TO SERIAL PORT
sleep 0.2s #WAIT FOR RESPONSE
kill $PID #KILL CAT PROCESS
exec 3<&- #FREE FD 3
cat /tmp/ttyDump.dat #DUMP CAPTURED DATA
answered Jun 19 '17 at 23:27
Leonardo Mendoza
311
311
add a comment |
add a comment |
You can read and write to a device simulataneously like so:
cat /dev/cu.usbmodem411 & cat > /dev/cu.usbmodem411
Your message is sent to the second cat
from stdin
, and the first cat
relays the response to stdout
, turning your terminal into a chatroom.
To finish up, ctrl-c
, then run fg
then ctrl-c
again.
add a comment |
You can read and write to a device simulataneously like so:
cat /dev/cu.usbmodem411 & cat > /dev/cu.usbmodem411
Your message is sent to the second cat
from stdin
, and the first cat
relays the response to stdout
, turning your terminal into a chatroom.
To finish up, ctrl-c
, then run fg
then ctrl-c
again.
add a comment |
You can read and write to a device simulataneously like so:
cat /dev/cu.usbmodem411 & cat > /dev/cu.usbmodem411
Your message is sent to the second cat
from stdin
, and the first cat
relays the response to stdout
, turning your terminal into a chatroom.
To finish up, ctrl-c
, then run fg
then ctrl-c
again.
You can read and write to a device simulataneously like so:
cat /dev/cu.usbmodem411 & cat > /dev/cu.usbmodem411
Your message is sent to the second cat
from stdin
, and the first cat
relays the response to stdout
, turning your terminal into a chatroom.
To finish up, ctrl-c
, then run fg
then ctrl-c
again.
answered Dec 14 '16 at 17:09
diachedelic
1212
1212
add a comment |
add a comment |
@Leonardo Mendoza
THANK YOU so much been palying around with minicom, socat and so on and your small script really solved all my probems..
New contributor
add a comment |
@Leonardo Mendoza
THANK YOU so much been palying around with minicom, socat and so on and your small script really solved all my probems..
New contributor
add a comment |
@Leonardo Mendoza
THANK YOU so much been palying around with minicom, socat and so on and your small script really solved all my probems..
New contributor
@Leonardo Mendoza
THANK YOU so much been palying around with minicom, socat and so on and your small script really solved all my probems..
New contributor
New contributor
answered 11 mins ago
Phil.F
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f117037%2fhow-to-send-data-to-a-serial-port-and-see-any-answer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
you should look at this unix.stackexchange.com/a/116705/53092
– Kiwy
Feb 26 '14 at 12:28
I don't have interceptty installed.
– Alex
Feb 26 '14 at 12:32
nominating for re-opening - it's not a duplicate as suggested.
– peterph
Jul 1 '15 at 7:19
some people are too stupid they just suggest questions as dublicate. First bother reading the questions and answer.
– Dina
Oct 4 at 8:14