@@ -106,6 +106,20 @@ func (sh *serialhub) run() {
106
106
}
107
107
}
108
108
109
+ func (sh * serialhub ) FindPortByName (portname string ) (* serport , bool ) {
110
+ sh .mu .Lock ()
111
+ defer sh .mu .Unlock ()
112
+
113
+ for port := range sh .ports {
114
+ if strings .EqualFold (port .portConf .Name , portname ) {
115
+ // we found our port
116
+ //spHandlerClose(port)
117
+ return port , true
118
+ }
119
+ }
120
+ return nil , false
121
+ }
122
+
109
123
func write (wr writeRequest ) {
110
124
switch wr .buffer {
111
125
case "send" :
@@ -167,7 +181,7 @@ func (sp *SerialPortList) Update() {
167
181
}
168
182
169
183
// figure out if port is open
170
- if myport , isFound := findPortByName (item .Name ); isFound {
184
+ if myport , isFound := sh . FindPortByName (item .Name ); isFound {
171
185
// and update data with the open port parameters
172
186
port .IsOpen = true
173
187
port .Baud = myport .portConf .Baud
@@ -193,7 +207,7 @@ func spClose(portname string) {
193
207
// that should cause an unregister channel call back
194
208
// to myself
195
209
196
- myport , isFound := findPortByName (portname )
210
+ myport , isFound := sh . FindPortByName (portname )
197
211
198
212
if isFound {
199
213
// we found our port
@@ -221,7 +235,7 @@ func spWrite(arg string) {
221
235
//log.Println("The data is:" + args[2] + "---")
222
236
223
237
// see if we have this port open
224
- myport , isFound := findPortByName (portname )
238
+ myport , isFound := sh . FindPortByName (portname )
225
239
226
240
if ! isFound {
227
241
// we couldn't find the port, so send err
0 commit comments