0

I call a C-subprocess from python using subprocess.Popen(..) Within the executable, a COM port is opened for communication with a serial device, using CreateFile(...).

Is it possible, to open the serial port already in python using pyserial and pass some "file handle" to the executable?

At least I can pass stdin, stdout and stderr as file descriptors (int) or file objects. But I don't know, how I could convert a Serial object to a one of the options above. Maybe it is not possible at all, but I ask anyway...

The question shall be a workaround related to USB VCP connection fails occasionally because repeatedly opening and closing the COM Port fails after some thousand times. The executable is called very often (each time with other parameters for test purposes), but it wouldn't be necessary to re-open the COM Port every time.

Of course it would be better to fix the problem with CreateFile(), but I invested days to find a problem and came finally to the conclusion, that it is not in my hands anymore...

MichaelW
  • 1,328
  • 1
  • 15
  • 32

1 Answers1

0

I found a workaround by using a pipe to redirect serial output to python. Works now.

MichaelW
  • 1,328
  • 1
  • 15
  • 32