diff --git a/src/examples/Si7021_example.cpp b/src/examples/Si7021_example.cpp index 33a9a4aa9fa248aebad13495b1df878d769be00a..9e8c701227ad9713c16bd852fd2d6e73c9a5362a 100644 --- a/src/examples/Si7021_example.cpp +++ b/src/examples/Si7021_example.cpp @@ -13,7 +13,8 @@ #include "Si7021.h" int main(int argc, char* argv[]) { - std::shared_ptr<TextSerialCom> TC(new TextSerialCom("/dev/ttyACM2", B9600)); + std::shared_ptr<TextSerialCom> TC( + new TextSerialCom("/dev/ttyACM2", SerialCom::BaudRate::Baud9600)); TC->setTermination("\r\n"); TC->init(); std::shared_ptr<I2CCom> i2c(new I2CDevComuino(0x40, TC)); diff --git a/src/examples/Si7021_example.py b/src/examples/Si7021_example.py index 90d7999ffb096459f5c6865b4a0a56f1be32310a..5c4f1567c035df05ba682cb7f7bd5835b2777c69 100644 --- a/src/examples/Si7021_example.py +++ b/src/examples/Si7021_example.py @@ -14,7 +14,8 @@ def si7021_example(device, baud, address) : ## initialize the communication line ## try : - serial = com.TextSerialCom(device, baud) + baud_rate = getattr(com.SerialCom.BaudRate, 'Baud{0:d}'.format(baud)) + serial = com.TextSerialCom(device, baud_rate) except : logger.error(f"Unable to initialize serial communication with device at port \"{device}\"") sys.exit(1) diff --git a/src/examples/chiller_example.cpp b/src/examples/chiller_example.cpp index 6e82c847af3058c349430915e06d985d9750e385..69ca58dfd92eec1aaacabe4eeca22ab6e75a62e7 100644 --- a/src/examples/chiller_example.cpp +++ b/src/examples/chiller_example.cpp @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) { // inputs float target_temp = 15; std::string device = ""; - speed_t baud = B9600; + SerialCom::BaudRate baud = SerialCom::BaudRate::Baud9600; int c; while (true) { @@ -61,13 +61,13 @@ int main(int argc, char* argv[]) { case 'b': { std::string baud_str = optarg; if (baud_str == "2400") - baud = B2400; + baud = SerialCom::BaudRate::Baud2400; else if (baud_str == "4800") - baud = B4800; + baud = SerialCom::BaudRate::Baud4800; else if (baud_str == "9600") - baud = B9600; + baud = SerialCom::BaudRate::Baud9600; else if (baud_str == "19200") - baud = B19200; + baud = SerialCom::BaudRate::Baud19200; else { std::cerr << "Invalid baud rate '" << optarg << "' supplied. Use either 2400, 4800, 9600, or " diff --git a/src/examples/chiller_example.py b/src/examples/chiller_example.py index af21bf262dacb5996eaa8b45ab8bcb06f5c4610b..3c4983221a20bd064a3e2547e5c2c3f09ca72b23 100644 --- a/src/examples/chiller_example.py +++ b/src/examples/chiller_example.py @@ -14,7 +14,8 @@ def chiller_example(device, baud, temperature) : ## setup the communication line ## try : - serial = com.TextSerialCom(device, baud) + baud_rate = getattr(com.SerialCom.BaudRate, 'Baud{0:d}'.format(baud)) + serial = com.TextSerialCom(device, baud_rate) except : logger.error(f"Unable to initialize serial communication with device at port \"{device}\"") sys.exit(1) diff --git a/src/examples/devcomuino_example.cpp b/src/examples/devcomuino_example.cpp index dd7bb95ddc36fab9d638254d6bf05da66b57d8f9..bbae1ec48b7890e3347bedee70f776f18057a17e 100644 --- a/src/examples/devcomuino_example.cpp +++ b/src/examples/devcomuino_example.cpp @@ -13,7 +13,7 @@ // https://cdn-learn.adafruit.com/assets/assets/000/035/931/original/Support_Documents_TechnicalDocs_Si7021-A20.pdf int main(int argc, char* argv[]) { - TextSerialCom com("/dev/ttyACM2", B9600); + TextSerialCom com("/dev/ttyACM2", SerialCom::BaudRate::Baud9600); com.setTermination("\r\n"); com.init(); diff --git a/src/examples/devcomuino_example.py b/src/examples/devcomuino_example.py index cf31fa78189c05cad9f8c72a9e7a7ff1d96d409c..692f9c4c8481beb4a1694787331fab577674a816 100644 --- a/src/examples/devcomuino_example.py +++ b/src/examples/devcomuino_example.py @@ -25,7 +25,8 @@ def devcomuino_example(device, baud) : ## initialize the communication line ## try : - serial = com.TextSerialCom(device, baud) + baud_rate = getattr(com.SerialCom.BaudRate, 'Baud{0:d}'.format(baud)) + serial = com.TextSerialCom(device, baud_rate) except : logger.error(f"Unable to initialize serial communication with device at port \"{device}\"") sys.exit(1) diff --git a/src/examples/ntc_example.cpp b/src/examples/ntc_example.cpp index 277c3f8799c92819d04017a92c7cfe36f9ddb80a..59599f998b42a7f9ca54c7623b5f4d63c177de79 100644 --- a/src/examples/ntc_example.cpp +++ b/src/examples/ntc_example.cpp @@ -132,7 +132,7 @@ int main(int argc, char* argv[]) { logger(logDEBUG) << "Pin: " << (int)pin; std::shared_ptr<TextSerialCom> com = - std::make_shared<TextSerialCom>(port, B9600); + std::make_shared<TextSerialCom>(port, SerialCom::BaudRate::Baud9600); com->setTermination("\r\n"); com->setTimeout(5); com->init(); diff --git a/src/examples/ntc_example.py b/src/examples/ntc_example.py index 246f8899c8c4e5a6ffe2b4732fb7598f390d4917..a881c01b9ef687f86b7e237ffa58eb12561f7402 100644 --- a/src/examples/ntc_example.py +++ b/src/examples/ntc_example.py @@ -33,7 +33,7 @@ def ntc_example(device, pin) : ## initialize the communication line ## try : - serial = com.TextSerialCom(device, 9600) + serial = com.TextSerialCom(device, com.SerialCom.BaudRate.Baud9600) except : logger.error(f"Unable to initialize serial communication with device at port \"{device}\"") sys.exit(1) diff --git a/src/examples/sht85_example.cpp b/src/examples/sht85_example.cpp index 3c81b81711898a94daa103cad873b885771532a6..9ffdbbf0549dcb975fcdf99651d9cd24b90810db 100644 --- a/src/examples/sht85_example.cpp +++ b/src/examples/sht85_example.cpp @@ -19,7 +19,8 @@ int main(int argc, char* argv[]) { MPSSEChip::Endianness::MSBFirst); std::shared_ptr<I2CCom> i2c = std::make_shared<I2CFTDICom>(ftdi, 0x44); #else - std::shared_ptr<TextSerialCom> TC(new TextSerialCom("/dev/ttyACM0", B9600)); + std::shared_ptr<TextSerialCom> TC( + new TextSerialCom("/dev/ttyACM0", SerialCom::BaudRate::Baud9600)); TC->setTermination("\r\n"); TC->init(); diff --git a/src/examples/sht85_example.py b/src/examples/sht85_example.py index 36e87323b28cc38802e50608e2615108c4834b3f..f610cacd14500b8f69c4ad37d5698888cbd4466a 100644 --- a/src/examples/sht85_example.py +++ b/src/examples/sht85_example.py @@ -27,7 +27,8 @@ def sht85_example(use_ftdi, device, baud) : ## initialize the communication line ## try : - serial = com.TextSerialCom(device, baud) + baud_rate = getattr(com.SerialCom.BaudRate, 'Baud{0:d}'.format(baud)) + serial = com.TextSerialCom(device, baud_rate) except : logger.error(f"Unable to initialize serial communication with the device at port \"{device}\"") sys.exit(1) diff --git a/src/examples/temp_hum_monitor_example.cpp b/src/examples/temp_hum_monitor_example.cpp index da470dd5dd3c56f22ec3861a44466ed2c2ce80bc..2e37494ca0dbca440f222e174876284ab887ba50 100644 --- a/src/examples/temp_hum_monitor_example.cpp +++ b/src/examples/temp_hum_monitor_example.cpp @@ -87,7 +87,7 @@ int main(int argc, char** argv) { } // open serial device - speed_t baud = B9600; + SerialCom::BaudRate baud = SerialCom::BaudRate::Baud9600; std::shared_ptr<TextSerialCom> sc( new TextSerialCom("/dev/ttyACM" + std::to_string(rport), baud)); sc->init(); diff --git a/src/labRemote/module.cpp b/src/labRemote/module.cpp index e9e26ac5fbdd17887593ec589611b6e0413f52fc..7c088e4e0a1186856f50e29acdc6c85ba43e4b4b 100644 --- a/src/labRemote/module.cpp +++ b/src/labRemote/module.cpp @@ -1,7 +1,7 @@ -#include "Logger.h" - #include <pybind11/pybind11.h> +#include "Logger.h" + namespace py = pybind11; void register_com(py::module&); diff --git a/src/libChiller/PolySciLM.h b/src/libChiller/PolySciLM.h index 11e8977cbb3bc888421935d1c33b3a62db19d5fa..0c69ec93ca9da69b3e708a5773c8a7f860f4e2f5 100644 --- a/src/libChiller/PolySciLM.h +++ b/src/libChiller/PolySciLM.h @@ -19,7 +19,7 @@ * * ``` * std::shared_ptr<TextSerialCom> com = - * std::make_shared<TextSerialCom>("/dev/ttyUSB0",B9600); + * std::make_shared<TextSerialCom>("/dev/ttyUSB0",SerialCom::BaudRate::Baud9600); * com->setTermination("\r"); * com->init(); * diff --git a/src/libCom/GPIBSerialCom.cpp b/src/libCom/GPIBSerialCom.cpp index e82f389597213341e36fffe28b81710b8f8cb79c..3e7f03b050550f011460504d592bd2f804fc606c 100644 --- a/src/libCom/GPIBSerialCom.cpp +++ b/src/libCom/GPIBSerialCom.cpp @@ -16,8 +16,9 @@ REGISTER_COM(GPIBSerialCom) GPIBSerialCom::GPIBSerialCom(uint16_t gpib_addr, const std::string& port, - speed_t baud, bool parityBit, bool twoStopBits, - bool flowControl, CharSize charsize) + SerialCom::BaudRate baud, bool parityBit, + bool twoStopBits, bool flowControl, + SerialCom::CharSize charsize) : TextSerialCom(port, baud, parityBit, twoStopBits, flowControl, charsize), m_gpib_addr(gpib_addr) {} diff --git a/src/libCom/GPIBSerialCom.h b/src/libCom/GPIBSerialCom.h index f4bbae4513b8bbefcb9b6581cd1de99a3557d68c..5c37987759919faf1b1a122c3eb7a343636ed066 100644 --- a/src/libCom/GPIBSerialCom.h +++ b/src/libCom/GPIBSerialCom.h @@ -26,10 +26,12 @@ class GPIBSerialCom : public TextSerialCom { * @param flowControl Enable hardware flow control * @param charsize Size of a character */ - GPIBSerialCom(uint16_t gpib_addr, const std::string& port, - speed_t baud = B19200, bool parityBit = false, - bool twoStopBits = false, bool flowControl = false, - CharSize charsize = CharSize::CharSize8); + GPIBSerialCom( + uint16_t gpib_addr, const std::string& port, + SerialCom::BaudRate baud = SerialCom::BaudRate::Baud19200, + bool parityBit = false, bool twoStopBits = false, + bool flowControl = false, + SerialCom::CharSize charsize = SerialCom::CharSize::CharSize8); GPIBSerialCom(); ~GPIBSerialCom(); diff --git a/src/libCom/SerialCom.cpp b/src/libCom/SerialCom.cpp index edaccca46bd75e8f8ddd2c01fcefb72481060d53..3a4aad9d089d3ac9fc3413eff8a5febeac0f302f 100644 --- a/src/libCom/SerialCom.cpp +++ b/src/libCom/SerialCom.cpp @@ -17,19 +17,46 @@ #include "ComRegistry.h" REGISTER_COM(SerialCom) -const std::unordered_map<std::string, speed_t> SerialCom::mapBAUDRATE = { - {"B0", B0}, {"B50", B50}, {"B75", B75}, {"B110", B110}, - {"B134", B134}, {"B150", B150}, {"B200", B200}, {"B300", B300}, - {"B600", B600}, {"B1200", B1200}, {"B1800", B1800}, {"B2400", B2400}, - {"B4800", B4800}, {"B9600", B9600}, {"B19200", B19200}, {"B38400", B38400}}; +const std::unordered_map<std::string, SerialCom::BaudRate> + SerialCom::mapBAUDRATE = {{"B0", SerialCom::BaudRate::Baud0}, + {"B50", SerialCom::BaudRate::Baud50}, + {"B75", SerialCom::BaudRate::Baud75}, + {"B110", SerialCom::BaudRate::Baud110}, + {"B134", SerialCom::BaudRate::Baud134}, + {"B150", SerialCom::BaudRate::Baud150}, + {"B200", SerialCom::BaudRate::Baud200}, + {"B300", SerialCom::BaudRate::Baud300}, + {"B600", SerialCom::BaudRate::Baud600}, + {"B1200", SerialCom::BaudRate::Baud1200}, + {"B1800", SerialCom::BaudRate::Baud1800}, + {"B2400", SerialCom::BaudRate::Baud2400}, + {"B4800", SerialCom::BaudRate::Baud4800}, + {"B9600", SerialCom::BaudRate::Baud9600}, + {"B19200", SerialCom::BaudRate::Baud19200}, + {"B38400", SerialCom::BaudRate::Baud38400}, + {"B57600", SerialCom::BaudRate::Baud57600}, + {"B115200", SerialCom::BaudRate::Baud115200}, + {"B230400", SerialCom::BaudRate::Baud230400}, + {"B460800", SerialCom::BaudRate::Baud460800}, + {"B500000", SerialCom::BaudRate::Baud500000}, + {"B576000", SerialCom::BaudRate::Baud576000}, + {"B921600", SerialCom::BaudRate::Baud921600}, + {"B1000000", SerialCom::BaudRate::Baud1000000}, + {"B1152000", SerialCom::BaudRate::Baud1152000}, + {"B1500000", SerialCom::BaudRate::Baud1500000}, + {"B2000000", SerialCom::BaudRate::Baud2000000}, + {"B2500000", SerialCom::BaudRate::Baud2500000}, + {"B3000000", SerialCom::BaudRate::Baud3000000}, + {"B3500000", SerialCom::BaudRate::Baud3500000}, + {"B4000000", SerialCom::BaudRate::Baud4000000}}; const std::unordered_map<std::string, SerialCom::CharSize> - SerialCom::mapCHARSIZE = {{"CS5", CharSize5}, - {"CS6", CharSize6}, - {"CS7", CharSize7}, - {"CS8", CharSize8}}; + SerialCom::mapCHARSIZE = {{"CS5", SerialCom::CharSize::CharSize5}, + {"CS6", SerialCom::CharSize::CharSize6}, + {"CS7", SerialCom::CharSize::CharSize7}, + {"CS8", SerialCom::CharSize::CharSize8}}; -SerialCom::SerialCom(const std::string &port, speed_t baud, bool parityBit, +SerialCom::SerialCom(const std::string &port, BaudRate baud, bool parityBit, bool twoStopBits, bool flowControl, CharSize charsize) : m_port(port), m_baudrate(baud), @@ -98,11 +125,12 @@ void SerialCom::config() { logger(logDEBUG3) << __PRETTY_FUNCTION__; logger(logDEBUG3) << "Configuring serial device " << m_port; - logger(logDEBUG3) << " Baud Rate: " << m_baudrate; + logger(logDEBUG3) << " Baud Rate: " << static_cast<speed_t>(m_baudrate); logger(logDEBUG3) << " Enable parity bit: " << m_parityBit; logger(logDEBUG3) << " Use two stop bits: " << m_twoStopBits; logger(logDEBUG3) << " Enable hardware flow control: " << m_flowControl; - logger(logDEBUG3) << " Character size: " << m_charsize; + logger(logDEBUG3) << " Character size: " + << static_cast<tcflag_t>(m_charsize); ScopeLock lock(this); if (tcgetattr(m_dev, &m_tty)) @@ -111,8 +139,8 @@ void SerialCom::config() { m_tty_old = m_tty; - cfsetospeed(&m_tty, m_baudrate); - cfsetispeed(&m_tty, m_baudrate); + cfsetospeed(&m_tty, static_cast<speed_t>(m_baudrate)); + cfsetispeed(&m_tty, static_cast<speed_t>(m_baudrate)); if (m_parityBit) m_tty.c_cflag &= PARENB; @@ -130,7 +158,7 @@ void SerialCom::config() { m_tty.c_cflag &= ~CRTSCTS; m_tty.c_cflag &= ~CSIZE; - m_tty.c_cflag |= m_charsize; + m_tty.c_cflag |= static_cast<tcflag_t>(m_charsize); m_tty.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines cfmakeraw(&m_tty); diff --git a/src/libCom/SerialCom.h b/src/libCom/SerialCom.h index 1e434434ab6d43a39a7d29f2c28d6ba2988105d5..8d437baa22537e2c044066b7224ba875509abf84 100644 --- a/src/libCom/SerialCom.h +++ b/src/libCom/SerialCom.h @@ -24,8 +24,43 @@ */ class SerialCom : public ICom { public: + /** Available baud rates */ + enum class BaudRate : speed_t { + Baud0 = B0, + Baud50 = B50, + Baud75 = B75, + Baud110 = B110, + Baud134 = B134, + Baud150 = B150, + Baud200 = B200, + Baud300 = B300, + Baud600 = B600, + Baud1200 = B1200, + Baud1800 = B1800, + Baud2400 = B2400, + Baud4800 = B4800, + Baud9600 = B9600, + Baud19200 = B19200, + Baud38400 = B38400, + Baud57600 = B57600, + Baud115200 = B115200, + Baud230400 = B230400, + Baud460800 = B460800, + Baud500000 = B500000, + Baud576000 = B576000, + Baud921600 = B921600, + Baud1000000 = B1000000, + Baud1152000 = B1152000, + Baud1500000 = B1500000, + Baud2000000 = B2000000, + Baud2500000 = B2500000, + Baud3000000 = B3000000, + Baud3500000 = B3500000, + Baud4000000 = B4000000 + }; + /** Available character sizes */ - enum CharSize { + enum class CharSize : tcflag_t { CharSize5 = CS5, CharSize6 = CS6, CharSize7 = CS7, @@ -41,7 +76,7 @@ class SerialCom : public ICom { * @param flowControl Enable hardware flow control * @param charsize Size of a character */ - SerialCom(const std::string& port, speed_t baud = B19200, + SerialCom(const std::string& port, BaudRate baud = BaudRate::Baud19200, bool parityBit = false, bool twoStopBits = false, bool flowControl = false, CharSize charsize = CharSize::CharSize8); @@ -187,7 +222,7 @@ class SerialCom : public ICom { std::string m_port; /// Baud rate to use - speed_t m_baudrate = B19200; + BaudRate m_baudrate = BaudRate::Baud19200; /// Use parity bit bool m_parityBit = false; @@ -228,8 +263,9 @@ class SerialCom : public ICom { //! Temporary buffer for ::read() char m_tmpbuf[MAX_READ]; - //! Maps valid baud rate settings to `speed_t` type - static const std::unordered_map<std::string, speed_t> mapBAUDRATE; + //! Maps valid baud rate settings to `BaudRate` type + static const std::unordered_map<std::string, SerialCom::BaudRate> + mapBAUDRATE; //! Maps valid char size settings to `CharSize` type static const std::unordered_map<std::string, SerialCom::CharSize> diff --git a/src/libCom/TextSerialCom.cpp b/src/libCom/TextSerialCom.cpp index 69396132ddb2a4d64f72f605e259d54c2f618e05..df5af5e812ea52b7f14305009741211fba45e012 100644 --- a/src/libCom/TextSerialCom.cpp +++ b/src/libCom/TextSerialCom.cpp @@ -15,9 +15,9 @@ #include "ComRegistry.h" REGISTER_COM(TextSerialCom) -TextSerialCom::TextSerialCom(const std::string& port, speed_t baud, +TextSerialCom::TextSerialCom(const std::string& port, SerialCom::BaudRate baud, bool parityBit, bool twoStopBits, bool flowControl, - CharSize charsize) + SerialCom::CharSize charsize) : SerialCom(port, baud, parityBit, twoStopBits, flowControl, charsize) {} TextSerialCom::TextSerialCom() : SerialCom() {} diff --git a/src/libCom/TextSerialCom.h b/src/libCom/TextSerialCom.h index 986203ec77bdd7ce59c7f6187ed3c9c91d703cb8..1b4e9833b103987537a824b55ea717f642effb76 100644 --- a/src/libCom/TextSerialCom.h +++ b/src/libCom/TextSerialCom.h @@ -22,10 +22,12 @@ class TextSerialCom : public SerialCom { * @param flowControl Enable hardware flow control * @param charsize Size of a character */ - TextSerialCom(const std::string& port, speed_t baud = B19200, - bool parityBit = false, bool twoStopBits = false, - bool flowControl = false, - CharSize charsize = CharSize::CharSize8); + TextSerialCom( + const std::string& port, + SerialCom::BaudRate baud = SerialCom::BaudRate::Baud19200, + bool parityBit = false, bool twoStopBits = false, + bool flowControl = false, + SerialCom::CharSize charsize = SerialCom::CharSize::CharSize8); TextSerialCom(); ~TextSerialCom() = default; diff --git a/src/libCom/python.cpp b/src/libCom/python.cpp index 359195bbd60811d2c8e8523058054d10a0102f50..d71be8c9c9237889df9c5482497e35bd5f9a8a9c 100644 --- a/src/libCom/python.cpp +++ b/src/libCom/python.cpp @@ -149,6 +149,39 @@ void register_com(py::module &m) { py::class_<SerialCom, PyCom<SerialCom>, ICom, std::shared_ptr<SerialCom>> py_serialcom(m, "SerialCom"); // nb: enum defined first because it is used in py_serialcom init() default + py::enum_<SerialCom::BaudRate>(py_serialcom, "BaudRate") + .value("Baud0", SerialCom::BaudRate::Baud0) + .value("Baud50", SerialCom::BaudRate::Baud50) + .value("Baud75", SerialCom::BaudRate::Baud75) + .value("Baud110", SerialCom::BaudRate::Baud110) + .value("Baud134", SerialCom::BaudRate::Baud134) + .value("Baud150", SerialCom::BaudRate::Baud150) + .value("Baud200", SerialCom::BaudRate::Baud200) + .value("Baud300", SerialCom::BaudRate::Baud300) + .value("Baud600", SerialCom::BaudRate::Baud600) + .value("Baud1200", SerialCom::BaudRate::Baud1200) + .value("Baud1800", SerialCom::BaudRate::Baud1800) + .value("Baud2400", SerialCom::BaudRate::Baud2400) + .value("Baud4800", SerialCom::BaudRate::Baud4800) + .value("Baud9600", SerialCom::BaudRate::Baud9600) + .value("Baud19200", SerialCom::BaudRate::Baud19200) + .value("Baud38400", SerialCom::BaudRate::Baud38400) + .value("Baud57600", SerialCom::BaudRate::Baud57600) + .value("Baud115200", SerialCom::BaudRate::Baud115200) + .value("Baud230400", SerialCom::BaudRate::Baud230400) + .value("Baud460800", SerialCom::BaudRate::Baud460800) + .value("Baud500000", SerialCom::BaudRate::Baud500000) + .value("Baud576000", SerialCom::BaudRate::Baud576000) + .value("Baud921600", SerialCom::BaudRate::Baud921600) + .value("Baud1000000", SerialCom::BaudRate::Baud1000000) + .value("Baud1152000", SerialCom::BaudRate::Baud1152000) + .value("Baud1500000", SerialCom::BaudRate::Baud1500000) + .value("Baud2000000", SerialCom::BaudRate::Baud2000000) + .value("Baud2500000", SerialCom::BaudRate::Baud2500000) + .value("Baud3000000", SerialCom::BaudRate::Baud3000000) + .value("Baud3500000", SerialCom::BaudRate::Baud3500000) + .value("Baud4000000", SerialCom::BaudRate::Baud4000000); + py::enum_<SerialCom::CharSize>(py_serialcom, "CharSize") .value("CharSize5", SerialCom::CharSize::CharSize5) .value("CharSize6", SerialCom::CharSize::CharSize6) @@ -156,9 +189,9 @@ void register_com(py::module &m) { .value("CharSize8", SerialCom::CharSize::CharSize8); py_serialcom - .def(py::init<const std::string &, speed_t, bool, bool, bool, - SerialCom::CharSize>(), - py::arg("port"), py::arg("baud") = B19200, + .def(py::init<const std::string &, SerialCom::BaudRate, bool, bool, + bool, SerialCom::CharSize>(), + py::arg("port"), py::arg("baud") = SerialCom::BaudRate::Baud19200, py::arg("parityBit") = false, py::arg("twoStopBits") = false, py::arg("flowControl") = false, py::arg("charsize") = SerialCom::CharSize::CharSize8) @@ -167,9 +200,9 @@ void register_com(py::module &m) { py::class_<TextSerialCom, PyTextSerialCom, SerialCom, std::shared_ptr<TextSerialCom>>(m, "TextSerialCom") - .def(py::init<const std::string &, speed_t, bool, bool, bool, - SerialCom::CharSize>(), - py::arg("port"), py::arg("baud") = B19200, + .def(py::init<const std::string &, SerialCom::BaudRate, bool, bool, + bool, SerialCom::CharSize>(), + py::arg("port"), py::arg("baud") = SerialCom::BaudRate::Baud19200, py::arg("parityBit") = false, py::arg("twoStopBits") = false, py::arg("flowControl") = false, py::arg("charsize") = SerialCom::CharSize::CharSize8) @@ -178,9 +211,10 @@ void register_com(py::module &m) { py::class_<GPIBSerialCom, PyGPIBSerialCom, TextSerialCom, std::shared_ptr<GPIBSerialCom>>(m, "GPIBSerialCom") - .def(py::init<uint16_t, const std::string &, speed_t, bool, bool, bool, - SerialCom::CharSize>(), - py::arg("gpib_addr"), py::arg("port"), py::arg("baud") = B19200, + .def(py::init<uint16_t, const std::string &, SerialCom::BaudRate, bool, + bool, bool, SerialCom::CharSize>(), + py::arg("gpib_addr"), py::arg("port"), + py::arg("baud") = SerialCom::BaudRate::Baud19200, py::arg("parityBit") = false, py::arg("twoStopBits") = false, py::arg("flowControl") = false, py::arg("charsize") = SerialCom::CharSize::CharSize8); diff --git a/src/libLoad/TTILD400P.cpp b/src/libLoad/TTILD400P.cpp index 70c86a90524ffdd264a9e66f05f4e54325575920..022137f51faf66d95c6864d7903b7e5ddec91543 100644 --- a/src/libLoad/TTILD400P.cpp +++ b/src/libLoad/TTILD400P.cpp @@ -3,9 +3,10 @@ #include <algorithm> #include "Logger.h" +#include "SerialCom.h" TTILD400P::TTILD400P(std::string dev, unsigned addr) { - m_com = new SerialCom(dev, B115200); + m_com = new SerialCom(dev, SerialCom::BaudRate::Baud115200); m_addr = addr; m_com->send("++auto 0\n\r"); m_channel = 0; diff --git a/src/libLoad/TTILD400P.h b/src/libLoad/TTILD400P.h index c46e6237651cfa99535372f42165791de2f88441..5d6edbb4ed63794220b21027f13115e4288907ab 100644 --- a/src/libLoad/TTILD400P.h +++ b/src/libLoad/TTILD400P.h @@ -13,7 +13,7 @@ #include <thread> #include "GenericLoad.h" -#include "SerialCom.h" +class SerialCom; class TTILD400P : public GenericLoad { public: diff --git a/src/libMeter/Fluke8842.cpp b/src/libMeter/Fluke8842.cpp index 9144720455ee0090ff53ab84907ea146315757e9..a0e0aad7d50fe20a8f330e6a50d70da53fe2206d 100644 --- a/src/libMeter/Fluke8842.cpp +++ b/src/libMeter/Fluke8842.cpp @@ -1,9 +1,10 @@ #include "Fluke8842.h" #include "Logger.h" +#include "SerialCom.h" Fluke8842::Fluke8842(std::string dev, unsigned addr) { - m_com = new SerialCom(dev, B115200); + m_com = new SerialCom(dev, SerialCom::BaudRate::Baud115200); m_addr = addr; m_com->send("++auto 0\n\r"); } diff --git a/src/libMeter/Fluke8842.h b/src/libMeter/Fluke8842.h index f33998dd6f40c8964f3305d0d2e6e0fbca794b8e..fb0cdb9afc46b44036bf96339df084c4e5c25e53 100644 --- a/src/libMeter/Fluke8842.h +++ b/src/libMeter/Fluke8842.h @@ -13,7 +13,7 @@ #include <string> #include <thread> -#include "SerialCom.h" +class SerialCom; enum class FlukeMode { VOLTAGEDC, VOLTAGEAC, CURRENTDC, CURRENTAC }; diff --git a/src/libMeter/HP3478A.cpp b/src/libMeter/HP3478A.cpp index 60f08e87aad031b3508fab5b8e0a8cc0e3310394..8ab9639b9c115b701c6db92b00708ed97e4292b5 100644 --- a/src/libMeter/HP3478A.cpp +++ b/src/libMeter/HP3478A.cpp @@ -1,11 +1,12 @@ #include "HP3478A.h" #include "Logger.h" +#include "SerialCom.h" // Commands predate SCPI. See manual for more details. HP3478A::HP3478A(std::string dev, unsigned addr) { - m_com = new SerialCom(dev, B115200); + m_com = new SerialCom(dev, SerialCom::BaudRate::Baud115200); m_addr = addr; m_com->send("++auto 0\n\r"); } diff --git a/src/libMeter/HP3478A.h b/src/libMeter/HP3478A.h index 1f51b11f28420538e581bc447344c596d44741fe..06cddee008a6df0f10664917ce1ea761ddc944ed 100644 --- a/src/libMeter/HP3478A.h +++ b/src/libMeter/HP3478A.h @@ -14,7 +14,7 @@ #include <string> #include <thread> -#include "SerialCom.h" +class SerialCom; enum class HPMode { SETTING, diff --git a/src/libMeter/Keithley2000.cpp b/src/libMeter/Keithley2000.cpp index 65e4d9231d9a108bcb7fe3cdadd9cde04b2a2cc3..89eb5e6aa31db15affdf276869a62737cbd372be 100644 --- a/src/libMeter/Keithley2000.cpp +++ b/src/libMeter/Keithley2000.cpp @@ -1,9 +1,10 @@ #include "Keithley2000.h" #include "Logger.h" +#include "SerialCom.h" Keithley2000::Keithley2000(std::string dev, unsigned addr) { - m_com = new SerialCom(dev, B115200); + m_com = new SerialCom(dev, SerialCom::BaudRate::Baud115200); m_addr = addr; m_com->send("++auto 0\n\r"); } diff --git a/src/libMeter/Keithley2000.h b/src/libMeter/Keithley2000.h index a5d3bddfa83d7ac78fe08b129566e68c473cbcaa..ce3be327ff45d8fcf7ad75b2ffa5df959200c5dc 100644 --- a/src/libMeter/Keithley2000.h +++ b/src/libMeter/Keithley2000.h @@ -13,7 +13,8 @@ #include <string> #include <thread> -#include "SerialCom.h" +//#include "SerialCom.h" +class SerialCom; enum class KeithleyMode { VOLTAGE, CURRENT }; diff --git a/src/libScope/Tektronix654C.cpp b/src/libScope/Tektronix654C.cpp index 3b74159954df8fa54ab23510587f56df846e89bc..69aad17d8c792043383e3ef12fffa38484f75e17 100644 --- a/src/libScope/Tektronix654C.cpp +++ b/src/libScope/Tektronix654C.cpp @@ -11,9 +11,10 @@ #include <string> #include "Logger.h" +#include "SerialCom.h" Tektronix654C::Tektronix654C(std::string dev, unsigned addr) { - m_com = new SerialCom(dev, B9600); + m_com = new SerialCom(dev, SerialCom::BaudRate::Baud9600); m_addr = addr; m_com->send("++auto 0\n\r"); } diff --git a/src/libScope/Tektronix654C.h b/src/libScope/Tektronix654C.h index 724b42e8607af49bc27464b46f440b6ca0ec359e..eff151fad57e9af582076c1cb8dcd4f372a0259c 100644 --- a/src/libScope/Tektronix654C.h +++ b/src/libScope/Tektronix654C.h @@ -13,7 +13,7 @@ #include <string> #include <thread> -#include "SerialCom.h" +class SerialCom; class Tektronix654C { public: diff --git a/src/tools/arduino_eeprom.cpp b/src/tools/arduino_eeprom.cpp index ff9c0ada35209e93763c3540e457d94215ae21ce..276352368322359ad5fe8cdc962efc978e2edbde 100644 --- a/src/tools/arduino_eeprom.cpp +++ b/src/tools/arduino_eeprom.cpp @@ -103,7 +103,7 @@ int main(int argc, char* argv[]) { } std::shared_ptr<TextSerialCom> com = - std::make_shared<TextSerialCom>(device, B9600); + std::make_shared<TextSerialCom>(device, SerialCom::BaudRate::Baud9600); com->setTermination("\r\n"); com->setTimeout(20); com->init();