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 = ser.read(10)
    i=0

    while linea == "":
        linea = ser.read(10)
        i = i+1
        print i
        time.sleep(1);

    print linea

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


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
C:\Python27>python puerto.py
Traceback (most recent call last):
  File "puerto.py", line 4, in <module>
    ser = serial.Serial("COM1", 9600, timeout=1);
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 38, in __init
__
    SerialBase.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\serial\serialutil.py", line 282, in __init
__
    self.open()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 66, in open
    raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.W
inError()))
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.
jesus_siordia
 
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.
Marbelous
 
Posts: 142
Joined: Fri May 31, 2013 8:12 pm


Return to General Discussions

Who is online

Users browsing this forum: Google [Bot], snippsat and 2 guests