Skip to content

Commit 72bcdc1

Browse files
committed
Append buffered bytes only if read() was successful
Should solve #155
1 parent e3a2cf6 commit 72bcdc1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

serialport.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ func (p *serport) reader() {
103103

104104
n, err := p.portIo.Read(ch)
105105

106+
if err != nil {
107+
ch = append(buffered_ch.Bytes(), ch[:n]...)
108+
n += len(buffered_ch.Bytes())
109+
buffered_ch.Reset()
110+
}
111+
106112
//if we detect that port is closing, break out o this for{} loop.
107113
if p.isClosing {
108114
strmsg := "Shutting down reader on " + p.portConf.Name
@@ -111,10 +117,6 @@ func (p *serport) reader() {
111117
break
112118
}
113119

114-
ch = append(buffered_ch.Bytes(), ch[:n]...)
115-
n += len(buffered_ch.Bytes())
116-
buffered_ch.Reset()
117-
118120
// read can return legitimate bytes as well as an error
119121
// so process the bytes if n > 0
120122
if n > 0 {

0 commit comments

Comments
 (0)