Post by msteffes on Jan 23, 2023 16:24:17 GMT -5
Hello Gang,
Below is a segment of code that I loop through to detect bits in a serial message package and then set or reset corresponding radio buttons.
It works well enough but I think there might be a faster cleaner way to do this. The full routine inspects three consecutive bytes extracted from a message packet.
The routine is constantly checking new messages coming in the serial port. The program dictates the speed since it is sending out polling messages at about 100ms interval
and then waits on the response. One issue I have seen is if the hardware address is changed on the fly( to look at a different device) the bit sequencing can get jumbled or out
of sequence and the app has to be restarted to recover. I want to be able to seamlessly jump from one address to another. I am sure I can modify my existing code to
accommodate this but would like to clean up the process of decoding the bits first if possible.
Below is a segment of code that I loop through to detect bits in a serial message package and then set or reset corresponding radio buttons.
It works well enough but I think there might be a faster cleaner way to do this. The full routine inspects three consecutive bytes extracted from a message packet.
The routine is constantly checking new messages coming in the serial port. The program dictates the speed since it is sending out polling messages at about 100ms interval
and then waits on the response. One issue I have seen is if the hardware address is changed on the fly( to look at a different device) the bit sequencing can get jumbled or out
of sequence and the app has to be restarted to recover. I want to be able to seamlessly jump from one address to another. I am sure I can modify my existing code to
accommodate this but would like to clean up the process of decoding the bits first if possible.
'###########################################
'##### 'setup Rad btn status for byt 5 #####
'###########################################
'''''not visible chars---print "BufrCurntInputMsg$ _> " + BufrCurntInputMsg$
byteInWork = asc(mid$(BufrCurntInputMsg$,5,1))'
'Dead Blt Ext
if byteInWork >= 128 then
byteInWork = byteInWork - 128
print #main.radiobutton8,"set"
else
if byteInWork < 128 then
#main.radiobutton8,"reset"
end if
end if
'*********************************************************
'Clutch
if byteInWork >= 64 then 'Clutch
#main.radiobutton7,"set"
byteInWork = byteInWork - 64
else
if byteInWork < 64 then
#main.radiobutton7,"reset"
end if
end if
'*********************************************************
'Motor Stld
if byteInWork >= 32 then 'Motor Stld
#main.radiobutton6,"set"
byteInWork = byteInWork - 32
else
if byteInWork < 32 then
#main.radiobutton6,"reset"
end if
end if
'*********************************************************
'Cache
if byteInWork >= 16 then
#main.radiobutton5,"set"
byteInWork = InWork - 16
else
if byteInWork < 16 then
#main.radiobutton5,"reset"
end if
end if 'xzxzx
'**********************************
'RSD Tmp
if byteInWork >= 8 then
#main.radiobutton4,"set"
byteInWork = byteInWork - 8
else
if byteInWork < 8 then
#main.radiobutton4,"reset"
end if
end if
'*********************************************************
'RF Loss
if byteInWork >= 4 then
"
#main.radiobutton3,"set"
byteInWork = byteInWork - 4
else
if byteInWork < 4 then
#main.radiobutton3,"reset"
end if
end if
'*********************************************************
'Low Batt
if byteInWork >= 2 then
#main.radiobutton2,"set"
byteInWork = byteInWork - 2
else
if byteInWork < 2 then
#main.radiobutton2,"reset"
end if
end if
'*********************************************************
'RDR Tmp
if byteInWork >= 1 then 'RDR Tmp
#main.radiobutton1,"set"
byteInWork = byteInWork - 1
else
if byteInWork < 1 then"
#main.radiobutton1,"reset"
end if
end if