views:

79

answers:

1

In Hyperterminal I am able to connect to a serial port called "X64-CL_iPro_1_Serial_0" where I am able to send/receive ASCII text to a camera. However when I try to connect to the same port with pySerial, it throws an exception:

SerialException: could not open port X64-CL_iPro_1_Serial_0: [Error 2] The system cannot find the file specified.

I don't understand why Hyperterminal can detect the port and communicate with it, but Python can't. I downloaded this script from the pySerial website that displays a list of serial ports, and the only ports it came up with was COM1 and COM2, neither of which I can connect to.

My code is very simple, and looks like this:

import serial
port = "X64-CL_iPro_1_Serial_0"
ser = serial.Serial(port)

Am I doing anything wrong? Is there a way to work around this? Thanks ahead of time.

Edit: It should also be noted that this port does not show up in the device manager, and neither does COM1 or COM2.

+1  A: 

The problem lies in the enumeration code you linked. It is wrong in two regards:

  1. It uses a fixed GUID_CLASS_COMPORT to enumerate. It should instead ask the GUID through SetupDiClassGuidsFromName, passing "Ports" as description of the class for which it is asking for names.
  2. The code insists of asking for the friendly name of the port. But if the only goal is to open the device (instead of displaying to an user), it should directly access the DevicePath element, which is a weird-looking-but-perfectly-valid port name to pass to pySerial. The friendly name might even be totally missing.
Giovanni Bajo