123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #ifndef SERIAL_H
- #define SERIAL_H
- #include <fcntl.h>
- #include <termio.h>
- #include <unistd.h>
- namespace CommunicationStuff {
- enum Status {
- OK = 0,
- DEV_NOT_FOUND = -1,
- BAUD_NOT_SUPPORT = -2,
- DATABITS_NOT_SUPPORT = -3,
- CONFIG_FAIL = -4,
- PARITYMODE_NOT_SUPPORT = -5,
- STOPBITS_NOT_SUPPORT = -6,
- };
- enum ParityMode {
- PARITY_NONE = 0,
- PARITY_ODD = 1,
- PARITY_EVEN = 2,
- };
- enum StopBits {
- ONE = 1,
- TWO = 2,
- };
- class Serial
- {
- public:
- Serial(const char* device);
- ~Serial();
- // Status open(const char* dev);
- Status setup(const int baud_speed, const int data_bits,
- const int parity_mode, const int stop_bits);
- Status change_baud(const int baud_speed);
- // Status close();
- int write(const unsigned char* buffer, int length);
- int read(unsigned char* buffer, int length);
- private:
- int fd_;
- struct termios options_;
- };
- } // namespace CommunicationStuff
- #endif
|