j6m8
j6m8

Reputation: 2409

Serial ports not being recognized or found by PySerial

On my new Dell XPS laptop, I've just started loading all of my goodies on -- and I'm embarrassed to say that I can't get pyserial to work properly in Python 2.7. I ask it to do the following:

import serial

s = serial.Serial(0)
s.write("Hello world!")
s.close()

...and the darn thing gives me the following (code simplified to the real problem so you don't have to scrub through forests of my poorly written Python):

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

I've tried asking for a port explicitly (s = serial.Serial(port="COM1", baudrate=9600) but to no avail. I've also tried COM2, COM3, COM4, etc... But I'm not sure how high it's really worth going if they all return the same SerialException, ya dig?

The reason I mention my laptop model is because I've heard rumors that Dell is slowly killing off its serial connectivity, but quite frankly, I don't know nearly enough about serial-ness to even pretend to know what I'm talking about here. So I hereby bequeath this mission upon you experts.

Thanks for any help you can give!

Upvotes: 2

Views: 4844

Answers (1)

detly
detly

Reputation: 30342

Are you sure you have a serial port? Your description of the problem suggests that you don't. I'd be quite surprised if a laptop built within the last ten years would actually have one.

I could be wrong though (I'm trying to find it in the specs of the XPS as I write this). At any rate, if you're running Windows you can look in the Device Manager under Ports (COM & LPT)... although beware, some PCs will show a couple of serial ports here that are actually used for purely internal purposes.

If you don't have a serial port, you need to get a USB-to-serial adapter. Look in the Device Manager to find the name of the port.

You can get USB/serial adapters from some electronic stores or office supply stores, and off eBay.

Upvotes: 3

Related Questions