Hello World -
I'm new to both Python and this list, but here's hoping someone can spot my 
problem.

System:  Mac OS-X, 10.6.3 (Intel dual quad processor)
Using Python 2.6.1, and pyserial-2.5_rc2-py2.6

The following snippet of code is designed to open a port via a KeySpan 
USB-to-serial converter and communicate with an X10 power line signaling 
system.  Before you look at the code, let me mention that my frustration is the 
it executes perfectly if i enter it line by line at the Python prompt, and 
executes perfectly if I run it under the Wing IDE.  It fails silently (no 
errors) if I run it as a standalone script.  Clearly, I'm missing something.

TIA,
Bill Wing

import serial, string

port = '/dev/tty.KeySerial1'

ser = serial.Serial(port, 9600, timeout=1)   # Set up handle to serial port
stat1 = ser.write('\x02')                    # Write "Attention" to PowerLink
print(' Stat1 is:', stat1)                   
ack = ser.read(2)                            # Check to see if PowerLink is 
ready
if ack == '\x06\r':                          # It returns ACK (\x06) \r if it is
    stat2 = ser.write('\x63\x4E\x5C\x45\x41')# send "On" to module at House 
Code B, device code 2
    print(' Stat2 is:', stat2)
    stat3 = ser.close()                      # Close serial port
    print(' Stat3 is:', stat3)
elif ack =='\x15':                           # PowerLink sends NAC (hex 15) if 
it isn't.
    print('Received NAK after first open')
else:   print("Something's wrong at 1.\n")

dummy = raw_input(' Hit any key to continue: ')



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to