diff --git a/hal/src/main/native/include/wpi/hal/SerialPort.h b/hal/src/main/native/include/wpi/hal/SerialPort.h index 3facf1ca70..55ca0f1f96 100644 --- a/hal/src/main/native/include/wpi/hal/SerialPort.h +++ b/hal/src/main/native/include/wpi/hal/SerialPort.h @@ -15,10 +15,10 @@ */ HAL_ENUM(HAL_SerialPort) { - HAL_SerialPort_Onboard = 0, - HAL_SerialPort_MXP = 1, - HAL_SerialPort_USB1 = 2, - HAL_SerialPort_USB2 = 3 + HAL_SERIAL_PORT_ONBOARD = 0, + HAL_SERIAL_PORT_MXP = 1, + HAL_SERIAL_PORT_USB_1 = 2, + HAL_SERIAL_PORT_USB_2 = 3 }; #ifdef __cplusplus diff --git a/wpilibc/src/main/native/cpp/hardware/bus/SerialPort.cpp b/wpilibc/src/main/native/cpp/hardware/bus/SerialPort.cpp index 9a3093bdab..2ffdb21ea8 100644 --- a/wpilibc/src/main/native/cpp/hardware/bus/SerialPort.cpp +++ b/wpilibc/src/main/native/cpp/hardware/bus/SerialPort.cpp @@ -24,10 +24,10 @@ SerialPort::SerialPort(int baudRate, Port port, int dataBits, WPILIB_CheckErrorStatus(status, "SetSerialBaudRate {}", baudRate); HAL_SetSerialDataBits(m_portHandle, dataBits, &status); WPILIB_CheckErrorStatus(status, "SetSerialDataBits {}", dataBits); - HAL_SetSerialParity(m_portHandle, parity, &status); + HAL_SetSerialParity(m_portHandle, static_cast(parity), &status); WPILIB_CheckErrorStatus(status, "SetSerialParity {}", static_cast(parity)); - HAL_SetSerialStopBits(m_portHandle, stopBits, &status); + HAL_SetSerialStopBits(m_portHandle, static_cast(stopBits), &status); WPILIB_CheckErrorStatus(status, "SetSerialStopBits {}", static_cast(stopBits)); @@ -35,7 +35,7 @@ SerialPort::SerialPort(int baudRate, Port port, int dataBits, SetTimeout(5_s); // Don't wait until the buffer is full to transmit. - SetWriteBufferMode(kFlushOnAccess); + SetWriteBufferMode(WriteBufferMode::FLUSH_ON_ACCESS); DisableTermination(); @@ -55,10 +55,10 @@ SerialPort::SerialPort(int baudRate, std::string_view portName, Port port, WPILIB_CheckErrorStatus(status, "SetSerialBaudRate {}", baudRate); HAL_SetSerialDataBits(m_portHandle, dataBits, &status); WPILIB_CheckErrorStatus(status, "SetSerialDataBits {}", dataBits); - HAL_SetSerialParity(m_portHandle, parity, &status); + HAL_SetSerialParity(m_portHandle, static_cast(parity), &status); WPILIB_CheckErrorStatus(status, "SetSerialParity {}", static_cast(parity)); - HAL_SetSerialStopBits(m_portHandle, stopBits, &status); + HAL_SetSerialStopBits(m_portHandle, static_cast(stopBits), &status); WPILIB_CheckErrorStatus(status, "SetSerialStopBits {}", static_cast(stopBits)); @@ -66,7 +66,7 @@ SerialPort::SerialPort(int baudRate, std::string_view portName, Port port, SetTimeout(5_s); // Don't wait until the buffer is full to transmit. - SetWriteBufferMode(kFlushOnAccess); + SetWriteBufferMode(WriteBufferMode::FLUSH_ON_ACCESS); DisableTermination(); @@ -75,7 +75,8 @@ SerialPort::SerialPort(int baudRate, std::string_view portName, Port port, void SerialPort::SetFlowControl(SerialPort::FlowControl flowControl) { int32_t status = 0; - HAL_SetSerialFlowControl(m_portHandle, flowControl, &status); + HAL_SetSerialFlowControl(m_portHandle, static_cast(flowControl), + &status); WPILIB_CheckErrorStatus(status, "SetFlowControl {}", static_cast(flowControl)); } @@ -138,7 +139,7 @@ void SerialPort::SetWriteBufferSize(int size) { void SerialPort::SetWriteBufferMode(SerialPort::WriteBufferMode mode) { int32_t status = 0; - HAL_SetSerialWriteMode(m_portHandle, mode, &status); + HAL_SetSerialWriteMode(m_portHandle, static_cast(mode), &status); WPILIB_CheckErrorStatus(status, "SetWriteBufferMode {}", static_cast(mode)); } diff --git a/wpilibc/src/main/native/include/wpi/hardware/bus/SerialPort.hpp b/wpilibc/src/main/native/include/wpi/hardware/bus/SerialPort.hpp index 28432d768a..5c181ec013 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/bus/SerialPort.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/bus/SerialPort.hpp @@ -29,69 +29,69 @@ class SerialPort { /** * Serial port. */ - enum Port { + enum class Port { /// Onboard serial port on the roboRIO. - kOnboard = 0, + ONBOARD = 0, /// MXP (roboRIO MXP) serial port. - kMXP = 1, - /// USB serial port (same as kUSB1). - kUSB = 2, + MXP = 1, + /// USB serial port (same as USB_1). + USB = 2, /// USB serial port 1. - kUSB1 = 2, + USB_1 = 2, /// USB serial port 2. - kUSB2 = 3 + USB_2 = 3 }; /** * Represents the parity to use for serial communications. */ - enum Parity { + enum class Parity { /// No parity. - kParity_None = 0, + NONE = 0, /// Odd parity. - kParity_Odd = 1, + ODD = 1, /// Even parity. - kParity_Even = 2, + EVEN = 2, /// Parity bit always on. - kParity_Mark = 3, + MARK = 3, /// Parity bit always off. - kParity_Space = 4 + SPACE = 4 }; /** * Represents the number of stop bits to use for Serial Communication. */ - enum StopBits { + enum class StopBits { /// One stop bit. - kStopBits_One = 10, + ONE = 10, /// One and a half stop bits. - kStopBits_OnePointFive = 15, + ONE_POINT_FIVE = 15, /// Two stop bits. - kStopBits_Two = 20 + TWO = 20 }; /** * Represents what type of flow control to use for serial communication. */ - enum FlowControl { + enum class FlowControl { /// No flow control. - kFlowControl_None = 0, + NONE = 0, /// XON/XOFF flow control. - kFlowControl_XonXoff = 1, + XON_XOFF = 1, /// RTS/CTS flow control. - kFlowControl_RtsCts = 2, + RTS_CTS = 2, /// DTS/DSR flow control. - kFlowControl_DtrDsr = 4 + DTR_DSR = 4 }; /** * Represents which type of buffer mode to use when writing to a serial port. */ - enum WriteBufferMode { + enum class WriteBufferMode { /// Flush the buffer on each access. - kFlushOnAccess = 1, + FLUSH_ON_ACCESS = 1, /// Flush the buffer when it is full. - kFlushWhenFull = 2 + FLUSH_WHEN_FULL = 2 }; /** @@ -105,9 +105,9 @@ class SerialPort { * @param stopBits The number of stop bits to use as defined by the enum * StopBits. */ - explicit SerialPort(int baudRate, Port port = kOnboard, int dataBits = 8, - Parity parity = kParity_None, - StopBits stopBits = kStopBits_One); + explicit SerialPort(int baudRate, Port port = Port::ONBOARD, int dataBits = 8, + Parity parity = Parity::NONE, + StopBits stopBits = StopBits::ONE); /** * Create an instance of a Serial Port class. @@ -124,9 +124,9 @@ class SerialPort { * @param stopBits The number of stop bits to use as defined by the enum * StopBits. */ - SerialPort(int baudRate, std::string_view portName, Port port = kOnboard, - int dataBits = 8, Parity parity = kParity_None, - StopBits stopBits = kStopBits_One); + SerialPort(int baudRate, std::string_view portName, Port port = Port::ONBOARD, + int dataBits = 8, Parity parity = Parity::NONE, + StopBits stopBits = StopBits::ONE); SerialPort(SerialPort&& rhs) = default; SerialPort& operator=(SerialPort&& rhs) = default; @@ -227,10 +227,10 @@ class SerialPort { /** * Specify the flushing behavior of the output buffer. * - * When set to kFlushOnAccess, data is synchronously written to the serial + * When set to FLUSH_ON_ACCESS, data is synchronously written to the serial * port after each call to either Printf() or Write(). * - * When set to kFlushWhenFull, data will only be written to the serial port + * When set to FLUSH_WHEN_FULL, data will only be written to the serial port * when the buffer is full or when Flush() is called. * * @param mode The write buffer mode. @@ -240,7 +240,7 @@ class SerialPort { /** * Force the output buffer to be written to the port. * - * This is used when SetWriteBufferMode() is set to kFlushWhenFull to force a + * This is used when SetWriteBufferMode() is set to FLUSH_WHEN_FULL to force a * flush before the buffer is full. */ void Flush(); diff --git a/wpilibc/src/main/python/semiwrap/SerialPort.yml b/wpilibc/src/main/python/semiwrap/SerialPort.yml index 8788584017..5fae374a8b 100644 --- a/wpilibc/src/main/python/semiwrap/SerialPort.yml +++ b/wpilibc/src/main/python/semiwrap/SerialPort.yml @@ -12,19 +12,19 @@ classes: int, Port, int, Parity, StopBits: param_override: port: - default: wpi::SerialPort::Port::kOnboard + default: wpi::SerialPort::Port::ONBOARD parity: - default: wpi::SerialPort::Parity::kParity_None + default: wpi::SerialPort::Parity::NONE stopBits: - default: wpi::SerialPort::StopBits::kStopBits_One + default: wpi::SerialPort::StopBits::ONE int, std::string_view, Port, int, Parity, StopBits: param_override: port: - default: wpi::SerialPort::Port::kOnboard + default: wpi::SerialPort::Port::ONBOARD parity: - default: wpi::SerialPort::Parity::kParity_None + default: wpi::SerialPort::Parity::NONE stopBits: - default: wpi::SerialPort::StopBits::kStopBits_One + default: wpi::SerialPort::StopBits::ONE SetFlowControl: EnableTermination: param_override: diff --git a/wpilibj/src/main/java/org/wpilib/hardware/bus/SerialPort.java b/wpilibj/src/main/java/org/wpilib/hardware/bus/SerialPort.java index 3a577ca61c..ac0bbe3925 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/bus/SerialPort.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/bus/SerialPort.java @@ -15,15 +15,15 @@ public class SerialPort implements AutoCloseable { /** Serial port. */ public enum Port { /** Onboard serial port on the roboRIO. */ - kOnboard(0), + ONBOARD(0), /** MXP (roboRIO MXP) serial port. */ - kMXP(1), + MXP(1), /** USB serial port (same as kUSB1). */ - kUSB(2), + USB(2), /** USB serial port 1. */ - kUSB1(2), + USB_1(2), /** USB serial port 2. */ - kUSB2(3); + USB_2(3); /** Port value. */ public final int value; @@ -36,15 +36,15 @@ public class SerialPort implements AutoCloseable { /** Represents the parity to use for serial communications. */ public enum Parity { /** No parity. */ - kNone(0), + NONE(0), /** Odd parity. */ - kOdd(1), + ODD(1), /** Even parity. */ - kEven(2), + EVEN(2), /** Parity bit always on. */ - kMark(3), + MARK(3), /** Parity bit always off. */ - kSpace(4); + SPACE(4); /** Parity value. */ public final int value; @@ -57,11 +57,11 @@ public class SerialPort implements AutoCloseable { /** Represents the number of stop bits to use for Serial Communication. */ public enum StopBits { /** One stop bit. */ - kOne(10), + ONE(10), /** One and a half stop bits. */ - kOnePointFive(15), + ONE_POINT_FIVE(15), /** Two stop bits. */ - kTwo(20); + TWO(20); /** StopBits value. */ public final int value; @@ -74,13 +74,13 @@ public class SerialPort implements AutoCloseable { /** Represents what type of flow control to use for serial communication. */ public enum FlowControl { /** No flow control. */ - kNone(0), + NONE(0), /** XON/XOFF flow control. */ - kXonXoff(1), + XON_XOFF(1), /** RTS/CTS flow control. */ - kRtsCts(2), + RTS_CTS(2), /** DTS/DSR flow control. */ - kDtsDsr(4); + DTS_DSR(4); /** FlowControl value. */ public final int value; @@ -93,9 +93,9 @@ public class SerialPort implements AutoCloseable { /** Represents which type of buffer mode to use when writing to a serial port. */ public enum WriteBufferMode { /** Flush the buffer on each access. */ - kFlushOnAccess(1), + FLUSH_ON_ACCESS(1), /** Flush the buffer when it is full. */ - kFlushWhenFull(2); + FLUSH_WHEN_FULL(2); /** WriteBufferMode value. */ public final int value; @@ -129,7 +129,7 @@ public class SerialPort implements AutoCloseable { setTimeout(5.0); // Don't wait until the buffer is full to transmit. - setWriteBufferMode(WriteBufferMode.kFlushOnAccess); + setWriteBufferMode(WriteBufferMode.FLUSH_ON_ACCESS); disableTermination(); @@ -145,7 +145,7 @@ public class SerialPort implements AutoCloseable { * @param parity Select the type of parity checking to use. */ public SerialPort(final int baudRate, Port port, final int dataBits, Parity parity) { - this(baudRate, port, dataBits, parity, StopBits.kOne); + this(baudRate, port, dataBits, parity, StopBits.ONE); } /** @@ -156,7 +156,7 @@ public class SerialPort implements AutoCloseable { * @param dataBits The number of data bits per transfer. Valid values are between 5 and 8 bits. */ public SerialPort(final int baudRate, Port port, final int dataBits) { - this(baudRate, port, dataBits, Parity.kNone, StopBits.kOne); + this(baudRate, port, dataBits, Parity.NONE, StopBits.ONE); } /** @@ -166,7 +166,7 @@ public class SerialPort implements AutoCloseable { * @param port The serial port to use. */ public SerialPort(final int baudRate, Port port) { - this(baudRate, port, 8, Parity.kNone, StopBits.kOne); + this(baudRate, port, 8, Parity.NONE, StopBits.ONE); } @Override