From 006c15bd46f2ff4567d612d3aeefd567a59fadd7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 13 Dec 2014 20:14:39 +0430 Subject: [PATCH] Fixed opaque windowsSerialPort struct --- serial/native_windows.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/serial/native_windows.go b/serial/native_windows.go index 63e7bf8..7413bd8 100644 --- a/serial/native_windows.go +++ b/serial/native_windows.go @@ -59,14 +59,9 @@ import "C" import "syscall" import "unsafe" -// OS dependent values - -const devFolder = "" -const regexFilter = "(ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO)[0-9]{1,3}" - -// opaque type that implements SerialPort interface for linux +// opaque type that implements SerialPort interface for Windows type windowsSerialPort struct { - Handle int + Handle syscall.Handle } func GetPortsList() ([]string, error) { @@ -87,16 +82,18 @@ func GetPortsList() ([]string, error) { return list, nil } -func (port *windowsSerialPort) Close() error { - return nil +func (port windowsSerialPort) Close() error { + return syscall.CloseHandle(port.Handle) } func (port *windowsSerialPort) Read(p []byte) (n int, err error) { return syscall.Read(port.Handle, p) } -func (port *windowsSerialPort) Write(p []byte) (n int, err error) { - return syscall.Write(port.Handle, p) +func (port windowsSerialPort) Write(p []byte) (int, error) { + var writed uint32 + err := syscall.WriteFile(port.Handle, p, &writed, nil) + return int(writed), err } func OpenPort(portName string, useTIOCEXCL bool) (SerialPort, error) {