diff --git a/serial_unix.go b/serial_unix.go index 54e55a8..338c5b6 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -109,12 +109,25 @@ func (port *unixPort) Read(p []byte) (int, error) { } } -func (port *unixPort) Write(p []byte) (n int, err error) { - n, err = unix.Write(port.handle, p) +func (port *unixPort) writeOnce(p []byte) (int, error) { + n, err := unix.Write(port.handle, p) if n < 0 { // Do not return -1 unix errors + if err == nil { + err = fmt.Errorf("unix.Write() returned n<0,err==nil: n=%d", n) + } n = 0 } - return + return n, err +} + +func (port *unixPort) Write(p []byte) (n int, err error) { + for n < len(p) && err == nil { + var n2 int + n2, err = port.writeOnce(p[n:]) + n += n2 + } + + return n, err } func (port *unixPort) Break(t time.Duration) error {