Fixed custom baud rate settings for MacOSX

This commit is contained in:
Cristian Maglie
2021-07-01 00:19:22 +02:00
parent cff9b2347b
commit 8ed18bb997

View File

@@ -145,6 +145,8 @@ func (port *unixPort) SetMode(mode *Mode) error {
return err return err
} }
if requireSpecialBaudrate { if requireSpecialBaudrate {
// MacOSX require this one to be the last operation otherwise an
// 'Invalid serial port' error is produced.
if err := port.setSpecialBaudrate(uint32(mode.BaudRate)); err != nil { if err := port.setSpecialBaudrate(uint32(mode.BaudRate)); err != nil {
return err return err
} }
@@ -217,11 +219,6 @@ func nativeOpen(portName string, mode *Mode) (*unixPort, error) {
} }
// Setup serial port // Setup serial port
if port.SetMode(mode) != nil {
port.Close()
return nil, &PortError{code: InvalidSerialPort}
}
settings, err := port.getTermSettings() settings, err := port.getTermSettings()
if err != nil { if err != nil {
port.Close() port.Close()
@@ -239,6 +236,13 @@ func nativeOpen(portName string, mode *Mode) (*unixPort, error) {
return nil, &PortError{code: InvalidSerialPort} return nil, &PortError{code: InvalidSerialPort}
} }
// MacOSX require that this operation is the last one otherwise an
// 'Invalid serial port' error is returned... don't know why...
if port.SetMode(mode) != nil {
port.Close()
return nil, &PortError{code: InvalidSerialPort}
}
unix.SetNonblock(h, false) unix.SetNonblock(h, false)
port.acquireExclusiveAccess() port.acquireExclusiveAccess()