I am working on an application where I have part of an embedded linux system transferring some data to a PC utilizing PySerial (a Python module). My question is: is there an alternative to finding a PC with an RS232 connector in order to establish two way communication between the PC and embedded system? Thanks.
A USB-Serial adapter will do what you want, they're available and cheap. However they will most likely come with a RS232 SUB-D connector and output RS232 voltage levels, which then need conversion.
You can also find USB-Serial cables with pin headers and nice easy 3.3V levels, much simpler to use in your application.
So you want to link your two devices via USB. Since you say the embedded device uses Linux, it must have Python. Depending on throughput and complexity, there are many solutions..
- If your embedded board has Ethernet... just use that!
- Two USB-Serial adapters back to back (speed is limited though)
- The "USB to USB file transfer cable" which actually emulates an Ethernet port for each USB ports, so both devices are networked together.
- Program the embedded board to act as a USB device, there are libraries to do this on Linux, I tried to google a bit and found this and this for example.
I've programmed a USB device on a Cortex-M4, it isn't rocket science but it does take a while. So if you need lowest possible cost, this would be the best, as all you need is a cable. If this is a one-off or personal project, I'd rather recommend the other solutions.
@peufeu is on the right track with using two USB-to-Serial adapters. But there's a very important thing missing: You will need a "null modem" adapter between them.
For a particular connector type (either 9-pin or 25-pin) there are two types of RS-232 wiring: "DTE" (Data Terminal Equipment) which is typically a PC, and "DCE" (Data Communications Equipment) which can be a telephone modem or similar gear. (If you're young you'll say what the heck is a telephone modem!)
So a DTE (PC) will transmit data on pin 3 and receive data on pin 2, while a DCE (modem) receives data on pin 3 and transmits on pin 2.
The problem is the USB-to-Serial adapter is typically wired as a DTE so if you just wire them straight, they both try to send data to the same pin 3 and receive on the same pin 2.
So a null modem is either a cable or back-to-back connectors where the RX and TX pins are swapped around so they transmit and receive data on the correct pins.
Additionally, the handshaking pins are swapped around so they appear correct.
So, bottom line, it makes the DTE on the other side look just like a DCE and the two computers can talk to each other and handshake works correctly.
Here's an image from Wikipedia that helps visualize what's going on:
The full entry is here: https://en.wikipedia.org/wiki/Null_modem
You can cut off the connectors and wire them together yourself. The bare minimum setup would be to ignore all the handshaking lines and just connect 3 wires: wire GND pin 5 together, and wire pins 2 and 3 swapped (2 of one goes to 3 of the other and vice versa). That's it.
Here's a snippet of handshaking: The DTE raises RTS (request to send) high and the modem if it is ready to get data should raise CTS (clear to send) high. When the modem is busy and cannot accept data at the time it lowers CTS.
So in the minimum setup none of those wires are connected so you'd have to disable handshaking in your SW and assume the other guy is ready to receive whenever you transmit.