jacobsa / go-serial

A Go library for dealing with serial ports.
Apache License 2.0
631 stars 121 forks source link

mips error: serial.Open: SYS_IOCTL: inappropriate ioctl for device #27

Open kexin-open opened 7 years ago

kexin-open commented 7 years ago

code:

     options := serial.OpenOptions{
        PortName: "/dev/ttyS1",
        BaudRate: 9600,
        DataBits: 8,
        StopBits: 1,
        MinimumReadSize: 4,
    }

        port, err := serial.Open(options)
    if err != nil {
        fmt.Printf("serial.Open: %v\n", err)
        return
    }

env: GOOS=linux GOARCH=mipsle go1.8.3 cpu:mt7688

error: serial.Open: SYS_IOCTL: inappropriate ioctl for device

thanks

philipgreat commented 6 years ago

The following code works under mips and arm CPU, it should work on other linux too.

env GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "-s -w" -o server-arm server.go env GOOS=linux GOARCH=mips go build -ldflags "-s -w" mem.go

PC linux is not tested yet. Referenced different headers made this works.

https://github.com/mojo-runtime/lib-linux/blob/6dbfa74d17beda9be9c6e3b595c76f8df3cbb077/c/struct-termios.h

#if defined(__mips__)
#  define NCCS 23
#elif defined(__sparc__)
#  define NCCS 17
#else
#  define NCCS 19
#endif

The change to the file serial/open_linux.go

Please reference https://github.com/philipgreat/go-serial/blob/master/serial/open_linux.go

func nccs() int {
    if runtime.GOARCH == "mips" {
        return 23
    }
    if runtime.GOARCH == "mipsle" {
        return 23
    }
    if runtime.GOARCH == "spark" {
        return 17
    }
    if runtime.GOARCH == "sparc64" {
        return 17
    }
    return 19

}

const (
    kTCSETS2 = unix.TCSETS2 //0x8030542B
    kBOTHER  = unix.BOTHER//0x00001000
    kNCCS    = nccs() 
)