14 #ifndef CHARINTERFACE_H_
15 #define CHARINTERFACE_H_
17 #include "interface.h"
29 const std::vector<char> &
buffer()
const {
return *s_tlBuffer;}
31 int scanf(
const char *format, ...) const
32 #if defined __GNUC__ || defined __clang__
33 __attribute__ ((format(scanf,2,3)))
36 double toDouble()
const throw (XConvError &);
37 int toInt() const throw (XConvError &);
38 unsigned int toUInt() const throw (XConvError &);
40 XString toStrSimplified() const;
44 void sendf(const
char *format, ...) throw (XInterfaceError &)
45 #if defined __GNUC__ || defined __clang__
46 __attribute__ ((format(printf,2,3)))
51 void queryf(
const char *format, ...) throw (XInterfaceError &)
52 #if defined __GNUC__ || defined __clang__
53 __attribute__ ((format(printf,2,3)))
57 void setEOS(
const char *str);
58 const XString &eos()
const {
return m_eos;}
60 void query(
const XString &str)
throw (XCommError &);
61 virtual void query(
const char *str)
throw (XCommError &);
62 virtual void send(
const char *str)
throw (XCommError &) = 0;
63 virtual void receive() throw (XCommError &) = 0;
65 virtual
bool isOpened() const = 0;
68 static std::vector<
char> &buffer_receive() {
return *s_tlBuffer;}
70 virtual void open() throw (XInterfaceError &) = 0;
72 virtual
void close() throw (XInterfaceError &) = 0;
83 XCharInterface(
const char *name,
bool runtime,
const shared_ptr<XDriver> &driver);
86 void setGPIBUseSerialPollOnWrite(
bool x) {m_bGPIBUseSerialPollOnWrite = x;}
87 void setGPIBUseSerialPollOnRead(
bool x) {m_bGPIBUseSerialPollOnRead = x;}
88 void setGPIBWaitBeforeWrite(
int msec) {m_gpibWaitBeforeWrite = msec;}
89 void setGPIBWaitBeforeRead(
int msec) {m_gpibWaitBeforeRead = msec;}
90 void setGPIBWaitBeforeSPoll(
int msec) {m_gpibWaitBeforeSPoll = msec;}
91 void setGPIBMAVbit(
unsigned char x) {m_gpibMAVbit = x;}
93 bool gpibUseSerialPollOnWrite()
const {
return m_bGPIBUseSerialPollOnWrite;}
94 bool gpibUseSerialPollOnRead()
const {
return m_bGPIBUseSerialPollOnRead;}
95 int gpibWaitBeforeWrite()
const {
return m_gpibWaitBeforeWrite;}
96 int gpibWaitBeforeRead()
const {
return m_gpibWaitBeforeRead;}
97 int gpibWaitBeforeSPoll()
const {
return m_gpibWaitBeforeSPoll;}
98 unsigned char gpibMAVbit()
const {
return m_gpibMAVbit;}
102 void setSerialStopBits(
unsigned int bits) {m_serialStopBits = bits;}
103 enum {PARITY_NONE = 0, PARITY_ODD = 1, PARITY_EVEN = 2};
104 void setSerialParity(
unsigned int parity) {m_serialParity = parity;}
105 void setSerial7Bits(
bool enable) {m_serial7Bits = enable;}
106 void setSerialFlushBeforeWrite(
bool x) {m_serialFlushBeforeWrite = x;}
108 void setSerialHasEchoBack(
bool x) {m_serialHasEchoBack = x;}
110 unsigned int serialBaudRate()
const {
return m_serialBaudRate;}
111 unsigned int serialStopBits()
const {
return m_serialStopBits;}
112 unsigned int serialParity()
const {
return m_serialParity;}
113 bool serial7Bits()
const {
return m_serial7Bits;}
114 bool serialFlushBeforeWrite()
const {
return m_serialFlushBeforeWrite;}
115 const XString &serialEOS()
const {
return m_serialEOS;}
116 bool serialHasEchoBack()
const {
return m_serialHasEchoBack;}
118 virtual void send(
const XString &str)
throw (XCommError &);
119 virtual void send(
const char *str)
throw (XCommError &);
120 virtual void write(
const char *sendbuf,
int size)
throw (XCommError &);
121 virtual void receive() throw (XCommError &);
122 virtual
void receive(
unsigned int length) throw (XCommError &);
123 virtual
bool isOpened()
const {
return !!m_xport;}
125 virtual void open() throw (XInterfaceError &);
127 virtual
void close() throw (XInterfaceError &);
129 shared_ptr<XPort> openedPort()
const {
return m_xport;}
132 bool m_bGPIBUseSerialPollOnWrite;
133 bool m_bGPIBUseSerialPollOnRead;
134 int m_gpibWaitBeforeWrite;
135 int m_gpibWaitBeforeRead;
136 int m_gpibWaitBeforeSPoll;
137 unsigned char m_gpibMAVbit;
140 unsigned int m_serialStopBits;
141 unsigned int m_serialParity;
143 bool m_serialFlushBeforeWrite;
144 bool m_serialHasEchoBack;
146 shared_ptr<XPort> m_xport;
150 shared_ptr<XStringNode> m_script_query;
151 shared_ptr<XListener> m_lsnOnSendRequested;
152 shared_ptr<XListener> m_lsnOnQueryRequested;
160 virtual ~XPort() =
default;
169 const XString &portString()
const {
return m_portString;}
170 const XString &eos()
const {
return m_eos;}
171 void setEOS(
const char *str) {m_eos = str;}