0

I've been trying to do a simple thing (under windows it IS very simple) as reading RS-232 data and sending it as keystrokes. I tried softwedge - which is supposed to do exactly that - unfortunately not exactly working (buggy, sends a lot of garbage). All a was able to do is:

screen /dev/ttyUSB0 9600,cs8,-parenb,-cstopb,-hupcl

which displays the data from my card reader every time I use RFID card (the same thing works with minicom). But how to send it as keystrokes to an active application?

P.S.: I'm using Raspberry Pi2

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • It's been a while but I think your on the right track and are 99% of the way there. It is Very very easy to do in LInux even easier then windows. Let me see if I can remember how. – coteyr Sep 18 '15 at 07:31

1 Answers1

1

This is a two step process in Linux.

First, if needed (usually not for most common serial devices) set the speed. Most work fine at the default (9600 last time I looked), and you really only need to set speed of your trying to cram lots of data (i.e. a modem) or the device requires it. To set the speed you use stty to do that.

stty -speed 19200 -f /dev/something

Second you will have an eaiser time of you open two terminals one for input and one for output (though it's not "needed" it does make this a lit easier)

To read from the device (or any thing) you

cat /dev/something or better yet cat -v < /dev/something give them both a try and see which you like better.

On the input side, to send to your device

echo -ne 'your gibberish here' > /dev/something should work just fine.

All your really doing is reading and writing to a "file". That's it.

For more info you can look at https://askubuntu.com/questions/411108/how-to-write-characters-to-serial-port or How to send data to a serial port and see any answer? and http://papers.mpastell.com/serial.pdf

Don't get discouraged. Sometimes it can be a bit rough coming from Windows to Linux. You expecting a complicated answer and it's usually quite simple.

coteyr
  • 4,310
  • Thanks for your quick reply. The problem is, that when I use above command cat /dev/ttyUSB0 or the second one, I get the same problem as with Softwedge. My device is transmitting "sFF01" text all the time and cannot even read my RFID - it stops reading and only sends "sFF01". My guess is, that Screen or Minicom are able to filter this. – Petr G. Sep 18 '15 at 09:19
  • No idea what sFF01 is, but check your baud-rate, (stty). The fact that gour getting sFF01 means it's working, you just have to get it initialized or set the baud rate or something. – coteyr Sep 18 '15 at 17:14
  • hmmm, strange. I tried to set it the same way as I set "screen" command (which was working and displayed only relevant data)

    stty -F /dev/ttyUSB0 9600 -parenb cs8 cstopb hupcl

    and it still sends nonsense when I type

    cat /dev/ttyUSB0

    BUT, when I start minicom or screen and THEN I start

    cat /dev/ttyUSB0

    it is ok and I see only data from my RFID card. Unfortunately, I still do not know how to send this output (my RFID card number) as a keystroke to any active app (e.g. active window of my text editor)

    – Petr G. Sep 22 '15 at 09:13