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
153
-
// before deciding if an EOF is legitimately a reason
154
-
// to close the port because we're seeing that on some
155
-
// os's like Linux/Ubuntu you get an EOF when you open
156
-
// the port. Perhaps the EOF was buffered from a previous
157
-
// close and the OS doesn't clear out that buffer on a new
158
-
// connect. This means we'll only catch EOF's when there are
159
-
// other characters with it, but that seems to work ok
160
-
ifn<=0 {
161
-
iferr==io.EOF||err==io.ErrUnexpectedEOF {
162
-
// hit end of file
163
-
log.Println("Hit end of file on serial port")
164
-
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) +"}")
165
-
166
-
}
106
+
break
107
+
}
167
108
109
+
// read can return legitimate bytes as well as an error
// 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) +"}")
166
+
167
+
}
175
168
176
-
// Keep track of time difference between two consecutive read with n == 0 and err == nil
177
-
// we get here if the port has been disconnected while open (cpu usage will jump to 100%)
178
-
// let's close the port only if the events are extremely fast (<1ms)
179
-
iferr==nil {
180
-
diff:=time.Since(timeCheckOpen)
181
-
ifdiff.Nanoseconds() <1000000 {
182
-
p.isClosing=true
183
-
}
184
-
timeCheckOpen=time.Now()
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
+
}
176
+
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