Skip to content

Commit 6a50f87

Browse files
committed
remove utf8 decoding with timedraw buffer type
1 parent 05ee6f5 commit 6a50f87

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

serialport.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type SpPortMessageRaw struct {
9292
D []byte // the data, i.e. G0 X0 Y0
9393
}
9494

95-
func (p *serport) reader() {
95+
func (p *serport) reader(buftype string) {
9696

9797
//var buf bytes.Buffer
9898
ch := make([]byte, 1024)
@@ -120,21 +120,24 @@ func (p *serport) reader() {
120120
// read can return legitimate bytes as well as an error
121121
// so process the bytes if n > 0
122122
if n > 0 {
123-
//log.Print("Read " + strconv.Itoa(n) + " bytes ch: " + string(ch))
123+
log.Print("Read " + strconv.Itoa(n) + " bytes ch: " + string(ch))
124124

125125
data := ""
126-
127-
for i, w := 0, 0; i < n; i += w {
128-
runeValue, width := utf8.DecodeRune(ch[i:n])
129-
if runeValue == utf8.RuneError {
130-
buffered_ch.Write(append(ch[i:n]))
131-
break
132-
}
133-
if i == n {
134-
buffered_ch.Reset()
126+
if buftype == "timedraw" {
127+
data = string(ch[:n])
128+
} else {
129+
for i, w := 0, 0; i < n; i += w {
130+
runeValue, width := utf8.DecodeRune(ch[i:n])
131+
if runeValue == utf8.RuneError {
132+
buffered_ch.Write(append(ch[i:n]))
133+
break
134+
}
135+
if i == n {
136+
buffered_ch.Reset()
137+
}
138+
data += string(runeValue)
139+
w = width
135140
}
136-
data += string(runeValue)
137-
w = width
138141
}
139142

140143
//log.Print("The data i will convert to json is:")
@@ -344,7 +347,7 @@ func spHandlerOpen(portname string, baud int, buftype string) {
344347
go p.writerBuffered()
345348
// this is thread to send to serial port regardless of block
346349
go p.writerNoBuf()
347-
p.reader()
350+
p.reader(buftype)
348351

349352
spListDual(false)
350353
spList(false)

0 commit comments

Comments
 (0)