You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// double check that we got characters in the buffer
155
-
// before deciding if an EOF is legitimately a reason
156
-
// to close the port because we're seeing that on some
157
-
// os's like Linux/Ubuntu you get an EOF when you open
158
-
// the port. Perhaps the EOF was buffered from a previous
159
-
// close and the OS doesn't clear out that buffer on a new
160
-
// connect. This means we'll only catch EOF's when there are
161
-
// other characters with it, but that seems to work ok
162
-
ifn<=0 {
163
-
iferr==io.EOF||err==io.ErrUnexpectedEOF {
164
-
// hit end of file
165
-
log.Println("Hit end of file on serial port")
166
-
h.broadcastSys<- []byte("{\"Cmd\":\"OpenFail\",\"Desc\":\"Got EOF (End of File) on port which usually means another app other than Serial Port JSON Server is locking your port. "+err.Error() +"\",\"Port\":\""+p.portConf.Name+"\",\"Baud\":"+strconv.Itoa(p.portConf.Baud) +"}")
153
+
// double check that we got characters in the buffer
154
+
// before deciding if an EOF is legitimately a reason
155
+
// to close the port because we're seeing that on some
156
+
// os's like Linux/Ubuntu you get an EOF when you open
157
+
// the port. Perhaps the EOF was buffered from a previous
158
+
// close and the OS doesn't clear out that buffer on a new
159
+
// connect. This means we'll only catch EOF's when there are
160
+
// other characters with it, but that seems to work ok
161
+
ifn<=0 {
162
+
iferr==io.EOF||err==io.ErrUnexpectedEOF {
163
+
// hit end of file
164
+
log.Println("Hit end of file on serial port")
165
+
h.broadcastSys<- []byte("{\"Cmd\":\"OpenFail\",\"Desc\":\"Got EOF (End of File) on port which usually means another app other than Serial Port JSON Server is locking your port. "+err.Error() +"\",\"Port\":\""+p.portConf.Name+"\",\"Baud\":"+strconv.Itoa(p.portConf.Baud) +"}")
167
166
168
-
}
167
+
}
169
168
170
-
iferr!=nil {
171
-
log.Println(err)
172
-
h.broadcastSys<- []byte("Error reading on "+p.portConf.Name+" "+
173
-
err.Error() +" Closing port.")
174
-
h.broadcastSys<- []byte("{\"Cmd\":\"OpenFail\",\"Desc\":\"Got error reading on port. "+err.Error() +"\",\"Port\":\""+p.portConf.Name+"\",\"Baud\":"+strconv.Itoa(p.portConf.Baud) +"}")
175
-
break
176
-
}
169
+
iferr!=nil {
170
+
log.Println(err)
171
+
h.broadcastSys<- []byte("Error reading on "+p.portConf.Name+" "+
172
+
err.Error() +" Closing port.")
173
+
h.broadcastSys<- []byte("{\"Cmd\":\"OpenFail\",\"Desc\":\"Got error reading on port. "+err.Error() +"\",\"Port\":\""+p.portConf.Name+"\",\"Baud\":"+strconv.Itoa(p.portConf.Baud) +"}")
174
+
break
175
+
}
177
176
178
-
// Keep track of time difference between two consecutive read with n == 0 and err == nil
179
-
// we get here if the port has been disconnected while open (cpu usage will jump to 100%)
180
-
// let's close the port only if the events are extremely fast (<1ms)
181
-
iferr==nil {
182
-
diff:=time.Since(timeCheckOpen)
183
-
ifdiff.Nanoseconds() <1000000 {
184
-
p.isClosing=true
177
+
// Keep track of time difference between two consecutive read with n == 0 and err == nil
178
+
// we get here if the port has been disconnected while open (cpu usage will jump to 100%)
179
+
// let's close the port only if the events are extremely fast (<1ms)
0 commit comments