Frustration debugging serial code
William R. Wing (Bill Wing)
wrw at mac.com
Fri May 7 22:42:00 EDT 2010
On May 7, 2010, at 10:18 PM, MRAB wrote:
> William R. Wing (Bill Wing) wrote:
>> See comments in-line.
>> On May 7, 2010, at 3:23 PM, MRAB wrote:
>>> William R. Wing (Bill Wing) wrote:
>>>> On May 7, 2010, at 2:08 PM, MRAB wrote:
[byte -byte- byte]
>>>>>
>> The X10 controller not only receives it, it echos the response (\x06\r) that means
>> it saw it and is ready for the next command in all three cases. The serial write
>> that immediately follows, in which five hex bytes get sent to it is the one which
>> succeeds interactively and in the IDE, and fails when executed as a bash script.
> Does the ' Hit any key to continue: ' message appear when run as a bash
> script?
Yes, in all three cases, and just for completeness, the neither of the error returns
from the first open statement ever are taken - that is, I never get either the \x15, which
would print "Received NAK" nor the "Something's wrong" print that would indicate
any other random return.
> I'm just wondering whether it's that when run from the Python prompt or
> IDE the 'ser' object continues to exist for a while, but when run as a
> bash script Python is terminating before all of the bytes have been
> sent.
>
> Of course, I'd expect 'ser.close()' to return only when there's nothing
> left to be sent, or, at least, for there to be enough time while it's
> waiting for you to press ENTER.
>
>>>>>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100507/cef0cae2/attachment-0001.html>
More information about the Python-list
mailing list