@@ -92,7 +92,7 @@ type SpPortMessageRaw struct {
92
92
D []byte // the data, i.e. G0 X0 Y0
93
93
}
94
94
95
- func (p * serport ) reader () {
95
+ func (p * serport ) reader (buftype string ) {
96
96
97
97
//var buf bytes.Buffer
98
98
ch := make ([]byte , 1024 )
@@ -120,21 +120,24 @@ func (p *serport) reader() {
120
120
// read can return legitimate bytes as well as an error
121
121
// so process the bytes if n > 0
122
122
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 ))
124
124
125
125
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
135
140
}
136
- data += string (runeValue )
137
- w = width
138
141
}
139
142
140
143
//log.Print("The data i will convert to json is:")
@@ -344,7 +347,7 @@ func spHandlerOpen(portname string, baud int, buftype string) {
344
347
go p .writerBuffered ()
345
348
// this is thread to send to serial port regardless of block
346
349
go p .writerNoBuf ()
347
- p .reader ()
350
+ p .reader (buftype )
348
351
349
352
spListDual (false )
350
353
spList (false )
0 commit comments