Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,260 Programmers. There are 1,935 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Accessing the Serial port

 
Reply to this topicStart new topic

Accessing the Serial port, Using Python with pyserial

Xiph
post 20 Apr, 2008 - 05:30 PM
Post #1


New D.I.C Head

*
Joined: 9 Nov, 2006
Posts: 8



I have a webcam that I would like to be able to steer in X and Y way. To that I'm going to use two engines and some Lego. The two engines are connected to a microprocessor which is connected to the COM-port attached to my laptop.

So I thought it would be easy to use Python, acctually I'm not well-known with Python though I've used PHP. So I installed pyserial and just tried to open the serial port like this (as said in the short introduction at http://pyserial.sourceforge.net/):

CODE

>>> import serial
>>> ser = serial.Serial(0)
>>> print ser.portstr
>>> ser.write("hello")
>>> ser.close()


Though I get an error message:

CODE

[root@localhost xiph]# python test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
  ser = serial.Serial(0);
File "/usr/lib/python2.5/site-packages/serial/serialutil.py", line 156, in __init__
  self.open()
File "/usr/lib/python2.5/site-packages/serial/serialposix.py", line 144, in open
  self._reconfigurePort()
File "/usr/lib/python2.5/site-packages/serial/serialposix.py", line 158, in _reconfigurePort
  raise SerialException("Could not configure port: %s" % msg)
serial.serialutil.SerialException: Could not configure port: (5, 'Input/output error')


Anyone who can help me out here?



EDIT: It seems that I haven't located the serial port properly. I'll be back with more info.
EDIT2: Got it working, just had to specify the serial port like this instead:
CODE

ser = serial.Serial('/dev/pts/2', 19200, timeout=1)

instead of this:
CODE

ser = serial.Serial(0)


This post has been edited by Xiph: 20 Apr, 2008 - 05:57 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 10:11AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month