Macro Problem With Serin Timeout

techElder

Well-known member
I can't find a way to get around the compiler message "Duplicate label name - timeoutLabel" with SERIN using a timeout label in a #Macro definition.

Code:
#Macro mySerMacro

serin [timeoutTime, timeoutLabel],pin,baud,variable
' do something
goto nothingHappened

timeoutLabel:
' do something different
goto exitThisRoutine

nothingHappened:

exitThisRoutine:

#endm
 

BESQUEUT

Senior Member
I can't find a way to get around the compiler message "Duplicate label name - timeoutLabel" with SERIN using a timeout label in a #Macro definition.

Code:
#Macro mySerMacro

serin [timeoutTime, timeoutLabel],pin,baud,variable
' do something
goto nothingHappened

timeoutLabel:
' do something different
goto exitThisRoutine

nothingHappened:

exitThisRoutine:

#endm
Maybe something like :
Code:
[color=Navy]#Macro [/color][color=Black]mySerMacro
      [/color][color=Blue]gosub [/color][color=Black]DoSerial[/color]
[color=Navy]#endmacro[/color]


[color=Black]DoSerial:
      [/color][color=Blue]serin [PLAIN][[/PLAIN][/color][color=Black]timeoutTime, timeoutLabel[/color][color=Blue][PLAIN]][/PLAIN][/color][color=Black],pin,baud,variable
      [/color][color=Green]' do something[/color]
[color=Blue]return[/color]

[color=Black]timeoutLabel:
      [/color][color=Green]' do something different[/color]
[color=Blue]return[/color]
But why do you want to use a macro ?
 

techElder

Well-known member
I know how to do it, but wanted to explore the limits of #Macro.

I believe this is a compiler situation where it could be handled differently.
 

BESQUEUT

Senior Member
I know how to do it, but wanted to explore the limits of #Macro.

I believe this is a compiler situation where it could be handled differently.
#macro is not a command ; this is not related to compiler.
#macro is another way to write inline code. So of course, you cannot use a LABEL (more that once) within a macro.
 

Goeytex

Senior Member
Of course.

Since a macro is inserted inline that would create 2 labels named "TimeOutLabel". Thus the duplicate label error.

The TimeOutLabel must be outside of the Macro. That would apply to all labels. None inside of a macro.
 

hippy

Technical Support
Staff member
You can pass label names into a #MACRO ...

Code:
#Macro SerInTimeout( timeoutLabel, exitLabel )
  serin [1000, timeoutLabel], C.0, N2400, b0
    SerTxd ( "Got it" )
    goto exitlabel
  timeoutLabel:
    SerTxd( "Timed out" )
  exitLabel:
#EndMacro

SerInTimeout( L1, L2 )
SerInTimeout( L3, L4 )
You can also pass in labels defined outside the #MACRO ...

Code:
#Macro SerInTimeout( timeoutLabel, exitLabel )
  serin [1000, timeoutLabel], C.0, N2400, b0
    SerTxd ( "Got it" )
    goto exitlabel
  timeoutLabel:
    SerTxd( "Timed out" )
#EndMacro

MainLoop:
  Do
    SerInTimeout( L1, MainLoop )
    SerInTimeout( L2, MainLoop )
  Loop
 

techElder

Well-known member
I used the word "compiler" because that is when the situation arises. Syntax checks didn't find this situation.

Testing didn't show this situation until I used the macro more than once in a program. I see that now. The second time I used the macro, the duplicate label was created.

Passing the label as a parameter is tedious at best. Guess I'll keep it as a subroutine. At least I can call it with a macro. ( BESQUEUT, because that's the way I'm doing this project.)

Thanks for showing me the problem (me!), guys, and Hippy showed me a new trick! :D
 
Top