When reading from a serial port, there is no EOF between data sets.  I may 
have to use something else besides a scanner to do this.  I have a handler 
function called by a goroutine that just monitors incoming data in a for 
loop and sends that data coming in back through a channel.  If the 
connection closes, I need a way to signal this loop to close so that the 
function can return and end.

On Sunday, December 30, 2018 at 6:48:21 PM UTC-6, Wagner Riffel wrote:
>
> Scan() returns false when it reaches EOF or an error, so with what you 
> provided i assume you're missing to check that. 
> for ns.Scan() { 
> ... 
> } 
>
> or 
>
> for { 
> if !ns.Scan() { 
>     break 
> } 
>
> -wgr 
>
> On Sun, Dec 30, 2018 at 10:36 PM Trig <edb...@gmail.com <javascript:>> 
> wrote: 
> > 
> > I'm currently utilizing the bufio.NewScanner to read ASCII data from a 
> serial port.  I have the following simple code: 
> > 
> > ns := bufio.NewScanner(sPort) 
> > 
> > for { 
> >    ns.Scan() 
> >    if ns.Text() != "" { // ignore blank lines 
> >       // handle content here 
> >    } 
> > } 
> > 
> > The problem is ns.Scan() blocks the loop from continuing if there isn't 
> any data.  This leaves me unable to break out of the loop with a for 
> condition or a select statement also within the loop which is looking for a 
> close command from a channel before or after it, etc.  Am I doing something 
> wrong, or is there a proper way to handle this? 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "golang-nuts" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to golang-nuts...@googlegroups.com <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to