Skip to content

Commit 726758f

Browse files
committed
Make Write a method of serport
1 parent 9f84d0d commit 726758f

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

serial.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,6 @@ func (sh *serialhub) Unregister(port *serport) {
8383
sh.mu.Unlock()
8484
}
8585

86-
// Write data to the serial port.
87-
func (sh *serialhub) Write(port *serport, data string, sendMode string) {
88-
// if user sent in the commands as one text mode line
89-
switch sendMode {
90-
case "send":
91-
port.sendBuffered <- data
92-
case "sendnobuf":
93-
port.sendNoBuf <- []byte(data)
94-
case "sendraw":
95-
port.sendRaw <- data
96-
}
97-
}
98-
9986
func (sh *serialhub) FindPortByName(portname string) (*serport, bool) {
10087
sh.mu.Lock()
10188
defer sh.mu.Unlock()
@@ -328,5 +315,5 @@ func spWrite(arg string) {
328315
}
329316

330317
// send it to the write channel
331-
sh.Write(port, data, bufferingMode)
318+
port.Write(data, bufferingMode)
332319
}

serialport.go

+13
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ func (p *serport) reader(buftype string) {
174174
}
175175
}
176176

177+
// Write data to the serial port.
178+
func (p *serport) Write(data string, sendMode string) {
179+
// if user sent in the commands as one text mode line
180+
switch sendMode {
181+
case "send":
182+
p.sendBuffered <- data
183+
case "sendnobuf":
184+
p.sendNoBuf <- []byte(data)
185+
case "sendraw":
186+
p.sendRaw <- data
187+
}
188+
}
189+
177190
// this method runs as its own thread because it's instantiated
178191
// as a "go" method. so if it blocks inside, it is ok
179192
func (p *serport) writerBuffered() {

0 commit comments

Comments
 (0)