From 4def6ef9a94833f8f1b84602b496cd2745336ac1 Mon Sep 17 00:00:00 2001 From: Edgar <44380483+Edgar242@users.noreply.github.com> Date: Fri, 14 Jun 2019 17:27:56 -0500 Subject: [PATCH] When the port Address number was grater than 10 the port couldn't be oppened, and a solution to this problem is adding those back slashes, other libraries are using this method. --- serial_windows.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/serial_windows.go b/serial_windows.go index 1eeb14b..1ff72af 100644 --- a/serial_windows.go +++ b/serial_windows.go @@ -156,13 +156,17 @@ func (p *port) setSerialConfig(c *Config) error { } func newHandle(c *Config) (handle syscall.Handle, err error) { + name := c.Address + if len(name) > 0 && name[0] != '\\' { + name = "\\\\.\\" + name + } handle, err = syscall.CreateFile( - syscall.StringToUTF16Ptr(c.Address), + syscall.StringToUTF16Ptr(name), syscall.GENERIC_READ|syscall.GENERIC_WRITE, - 0, // mode - nil, // security + 0, // mode + nil, // security syscall.OPEN_EXISTING, // create mode - 0, // attributes - 0) // templates + 0, // attributes + 0) // templates return }