2

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!

MPelletier
  • 16,256
  • 15
  • 86
  • 137
j6m8
  • 2,261
  • 2
  • 26
  • 34

1 Answers1

3

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.

detly
  • 29,332
  • 18
  • 93
  • 152
  • That's what I suspected -- oy. Thanks so much for your help, although this does not bode well for me, since this project was going to be a communication between webcam, python, and arduino -- so, essentially, serial, serial, and serial. I guess it's off to Radio Shack or eBay -- thanks again! – j6m8 Jun 14 '12 at 00:51
  • @j6m8 Well, I've used USB/serial adapters on a huge range of PCs running every version of Windows from 2000 to 7, Debian, Emdebian, Ubuntu and Slackware — they've always just worked out of the box. I think you'll be fine, just beware of Windows 7 compatibility for drivers (if that's the OS you're using). Running the webcam might be a separate issue though — you'll have to find out what kind of protocol or connection that uses. – detly Jun 14 '12 at 00:54
  • I guess this question is dead, but I'm using a built-in cam, so magically, everything just WORKS. It's such a relief after my last computer where the webcam would go to sleep whenever it wasn't being used, and lose its connection to the computer. Every program I wrote had to constantly ping the cam or it would go on vacation and leave no forwarding address. – j6m8 Jun 14 '12 at 01:26
  • @j6m8 - maybe it just didn't find you interesting enough :P – detly Jun 14 '12 at 01:55
  • That is quite possible. I'm pretty damn boring. That being said -- do you know of any ways to get Python to talk to, say, Arduino, without using that serial dealio? I feel like that might be the only way. Which is sad. – j6m8 Jun 15 '12 at 14:13
  • I haven't used an Arduino set, but it looks like they simply have a USB-to-serial interface built in. If you plug the board in via USB, look in the device manager to see if a COM port becomes available. – detly Jun 16 '12 at 06:18
  • AHA. Brilliant. This is still moderately inconvenient for the project, but... So it goes. Thanks! – j6m8 Jul 18 '12 at 00:19
  • @j6m8 - Take a look at the question [What is the cross-platform method of enumerating serial ports in Python (including virtual ports)?](http://stackoverflow.com/questions/11303850/what-is-the-cross-platform-method-of-enumerating-serial-ports-in-python-includi) if you need code to detect the port programatically :) – detly Jul 18 '12 at 00:44