0

I'm using python to send data out to my arduino and for some reason under windows it's giving me an error. Below is my code.

import serial 

ser = serial.Serial("COM3")

ser.write('1')

Here is the error.

  File "C:\Python25\lib\site-packages\serial\serialwin32.py",

line 255, in write raise SerialException("WriteFile failed (%s)" % ctypes.WinError()) serial.serialutil.SerialException: WriteFile failed ([Error 9] The handle is invalid.)

Any idea why it's giving me this?

1
  • Use the 101010 button for proper code formatting. Commented Nov 22, 2010 at 4:23

1 Answer 1

1

Are you sure COM3 is a valid serial port on your Windows box? Can you open it with HyperTerminal and send stuff to it?

If it is, another thing to try is to replace it with the fully qualified name, for example:

port = "\\\\.\\COM3"
ser = serial.Serial(port, 38400)
Sign up to request clarification or add additional context in comments.

1 Comment

Yet another thing to do is replace "COM3" with the literal int 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.