<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 7, 2010, at 10:18 PM, MRAB wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>William R. Wing (Bill Wing) wrote:<br><blockquote type="cite">See comments in-line.<br></blockquote><blockquote type="cite">On May 7, 2010, at 3:23 PM, MRAB wrote:<br></blockquote><blockquote type="cite"><blockquote type="cite">William R. Wing (Bill Wing) wrote:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">On May 7, 2010, at 2:08 PM, MRAB wrote:<br></blockquote></blockquote></blockquote></div></blockquote><div><br></div><div>[byte -byte- byte]</div><br><blockquote type="cite"><div><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite">The X10 controller not only receives it, it echos the response (\x06\r) that means<br></blockquote><blockquote type="cite">it saw it and is ready for the next command in all three cases.  The serial write<br></blockquote><blockquote type="cite">that immediately follows, in which five hex bytes get sent to it is the one which<br></blockquote><blockquote type="cite">succeeds interactively and in the IDE, and fails when executed as a bash script.<br></blockquote>Does the ' Hit any key to continue: ' message appear when run as a bash<br>script?<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><div><br></div>Yes, in all three cases, and just for completeness, the neither of the error returns</div><div>from the first open statement ever are taken - that is, I never get either the \x15, which</div><div>would print "Received NAK" nor the "Something's wrong" print that would indicate</div><div>any other random return.</div><div><br><blockquote type="cite"><div>I'm just wondering whether it's that when run from the Python prompt or<br>IDE the 'ser' object continues to exist for a while, but when run as a<br>bash script Python is terminating before all of the bytes have been<br>sent.<br><br>Of course, I'd expect 'ser.close()' to return only when there's nothing<br>left to be sent, or, at least, for there to be enough time while it's<br>waiting for you to press ENTER.<br><br><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">import serial, string<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">port = '/dev/tty.KeySerial1'<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">ser = serial.Serial(port, 9600, timeout=1)   # Set up handle to serial port<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">stat1 = ser.write('\x02')                    # Write "Attention" to PowerLink<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">print(' Stat1 is:', stat1)                   ack = ser.read(2)                            # Check to see if PowerLink is ready<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">if ack == '\x06\r':                          # It returns ACK (\x06) \r if it is<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><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></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">  print(' Stat2 is:', stat2)<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">  stat3 = ser.close()                      # Close serial port<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">  print(' Stat3 is:', stat3)<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">elif ack =='\x15':                           # PowerLink sends NAC (hex 15) if it isn't.<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">  print('Received NAK after first open')<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">else:   print("Something's wrong at 1.\n")<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">dummy = raw_input(' Hit any key to continue: ')<br></blockquote></blockquote></blockquote></blockquote></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>