From 786ac2b04d941833bae6e30cdb6f9550d29fb364 Mon Sep 17 00:00:00 2001 From: Davide N Date: Fri, 10 Jan 2025 15:21:01 +0100 Subject: [PATCH] fix: remove unused buffer slice and simplify data reading in serial port --- serialport.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/serialport.go b/serialport.go index d5862681..21affc42 100755 --- a/serialport.go +++ b/serialport.go @@ -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 { @@ -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