I have to read a stream which is sent from a homemade device over the serial port. The problem is that it should be deployed on a machine where I don't have access to install anything new, which means I have to use the python standard libraries to do this. Is this possible, and if so, how can I manage this.
If it turns out to be almost impossible, I will have to get someone to install pySerial, but I would really appreciate it if it could be done without this.
If there is differences in Linux/Windows, this is on a Windows machine, but I would really appreciate a cross platform solution.
On Unix-like operating systems, the serial port work just like a file, and you simply open it and read or write bytes. There are some extra calls you can make to set the baud rate and whatnot, but that's essentially all there is.
On Windows, you open the serial port like a file, but you must use some particular ways of accessing it that are slightly different from what Python uses for normal files. Unfortunately it is difficult to successfully access a Windows serial port using only native Python libraries.
The pyserial
library provides a uniform, cross-platform way of accessing serial ports. It relies on ctypes
, which is in the standard library since Python 2.5, so you may be able to include pyserial
with your application and just use that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With