From 667f593174013d1f2f1a682eec5de7e4e5919ced Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 15 Dec 2014 18:13:37 +0100 Subject: [PATCH] linux: implemented last native calls through syscall package no more "C" package dependencies for linux! yay! --- serial_linux.go | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/serial_linux.go b/serial_linux.go index dda39b7..0ff5de1 100644 --- a/serial_linux.go +++ b/serial_linux.go @@ -6,39 +6,6 @@ package serial -/* - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -//int fcntl_wrapper(int fd, int cmd, int arg) { -// return fcntl(fd, cmd, arg); -//} - -// Gain exclusive access to serial port -void setTIOCEXCL(int handle) { -#if defined TIOCEXCL - ioctl(handle, TIOCEXCL); -#endif -} - -// Release exclusive access to serial port -void setTIOCNXCL(int handle) { -#if defined TIOCNXCL - ioctl(handle, TIOCNXCL); -#endif -} - -*/ -import "C" import "io/ioutil" import "regexp" import "syscall" @@ -56,13 +23,11 @@ func ioctl(fd int, req uint64, data uintptr) (err error) { // native syscall wrapper functions func getExclusiveAccess(handle int) error { - _, err := C.setTIOCEXCL(C.int(handle)) - return err + return ioctl(handle, syscall.TIOCEXCL, 0) } func releaseExclusiveAccess(handle int) error { - _, err := C.setTIOCNXCL(C.int(handle)) - return err + return ioctl(handle, syscall.TIOCNXCL, 0) } func getTermSettings(handle int) (*syscall.Termios, error) { @@ -290,7 +255,7 @@ func OpenPort(portName string, exclusive bool) (SerialPort, error) { } // Set local mode - settings.Cflag |= C.CREAD | C.CLOCAL + settings.Cflag |= syscall.CREAD | syscall.CLOCAL // Set raw mode settings.Lflag &= ^uint32(syscall.ICANON | syscall.ECHO | syscall.ECHOE | syscall.ECHOK | syscall.ECHONL | syscall.ECHOCTL | syscall.ECHOPRT | syscall.ECHOKE | syscall.ISIG | syscall.IEXTEN)