Urgent:Serial Port Read/Write

Chris Angelico rosuav at gmail.com
Thu May 9 11:49:05 EDT 2013


On Fri, May 10, 2013 at 1:35 AM, chandan kumar <chandan_psr at yahoo.co.in> wrote:
>
> Hi all,
> I'm new to python and facing issue using serial in python.I'm facing the below error
>
>     ser.write(port,command)
> NameError: global name 'ser' is not defined
>
> Please find the attached script and let me know whats wrong in my script and also how can i read data from serial port for the  same script.

You're assigning to 'ser' inside OpenPort(), but then trying to use it
in WriteSerialData(). You'll need to declare 'global ser' in OpenPort
to make this work.

Alternatively, you may want to cut down on the number of functions you
have, since they're called in only one place anyway and have to share
state.

ChrisA



More information about the Python-list mailing list