Serial Question...
Archiver
Posts: 46,084
I have an extremely simple program as follows...
LEDs Var OutA
TxD Con 15
RxD Con 14
Baud96 CON 84
cmd Var Byte
param VAR Word
CLEDs CON $FF
SLEDs CON $FE
Initialize:
DirA = %1111
Main:
cmd = 0
SERIN RxD, Baud96, [noparse][[/noparse]WAIT ("?"), HEX cmd]
LOOKDOWN cmd, [noparse][[/noparse]CLEDs, SLEDs], cmd
BRANCH cmd, [noparse][[/noparse]LEDStat, SetLEDs]
SEROUT TxD, Baud96, [noparse][[/noparse]"The command was: ", HEX2 cmd, CR]
GOTO Main
End
LEDStat:
SEROUT TxD, Baud96, [noparse][[/noparse]"LED Status: ", BIN4 LEDs, CR]
GOTO Main
SetLEDs:
SERIN RxD, Baud96, [noparse][[/noparse]BIN param]
LEDs = param.LowNib
GOTO LEDStat
Now, when I run that program in the debug terminal in The Basic Stamp editor
from Parallax, all is well. Works like a charm. Now, when I try to run it
from python with a simple program as follows
ser = serial.Serial(1, timeout=1)
ser.write("?FF\r")
line = ser.readline()
print line
ser.close()
Then it only works every other time. I'm sure there is some silly bit
somewhere that I've improperly set, but I can't figure it out. I've tried
substituting ?FF\r\r, ?FF, \r?FF\r, etc, but it still won't work every time.
What do I need to reset to make it happen for me?
Thanks,
Kelley
LEDs Var OutA
TxD Con 15
RxD Con 14
Baud96 CON 84
cmd Var Byte
param VAR Word
CLEDs CON $FF
SLEDs CON $FE
Initialize:
DirA = %1111
Main:
cmd = 0
SERIN RxD, Baud96, [noparse][[/noparse]WAIT ("?"), HEX cmd]
LOOKDOWN cmd, [noparse][[/noparse]CLEDs, SLEDs], cmd
BRANCH cmd, [noparse][[/noparse]LEDStat, SetLEDs]
SEROUT TxD, Baud96, [noparse][[/noparse]"The command was: ", HEX2 cmd, CR]
GOTO Main
End
LEDStat:
SEROUT TxD, Baud96, [noparse][[/noparse]"LED Status: ", BIN4 LEDs, CR]
GOTO Main
SetLEDs:
SERIN RxD, Baud96, [noparse][[/noparse]BIN param]
LEDs = param.LowNib
GOTO LEDStat
Now, when I run that program in the debug terminal in The Basic Stamp editor
from Parallax, all is well. Works like a charm. Now, when I try to run it
from python with a simple program as follows
ser = serial.Serial(1, timeout=1)
ser.write("?FF\r")
line = ser.readline()
print line
ser.close()
Then it only works every other time. I'm sure there is some silly bit
somewhere that I've improperly set, but I can't figure it out. I've tried
substituting ?FF\r\r, ?FF, \r?FF\r, etc, but it still won't work every time.
What do I need to reset to make it happen for me?
Thanks,
Kelley