go-serial icon indicating copy to clipboard operation
go-serial copied to clipboard

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

Open kexin-open opened this issue 8 years ago • 1 comments

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

kexin-open avatar Aug 02 '17 14:08 kexin-open

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() 
)

philipgreat avatar Jul 16 '18 02:07 philipgreat