News:

;) This forum is the property of Proton software developers

Main Menu

Serin and serout

Started by Ivano, Mar 01, 2026, 08:02 PM

Previous topic - Next topic

Ivano

Good evening, I have a question about the Serin or serout command.
In the example, SerIn PORTA.1,84,1000,continue,[A].
Does continue mean that after the timeout, it skips to the next instruction after serin, or does it resume the serin command?
It seems to me that after the timeout, it resumes from serin. Is this correct?
Thanks, Ivano

RGV250

Hi,
I haven't got access to PC at moment but I would say it jumps to a label "continue" or whatever you call the timeout.

Bob

JackB

#2
Hi Ivano,

about ( SerIn PORTA.1,84,1000,continue,[A]. )


the way I use it is within a Do-Loop or Goto Main

usualy the "Timout" Label indicate where will be the next instruction to follow, then you can decide to Loop again
or use a Goto statement.

In the sample code below the "main'" timeout label redirect to the "main:" label after a timout.

'Serin
main:
    SerIn PORTB.5,BaudR,3,main,[B1] 
If B1 < 253 Then   ' Characters
        PORTC = B1 : High En : DelayUS 1 : Low En
GoTo main



see Positron8 Basic Compiler Manual page: 241 for more details.

Here's a sumary :

Timeout is an optional constant (0 - 65535) that informs Serin how long to wait for incoming
data. If data does not arrive in time, the program will jump to the address specified by Tlabel.
Tlabel is an optional label that must be provided along with Timeout, indicating where the program jump to in the event that data does not arrive within the period specified by Timeout. It
can also be the compiler directives; Break or Continue, if the command is used inside a loop.
Break will exit a loop if a timeout occurs, and Continue will re-iterate the loop.
















Ivano

The serin command is inserted in a do loop. I've tested various break and label commands after the timeout, and everything works correctly. With the "Continue" label, I expected the program to continue with the instruction following serin after the timeout, that is, to continue the instructions within the do loop. Instead, after the timeout, the serin instruction resumes. I was trying to understand the correct "continue" function after the timeout. Let me explain better: if after the timeout, "continue" causes the program to continue with the subsequent instructions, as I thought, or if it resumes reading the serial line, as I found. In JackB's example, if I replace main with continue in the Serin command, the program does the same thing, but without switching to the main label in the event of a timeout.
In this last case, I don't see the point of using "continue," since if I don't set timeout with its label, it does the same thing; it just stays there waiting for a serial command. I was just trying to understand the meaning of this label.
Thanks, Ivano

Stephen Moss

Quote from: Ivano on Mar 01, 2026, 08:02 PMGood evening, I have a question about the Serin or serout command.
In the example, SerIn PORTA.1,84,1000,continue,[A].
Does continue mean that after the timeout, it skips to the next instruction after serin, or does it resume the serin command?
It seems to me that after the timeout, it resumes from serin. Is this correct?
Thanks, Ivano
The manual states that...
QuoteTlabel is an optional label that must be provided along with Timeout, indicating where the program jumps to in the event that data does not arrive within the period specified by Timeout. It can also be the compiler directives; Break or Continue, if the command is used inside a loop.
Break will exit a loop if a timeout occurs, and Continue will re-iterate the loop.
So from that is it not clear if Continue should be used at all when the command is not is used within a loop, or whether when used outside a loop the compiler ignores it.

It don't think I have used that before so I may be wrong, but from the manual description I would expect that Continue would result in the following...
  • Where the SerIn command is not executed within a loop, the instruction immediately after the SerIn instruction in your code listing will be executed upon the time out being reached, i.e., stop waiting for data and continue executing the rest of the code.
  • Whereas if the SerIn command is used within a loop, when the timeout is reached, the next instruction to be executed would the the one at the start of the loop, i.e., keep executing the loop until data is received.

Whereas if you had used Break instead of Continue, the result would be the same as item 1 whether used in a loop or not, and if a label was used code execution after the timeout would resume at the instruction immediately after the label.

RGV250

Hi Ivano,
Perhaps posting your code so we can see might help.

Regards,
Bob

top204

#6
The Continue directive jumps over code in front of it, and carries on with the loop. So it does not perform any code in front of it.

For example, in a simple code listing such as:
    bIndex = 0
    Repeat
        SerIn PORTC.7, cBaudVal, 2000, Continue, [Bytein]
        Print Bytein
        Inc bIndex
    Until bIndex = 9

Where the Serin command is within a Repeat-Until loop, the generated assembler code is:

F1_000057 equ $ ; in [Test.bas] bIndex = 0
    clrf bIndex,0
F1_000057 equ $ ; in [Test.bas] Repeat
_lbl__3
F1_000060 equ $ ; in [Test.bas] Serin PORTC.7, cBaudVal, 2000, Continue,[Bytein]
    movlw PORTC         <------------------\
    movwf GEN,0         <------------------|
    movlw 128           <------------------| Port. Pin Address and Mask in GEN and GENH
    movwf GENH,0        <------------------/
    movlw 4             <------------------\
    movwf PP5H,0        <------------------|
    movlw 210           <------------------| Baud Rate value in PP5 and PP5H
    movwf PP5,0         <------------------/
    movlw 7             <------------------\
    movwf GEN3H,0       <------------------|
    movlw 208           <------------------| Timeout value in GEN3 and GEN3H
    movwf GEN3,0        <------------------/
    rcall _serin__timeout_
    bnc _lbl__5                <------------------ Timeout jump here, jumps to the end of the loop
    movwf Bytein,0
F1_000061 equ $ ; in [Test.bas] Print Bytein
    movf Bytein,W,0
    rcall __print_
F1_000062 equ $ ; in [Test.bas] Inc bIndex
    incf bIndex,F,0
_lbl__5
F1_000063 equ $ ; in [Test.bas] Until bIndex = 9
    movlw 9
    cpfseq bIndex,0
    bra _lbl__3


See where the jump is made if the serial data times out: bnc _lbl__5. So it skips the Print, and increment, and anything else that would have been there, and tests the end of the loop.

You can also see the bulky setup of the Serin command because of the multiple parameters it requires, and why it is now very much out-dated and is, really, for backward compatability. The only reason I added it was for backward compatability with the original BASIC Stamp syntax, all of those years ago. I always prefered my RSout/RSin commands for software serial, because they take very little setting up in the assembler code, when used, and as soon as devices contained UARTs, they are the peripheral that should be used for async serial coms, because they are so much more efficient, in speed, code size, and operation.

Regards
Les