Is there a better way to watch for commands from hserin?

wapo54001

Senior Member
I am using hardware serial in on a 20x2 to watch for IR commands from an 08M2. If no commands arrive then a null "255" is generated and sent out into the program. I trap the null with an IF...THEN test to prevent the 255 from going out into the program where I don't want it.

Question: Is there a way to rewrite the DO WHILE loop so that a null never leaves the loop in the first place, but anything other than a null does get out?


Code:
HSERSETUP B9600_32,5    

Main:
DO

    'inside loop to accept commands
    DO WHILE ptr<>hserptr
        CmdCode = @ptrinc
    LOOP 

    'reject null command
    IF CmdCode = 255 THEN
    GOTO Main
    ENDIF
 

hippy

Technical Support
Staff member
You should be able to do it just by using -
Code:
  DO 
    DO WHILE ptr = hserptr : LOOP
    CmdCode = @ptrinc
  LOOP UNTIL CmdCode <> 255
  GOTO Main
 

wapo54001

Senior Member
Whoopee, I will give that a try, thanks hippy! --- and, it works a charm, much happier with that code!

Just discovered a funny thing about it -- I now have to turn off and turn back on the 20X2 in order to program it. Otherwise, PE6 reports hardware not found . . . I suppose that means that this loop is super-efficient!
 
Last edited:

hippy

Technical Support
Staff member
That is odd because none of that should be blocking. Even though the "DO WHILE ptr = hserptr : LOOP" loop is very tight, the PICAXE should be checking the Serial In pin at least twice for downloads during each loop of that.

It's probably worth checking you don't have a DISCONNECT in the program.

Actually DO : LOOP WHILE ptr = hserptr would be more efficient.
 

wapo54001

Senior Member
hippy, could you put that "more efficent" code you've introduced into the full code, please?

I am in the very early stages of working up my image stacking project and the only code I have in the program is the manual control of the focus ring with accelerated movement so I get very precise movement at the beginning and gradually increasing speed while I hold the remote control button down. There is no "Disconnect" command in the code.
 
Last edited:

hippy

Technical Support
Staff member
Code:
DO
  DO : LOOP WHILE ptr = hserptr
  CmdCode = @ptrinc
LOOP UNTIL CmdCode <> 255
GOTO Main
 
Top