Skip to content

Commit

Permalink
fix: remove unused buffer slice and simplify data reading in serial port
Browse files Browse the repository at this point in the history
  • Loading branch information
dido18 committed Jan 10, 2025
1 parent 6905fae commit 786ac2b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions serialport.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (p *serport) reader() {
serialBuffer := make([]byte, 1024)
for {
n, err := p.portIo.Read(serialBuffer)
bufferPart := serialBuffer[:n]

//if we detect that port is closing, break out of this for{} loop.
if p.isClosing {
Expand All @@ -90,8 +89,8 @@ func (p *serport) reader() {
// read can return legitimate bytes as well as an error
// so process the n bytes red, if n > 0
if n > 0 && err == nil {
log.Print("Read " + strconv.Itoa(n) + " bytes ch: " + string(bufferPart[:n]))
p.bufferFlow.OnIncomingData(string(bufferPart[:n]))
log.Print("Read " + strconv.Itoa(n) + " bytes ch: " + string(serialBuffer[:n]))
p.bufferFlow.OnIncomingData(string(serialBuffer[:n]))
}

// double check that we got characters in the buffer
Expand Down

0 comments on commit 786ac2b

Please sign in to comment.