I'm trying to create a serial port in python. I'm going to use it to communicate with another program that is communicating via a serial port. the PySerial package seems fine but I can't get it working. I've looked eveywhere and every implementation is for linux. Can anyone help me create a COM port on windows and read/write to it?
It is not possible to create a serial port in Python, because you need a special driver for this task. You can only call 3rd party utility (with the drivers) that will do it for you.
I would recommend to try the following utilities:
Com0Com: http://sourceforge.net/projects/com0com/
Virtual Null Modem: http://www.virtual-null-modem.com/
Related
I have a python script that talks to an external device through a COM port. I'm trying to make unit tests for this and I would like to write something that can act as a simulated COM port so I can run these tests without the machine that the script usually uses.
It seems like virtual COM ports are what I need but I haven't been able to find any clear python implementations of this. I'm not sure the best way to do this but I've been thinking that a script that I could leave running would read the virtual port and write back to it whenever the tests are running.
Im trying to see what pyserial is writing in Putty, later on I would like to try CubeIDE STM32 to receive this data as well.
Putty gives me a port is being used error. How can I check what Python is writing to COM5?
You can use programs like for example Virtual Serial Port Driver. It can create linked virtual COM ports ,one to write and second to read data.
I cant seem to find an easy to use wifi module that enables connection establishing that works with windows.
If you want to manage wirless network in Python, you should refer to the DDL for Wlan API and use ctypes to open it in Python.
You can find an example of such code in this previous question.
I'm writing a Python script which connects to remote hosts over a (super complicated) SOCKS/SSL tunnel. I am able to establish connections to IPs in a remote intranet on any port.
What I'm hoping to do is set up this python script to use IP addresses in the local loopback range (127.0.x.x) to become (maybe with the help of the hosts file) a 'replica' of the remote systems, and hence enable me to use applications which don't support proxies. The problem is that I don't always know what ports they're trying to connect to. It seems the only way to work this out is to bind sockets to all 65536 ports, which seems a little crazy. So two questions:
Is it crazy? Can I just set up a python list of sockets from 1-65536?
Or is there a better way I should be doing this? Can I monitor connections to an IP somehow and bind the ports just before they're needed?
I want to avoid using too much platform-dependent or non-python code if possible.
EDIT: To clarify, I'm only writing the client here - I have no control over the server. Believe me, if I had control over the server side of it I would not be doing it with SOCKS/SSL/CRAM :)
What about going lower level and interfacing a library designed for network analyzers like pycap?
This way you could detect all connection attempts and find the ports that you need to expose or may be you can just route the packets directly assuming the library in addition to packet detection can also do packet injection (pypcap page says this feature is experimental).
This would IMO make sense in python only for slow applications however...
Pycap seems to be developed for linux, but the core capturing is done by libpcap and for windows there is a similar library winpcap.
Matt,
If using windows your best shot is something like OpenVPN over the tunnel. OpenVPN requires only one TCP port/stream and gives you a pair of virtual interfaces with full connectivity.
[updated]
It may be possible using a TUN/TAP driver on the client side. See this unix version for ideas.
I am testing a piece of hardware which hosts an ftp server. I connect to the server in order to configure the hardware in question.
My test environment is written in Python 3.
To start the ftp server, I need to launch a special proprietary terminal application on my pc. I must use this software as far as I know and I have no help files for it. I do however know how to use it to launch the ftp server and that's all I need it for.
When I start this app, I go to the menu and open a dialog where I select the com port/speed the hardware is connected to. I then enter the command to launch the ftp server in a console like window within the application. I am then prompted for the admin code for the hardware, which I enter. When I'm finished configuring the device, I issue a command to restart the hardware's software.
In order for me to fully automate my tests, I need to remove the manual starting of this ftp server for each test.
As far as I know, I have two options:
Windows GUI automation
Save the stream of data sent on the com port when using this application.
I've tried to find an GUI automater but pywinauto isn't supporting Python 3. Any other options here which I should look at?
Any suggestions on how I can monitor the com port in question and save the traffic on it?
Thanks,
Barry
Have you looked at pySerial? It's been a few years since I've used it but it was quite good at handling RS-232 communications and it looks like it's compatible with Python 3.x.
Sikuli might provide the kind of GUI automation you need.
I was also able to solve this using WScript, but pySerial was the preferred solution.