Spin case statement question
kwinn
Posts: 8,697
I have the code below which receives a single character and places the character (or a -1 if the receive times out) in the variable "k" . I want to process a lower case and upper case character the same way so initially I had a case for k that was "piduc or pidlc". This did compile and gave no errors but the "piduc or pidlc" seemed to always be executed. Once I split them up into separate cases as shown below it worked as I expected. Am I doing something wrong or is this a bug of some kind?
k := uarts.rxtime(0, 50) ' receive byte from "echo" routine above uarts.tx(1, k) ' send status heading to console uarts.tx(1, " ") ' send space to console case k ' what did we receive and put into "k"? ' ********************************************************************************************************* ' code for case where a character was not received in the allotted time ( -1 returned ) -1 : ' set status to "Timed Out" uarts.tx(1, "T") ' send "Timed out" status to console uarts.tx(0, bad) ' send error status to master ' ********************************************************************************************************* ' code for case where the character is one less than the upper case station_id (my turn to send status) piduc : sw := ina[noparse][[/noparse]sw_no..sw_nc] ' read the E-switch uarts.tx(1, "S") ' send an "S" to console to indicate this case was entered if sw <> %10 ' if the E-switch is not in normal position uarts.tx(0, bad) ' send error status (lower case station id) to master else ' if the E-switch is in the normal position uarts.tx(0, station_id) ' send status to master ' ********************************************************************************************************* ' code for case where the character is one less than the lower case station_id (my turn to send status) pidlc : sw := ina[noparse][[/noparse]sw_no..sw_nc] ' read the E-switch uarts.tx(1, "S") ' send an "S" to console to indicate this case was entered if sw <> %10 ' if the E-switch is not in normal position uarts.tx(0, bad) ' send error status (lower case station id) to master else ' if the E-switch is in the normal position uarts.tx(0, station_id) ' send status to master ' ********************************************************************************************************* ' code for any other characters other : uarts.tx(1, "U") ' send an "S" to console to indicate this case was entered uarts.tx(1, k) ' send received character to console uarts.tx(0, bad) ' send error status (lower case station id) to master ' ********************************************************************************************************* ' end of station code ' *********************************************************************************************************
Comments