<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On May 7, 2010, at 2:08 PM, MRAB wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>William R. Wing (Bill Wing) wrote:<br><blockquote type="cite">Hello World -<br></blockquote><blockquote type="cite">I'm new to both Python and this list, but here's hoping someone can spot my problem.<br></blockquote><blockquote type="cite">System: Mac OS-X, 10.6.3 (Intel dual quad processor)<br></blockquote><blockquote type="cite">Using Python 2.6.1, and pyserial-2.5_rc2-py2.6<br></blockquote><blockquote type="cite">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.<br></blockquote>What do you mean "It fails silently"? It might be unable to find the<br>modules if you double-click on the script. You could check for that by<br>printing a message if the import statement raises an ImportError.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><div><br></div>Maybe I should have been more explicit. The first line in the Python file is:</div><div><br></div><div>#!/usr/bin/env Python (alternatively #!/usr/bin/Python - same results either way).</div><div><br></div><div>and what I meant was that when I invoke it from a UNIX CLI window, it fails.</div><div>If the import were failing, wouldn't I get failures on the serial operations?</div><div>In particular, the ser object is exactly what it should be. If I print it out, I get</div><div>the same value for ser from either the UNIX CLI or in the debugger, and in </div><div>both cases it says "open=True"</div><div><br></div><div>The various status print statements give exactly the same (expected) results in</div><div>both cases. But when invoked from the terminal window, the X10 controller doesn't</div><div>get commands. If I invoke python from the same window, and enter the script</div><div>code interactively one line at a time - it works just fine.</div><div><div><br></div><br><blockquote type="cite"><div><blockquote type="cite">TIA,<br></blockquote><blockquote type="cite">Bill Wing<br></blockquote><blockquote type="cite">import serial, string<br></blockquote><blockquote type="cite">port = '/dev/tty.KeySerial1'<br></blockquote><blockquote type="cite">ser = serial.Serial(port, 9600, timeout=1) # Set up handle to serial port<br></blockquote><blockquote type="cite">stat1 = ser.write('\x02') # Write "Attention" to PowerLink<br></blockquote><blockquote type="cite">print(' Stat1 is:', stat1) ack = ser.read(2) # Check to see if PowerLink is ready<br></blockquote><blockquote type="cite">if ack == '\x06\r': # It returns ACK (\x06) \r if it is<br></blockquote><blockquote type="cite"> stat2 = ser.write('\x63\x4E\x5C\x45\x41')# send "On" to module at House Code B, device code 2<br></blockquote><blockquote type="cite"> print(' Stat2 is:', stat2)<br></blockquote><blockquote type="cite"> stat3 = ser.close() # Close serial port<br></blockquote><blockquote type="cite"> print(' Stat3 is:', stat3)<br></blockquote><blockquote type="cite">elif ack =='\x15': # PowerLink sends NAC (hex 15) if it isn't.<br></blockquote><blockquote type="cite"> print('Received NAK after first open')<br></blockquote><blockquote type="cite">else: print("Something's wrong at 1.\n")<br></blockquote><blockquote type="cite">dummy = raw_input(' Hit any key to continue: ')<br></blockquote><br>-- <br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br></div></blockquote></div><br></body></html>