Run on CMD

A forum for general discussion of the Python programming language.

Run on CMD

Postby jesus_siordia » Fri Jun 27, 2014 9:53 pm

Hi you all, I'm new on Python, I began yesterday :D and I have this code:

Code: Select all
import serial
import time

ser = serial.Serial("COM1", 9600, timeout=1);

while 1:
    linea =

    while linea == "":
        linea =
        i = i+1
        print i

    print linea

    f = open("C:/xampp/htdocs/prueba/peso.txt", "w")

And it works really sweet when I run it on PyScriter but when I want to run it on CMD it show this:
Code: Select all
Traceback (most recent call last):
  File "", line 4, in <module>
    ser = serial.Serial("COM1", 9600, timeout=1);
  File "C:\Python27\lib\site-packages\serial\", line 38, in __init
    SerialBase.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\serial\", line 282, in __init
  File "C:\Python27\lib\site-packages\serial\", line 66, in open
    raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.W
serial.serialutil.SerialException: could not open port 'COM1': WindowsError(5, '
Acceso denegado.')

I really hope some of your can helpe, thanks a lot.
Last edited by Yoriz on Fri Jun 27, 2014 10:25 pm, edited 1 time in total.
Reason: First post lock.
Posts: 1
Joined: Fri Jun 27, 2014 9:47 pm

Re: Run on CMD

Postby Marbelous » Mon Jun 30, 2014 2:40 pm

Nice post! It's unusual to see a new poster using code tags and providing a good description and complete traceback.

I was just about to start using python with serial ports so I don't have much experience but I THINK you may be locking the COM1 when you run it in pyscripter so the resource is unavailable when you try in the command line. Try adding ser.close() at the end of your script to release the COM port.
User avatar
Posts: 401
Joined: Fri May 31, 2013 8:12 pm

Return to General Discussions

Who is online

Users browsing this forum: Bing [Bot] and 6 guests