8000 Unable read from port in Mac M1 · Issue #43 · albenik/go-serial · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unable read from port in Mac M1 #43
Open
@sahilpaudel

Description

@sahilpaudel

Hey there,

go version go1.21.6 darwin/arm64

`
import (
"fmt"
"github.com/albenik/go-serial/v2"
"log"
)

func main() {
ports, err := serial.GetPortsList()
if err != nil {
log.Fatal(err)
}
if len(ports) == 0 {
log.Fatal("No serial ports found!")
}

// Print the list of detected ports
for _, port := range ports {
	fmt.Printf("Found port: %v\n", port)
}

port, err := serial.Open(ports[0],
	serial.WithBaudrate(9600),
	serial.WithDataBits(8),
	serial.WithParity(serial.NoParity),
	serial.WithStopBits(serial.OneStopBit),
	serial.WithReadTimeout(2000),
	serial.WithWriteTimeout(2000),
	serial.WithHUPCL(false),
)
if err != nil {
	log.Fatal(err)
}

n, err := port.Write([]byte("sdadas dasdasd dasdasd dasdasda dasd asdas dasd asd as"))
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Sent %v bytes\n", n)

buff := make([]byte, 1024)
for {
	n, err := port.Read(buff)
	fmt.Printf("Length %v", err)
	fmt.Printf("Length %d", n)
	if n == 0 {
		fmt.Println("\nEOF")
		break
	}
	fmt.Printf("%v", string(buff[:n]))
}

}
`

The output of above code is

Found port: /dev/cu.Bluetooth-Incoming-Port Found port: /dev/cu.wlan-debug Found port: /dev/tty.Bluetooth-Incoming-Port Found port: /dev/tty.wlan-debug Sent 54 bytes Length <nil>Length 0 EOF

No matter what I send it gives length of read bytes as 0.
Can you please suggest what am I missing here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull 2C80 requests

    Issue actions

      0