import serial failure

J W Burton jahree1129 at gmail.com
Wed Apr 16 13:56:50 EDT 2014


I have installed both Python 2.7 AND Python 3.3 and the corresponding pyserial files from

ihttps://pypi.python.org/packages/any/p/pyserial/pyserial-2.7.win32.exe#md5=21555387937eeb79126cde25abee4b35n my 

for 2.7

When I look in my Python27/Lib/site-packages/serial folder I see
package files

but when I run a program using import serial, I get an error
 Traceback (most recent call last):
  File "C:\Users\Jahree\serial.py", line 2, in <module>
    import serial
  File "C:\Users\Jahree\serial.py", line 5, in <module>
    ser = serial.Serial(
AttributeError: 'module' object has no attribute 'Serial'

I'm guessing there is a path not set correctly - I'M STUCK

Please help.

Thanks

ps: the following is serial.py file I'm using for testing.

import time
import serial

# configure the serial connections (the parameters differs on the device you are connecting to)
ser = serial.Serial(
    port='/dev/ttyUSB1',
    baudrate=19200,
    parity=serial.PARITY_ODD,
    stopbits=serial.STOPBITS_TWO,
    bytesize=serial.SEVENBITS
)

ser.open()
ser.isOpen()

print('Enter your commands below.\r\nInsert "exit" to leave the application.')

input=1
while 1 :
    # get keyboard input
    input = raw_input(">> ")
    input = input(">> ")
    if input == 'exit':
        ser.close()
        exit()
    else:
        # send the character to the device
        # (note that I happend a \r\n carriage return and line feed to the characters - this is requested by my device)
        ser.write(input + '\r\n')
        out = ''
        # let's wait one second before reading output (let's give device time to answer)
        time.sleep(2)
    while ser.inWaiting() > 0:
            out += ser.read(4)

    if out != '':
            print(">>" ,out)



More information about the Python-list mailing list