Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 908839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:46:53+00:00 2026-05-15T16:46:53+00:00

I’m trying to connect to my phone from my Windows 7 PC using PySerial

  • 0

I’m trying to connect to my phone from my Windows 7 PC using PySerial with the following code:

import wmi
import serial

c = wmi.WMI()
modem = c.query("SELECT * FROM Win32_POTSModem").pop()
ser = serial.Serial(modem.AttachedTo, modem.MaxBaudRateToSerialPort)

try:
    ser.write('at \r\n')
    print ser.readline()
finally:
    ser.close()

But get the following error on the write call:

Traceback (most recent call last):
  File "D:\Alasdair\Documents\Python Scripts\Phone Interface\test.py", line 14, in <module>
    ser.write('at \r\n')
  File "C:\Python26\Lib\site-packages\serial\serialwin32.py", line 255, in write
    raise SerialException("WriteFile failed (%s)" % ctypes.WinError())
SerialException: WriteFile failed ([Error 6] The handle is invalid.)

I’ve tried connecting with TeraTerm and that works fine, so it’s not a problem with the connection to the phone itself.

I’ve been searching around for ages trying to find a solution but haven’t come up with anything that works. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:46:54+00:00Added an answer on May 15, 2026 at 4:46 pm

    I’m on windows 7 64 bit, with python 2.6, and it’s giving me the same error.

    ser = serial.Serial(3,115200,timeout=1)
    ser.read()
    #or ser.write("whatever")
    
    Traceback (most recent call last):
      File "<pyshell#3>", line 1, in <module>
        ser.read(1)
      File "build\bdist.win-amd64\egg\serial\serialwin32.py", line 236, in read
        raise SerialException("ReadFile failed (%s)" % ctypes.WinError())
    SerialException: ReadFile failed ([Error 6] The handle is invalid.)
    

    When using a similar program using a c library, the same port responds correctly. What happens here? Sounds like a bug in either pyserial or ctypes. Are you using 64 bit too?

    the source code for writing in pyserial looks very simple

    def write(self, data):
            """Output the given string over the serial port."""
            if not self.hComPort: raise portNotOpenError
            #~ if not isinstance(data, (bytes, bytearray)):
                #~ raise TypeError('expected %s or bytearray, got %s' % (bytes, type(data)))
            # convert data (needed in case of memoryview instance: Py 3.1 io lib), ctypes doesn't like memoryview
            data = bytes(data)
            if data:
                #~ win32event.ResetEvent(self._overlappedWrite.hEvent)
                n = win32.DWORD()
                err = win32.WriteFile(self.hComPort, data, len(data), ctypes.byref(n), self._overlappedWrite)
                if not err and win32.GetLastError() != win32.ERROR_IO_PENDING:
                    raise SerialException("WriteFile failed (%s)" % ctypes.WinError())
    

    perhaps a problem with 64 bit ctypes?


    Update:
    Definitly a 64 bit problem atleast for me. I just installed an x86 version of python (3.1 this time), and it now works fine. Apperantly 64 bit ctypes can only import 64 bits libraries. Sounds very strange not being able to reach operating system libraries though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.