doc, small fixes

This commit is contained in:
2022-05-08 19:23:52 +03:00
parent 460519c075
commit 3107949e6f
24 changed files with 1061 additions and 406 deletions

View File

@@ -29,42 +29,52 @@
#include "pitimer.h"
#include "piiodevice.h"
//! \ingroup IO
//! \~\brief
//! \~english Serial device.
//! \~russian Последовательный порт.
class PIP_EXPORT PISerial: public PIIODevice
{
PIIODEVICE(PISerial, "ser")
public:
//! Contructs an empty %PISerial
//! \~english Contructs an empty %PISerial
//! \~russian Создает пустой %PISerial
explicit PISerial();
//! \brief Parameters of PISerial
virtual ~PISerial();
//! \~english Parameters of PISerial
//! \~russian Параметры PISerial
enum Parameters {
ParityControl /*! Enable parity check and generate */ = 0x1,
ParityOdd /*! Parity is odd instead of even */ = 0x2,
TwoStopBits /*! Two stop bits instead of one */ = 0x4
ParityControl /*! \~english Enable parity check and generate \~russian Включить генерацию и проверку контроля чётности */ = 0x1,
ParityOdd /*! \~english Parity is odd instead of even \~russian Нечётный контроль чётности вместо чётного */ = 0x2,
TwoStopBits /*! \~english Two stop bits instead of one \~russian Два стоповых бита вместо одного */ = 0x4
};
//! \brief Speed of PISerial
//! \~english Speed of PISerial
//! \~russian Скорость PISerial
enum Speed {
S50 /*! 50 baud */ = 50,
S75 /*! 75 baud */ = 75,
S110 /*! 110 baud */ = 110,
S300 /*! 300 baud */ = 300,
S600 /*! 600 baud */ = 600,
S1200 /*! 1200 baud */ = 1200,
S2400 /*! 2400 baud */ = 2400,
S4800 /*! 4800 baud */ = 4800,
S9600 /*! 9600 baud */ = 9600,
S14400 /*! 14400 baud */ = 14400,
S19200 /*! 19200 baud */ = 19200,
S38400 /*! 38400 baud */ = 38400,
S57600 /*! 57600 baud */ = 57600,
S115200 /*! 115200 baud */ = 115200,
S230400 /*! 230400 baud */ = 230400,
S460800 /*! 460800 baud */ = 460800,
S500000 /*! 500000 baud */ = 500000,
S576000 /*! 576000 baud */ = 576000,
S921600 /*! 921600 baud */ = 921600,
S50 /*! 50 baud */ = 50,
S75 /*! 75 baud */ = 75,
S110 /*! 110 baud */ = 110,
S300 /*! 300 baud */ = 300,
S600 /*! 600 baud */ = 600,
S1200 /*! 1200 baud */ = 1200,
S2400 /*! 2400 baud */ = 2400,
S4800 /*! 4800 baud */ = 4800,
S9600 /*! 9600 baud */ = 9600,
S14400 /*! 14400 baud */ = 14400,
S19200 /*! 19200 baud */ = 19200,
S38400 /*! 38400 baud */ = 38400,
S57600 /*! 57600 baud */ = 57600,
S115200 /*! 115200 baud */ = 115200,
S230400 /*! 230400 baud */ = 230400,
S460800 /*! 460800 baud */ = 460800,
S500000 /*! 500000 baud */ = 500000,
S576000 /*! 576000 baud */ = 576000,
S921600 /*! 921600 baud */ = 921600,
S1000000 /*! 1000000 baud */ = 1000000,
S1152000 /*! 1152000 baud */ = 1152000,
S1500000 /*! 1500000 baud */ = 1500000,
@@ -75,72 +85,93 @@ public:
S4000000 /*! 4000000 baud */ = 4000000
};
//! \brief Information about serial device
//! \ingroup IO
//! \~\brief
//! \~english Information about serial device
//! \~russian Информация о последовательном устройстве
struct PIP_EXPORT DeviceInfo {
DeviceInfo();
//! \brief String representation of USB ID in format \"xxxx:xxxx\"
//! \~english Returns string representation of USB ID in format "xxxx:xxxx" (vID:pID)
//! \~russian Возвращает строковое представление USB ID в формате "xxxx:xxxx" (vID:pID)
PIString id() const;
//! \brief USB Vendor ID
//! \~english USB Vendor ID
//! \~russian USB Vendor ID
uint vID;
//! \brief USB Product ID
//! \~english USB Product ID
//! \~russian USB Product ID
uint pID;
//! \brief Path to device, e.g. "COM2" or "/dev/ttyUSB0"
//! \~english Path to device, e.g. "COM2" or "/dev/ttyUSB0"
//! \~russian Путь к устройству, например "COM2" или "/dev/ttyUSB0"
PIString path;
//! \brief Device description
//! \~english Device description
//! \~russian Описание устройства
PIString description;
//! \brief Device manufacturer
//! \~english Device manufacturer
//! \~russian Описание производителя
PIString manufacturer;
};
//! Contructs %PISerial with device name "device", speed "speed" and parameters "params"
//! \~english Contructs %PISerial with device name "device", speed "speed" and parameters "params"
//! \~russian Создает %PISerial с именем устройства "device", скоростью "speed" и параметрами "params"
explicit PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags<PISerial::Parameters> params = 0);
virtual ~PISerial();
//! Set both input and output speed to "speed"
//! \~english Set both input and output speed to "speed"
//! \~russian Устанавливает скорости приема и передачи в "speed"
void setSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); setProperty("inSpeed", (int)speed); applySettings();}
//! Set output speed to "speed"
//! \~english Set output speed to "speed"
//! \~russian Устанавливает скорость передачи в "speed"
void setOutSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); applySettings();}
//! Set input speed to "speed"
//! \~english Set input speed to "speed"
//! \~russian Устанавливает скорость приема в "speed"
void setInSpeed(PISerial::Speed speed) {setProperty("inSpeed", (int)speed); applySettings();}
//! Set device name to "dev"
//! \~english Set device name to "dev"
//! \~russian Устанавливает имя устройства в "dev"
void setDevice(const PIString & dev) {setPath(dev); if (isOpened()) {close(); open();};}
//! Set parameters to "parameters_"
//! \~english Set parameters to "parameters_"
//! \~russian Устанавливает параметры в "parameters_"
void setParameters(PIFlags<PISerial::Parameters> parameters_) {setProperty("parameters", (int)parameters_); applySettings();}
//! Set parameter "parameter" to "on" state
//! \~english Set parameter "parameter" to "on" state
//! \~russian Устанавливает параметр "parameter" в "on"
void setParameter(PISerial::Parameters parameter, bool on = true);
//! Returns if parameter "parameter" is set
//! \~english Returns if parameter "parameter" is set
//! \~russian Возвращает установлен ли параметр "parameter"
bool isParameterSet(PISerial::Parameters parameter) const;
//! Returns parameters
//! \~english Returns parameters
//! \~russian Возвращает параметры
PIFlags<PISerial::Parameters> parameters() const {return (PIFlags<Parameters>)(property("parameters").toInt());}
//! Set data bits count. Valid range is from 5 to 8, befault is 8
//! \~english Set data bits count. Valid range is from 5 to 8, befault is 8
//! \~russian Устанавливает количество бит данных. Разрешены значения от 5 до 8, по умолчанию 8
void setDataBitsCount(int bits) {setProperty("dataBitsCount", bits); applySettings();}
//! Returns data bits count
//! \~english Returns data bits count
//! \~russian Возвращает количество бит данных
int dataBitsCount() const {return property("dataBitsCount").toInt();}
//! Set pin number "number" to logic level "on". Valid numbers are 4 (DTR) and 7 (RTS)
//! \~english Set pin number "number" to logic level "on". Valid numbers are 4 (DTR) and 7 (RTS)
//! \~russian Устанавливает пин с номером "number" в логический уровень "on". Разрешены номера 4 (DTR) и 7 (RTS)
bool setPin(int number, bool on);
//! Returns pin number "number" logic level. Valid numbers range is from 1 to 9
//! \~english Returns pin number "number" logic level. Valid numbers range is from 1 to 9
//! \~russian Возвращает логический уровень пина с номером "number". Разрешены номера от 1 до 9
bool isPin(int number) const;
bool setLE(bool on); // useless function, just formally
@@ -163,69 +194,89 @@ public:
bool isRNG() const;
bool isDSR() const;
//! Switch transmission line in break if enabled.
//! i.e. sends a continuous stream of zero bits.
//! If successful, returns true; otherwise returns false.
//! The serial port has to be open before trying to send a break duration; otherwise returns false
//! \~english Switch transmission line in break
//! \~russian Переключает состояние передачи в break
bool setBreak(bool enabled);
void setVTime(int t) {vtime = t; applySettings();}
//! Returns device name
//! \~english Returns device name
//! \~russian Возвращает имя устройства
PIString device() const {return path();}
//! Returns output speed
//! \~english Returns output speed
//! \~russian Возвращает скорость передачи
PISerial::Speed outSpeed() const {return (PISerial::Speed)(property("outSpeed").toInt());}
//! Returns input speed
//! \~english Returns input speed
//! \~russian Возвращает скорость приема
PISerial::Speed inSpeed() const {return (PISerial::Speed)(property("inSpeed").toInt());}
int VTime() const {return vtime;}
//! Discard all buffered input and output data
//! \~english Discard all buffered input and output data
//! \~russian Откидывает все буферизированные данные для передачи и приема
void flush();
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
//! \~english Read from device no more "max_size" bytes into "read_to" with "timeout_ms" timeout
//! \~russian Читает из устройства не более "max_size" байт в "read_to" с таймаутом "timeout_ms"
bool read(void * read_to, int max_size, double timeout_ms);
PIString read(int size = -1, double timeout_ms = 1000.);
//! \~english Read from device for "timeout_ms" timeout or for "size" bytes
//! \~russian Читает из устройства в течении таймаута "timeout_ms" или до "size" байт
PIString readString(int size = -1, double timeout_ms = 1000.);
//! \~english Read from device for "timeout_ms" timeout or for "size" bytes
//! \~russian Читает из устройства в течении таймаута "timeout_ms" или до "size" байт
PIByteArray readData(int size = -1, double timeout_ms = 1000.);
//! \brief Write to device data "data" with maximum size "size" and wait for data written if "wait" is \b true.
//! \returns \b true if sended bytes count = "size"
//! \~english Write to device data "data" with maximum size "size". Returns if sended bytes count = "size"
//! \~russian Пишет в порт не более "size" байт данных "data". Возвращает если количество записанных байт = "size"
bool send(const void * data, int size);
//! \brief Write to device byte array "data"
//! \returns \b true if sended bytes count = size of string
//! \~english Write to device byte array "data". Returns if sended bytes count = size of "data"
//! \~russian Пишет в порт байтовый массив "data". Возвращает если количество записанных байт = размер "data"
bool send(const PIByteArray & data) {return send(data.data(), data.size_s());}
//! \brief Returns all available speeds for serial devices
//! \~english Returns all available speeds for serial devices
//! \~russian Возвращает все возможные скорости для устройств
static PIVector<int> availableSpeeds();
//! \brief Returns all available system devices path. If "test" each device will be tried to open
//! \~english Returns all available system devices path. If "test" each device will be tried to open
//! \~russian Возвращает пути всех доступных устройств в системе. Если "test", то каждое устройство будет опробовано на открытие
static PIStringList availableDevices(bool test = false);
//! \brief Returns all available system devices. If "test" each device will be tried to open
//! \~english Returns all available system devices. If "test" each device will be tried to open
//! \~russian Возвращает все доступные устройства в системе. Если "test", то каждое устройство будет опробовано на открытие
static PIVector<DeviceInfo> availableDevicesInfo(bool test = false);
//! \ioparams
//! \{
#ifdef DOXYGEN
//! \brief device, default ""
//! \~english device, default ""
//! \~russian устройство, по умолчанию ""
string device;
//! \brief input/output speed, default 115200
//! \~english input/output speed, default 115200
//! \~russian скорость чтения/записи, по умолчанию 115200
int speed;
//! \brief dataBitsCount, default 8
//! \~english dataBitsCount, default 8
//! \~russian количесво бит данных, по умолчанию 8
int dataBitsCount;
//! \brief parityControl, default false
//! \~english parityControl, default false
//! \~russian контроль четности, по умолчанию false
bool parityControl;
//! \brief parityOdd, default false
//! \~english parityOdd, default false
//! \~russian нечётный контроль четности, по умолчанию false
bool parityOdd;
//! \brief twoStopBits, default false
//! \~english twoStopBits, default false
//! \~russian два стоповых бита, по умолчанию false
bool twoStopBits;
#endif
//! \}
@@ -238,6 +289,9 @@ protected:
bool configureDevice(const void * e_main, const void * e_parent = 0);
void optionsChanged();
void threadedReadBufferSizeChanged();
//! \~english Basic read function
//! \~russian Базовое чтение
int readDevice(void * read_to, int max_size);
int writeDevice(const void * data, int max_size);
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Sequential;}
@@ -263,14 +317,30 @@ protected:
};
//! \relatesalso PICout
//! \~english Output operator to \a PICout
//! \~russian Оператор вывода в \a PICout
inline PICout operator <<(PICout s, const PISerial::DeviceInfo & v) {
s << v.path << " (" << v.id() << ", \"" << v.manufacturer << "\", \"" << v.description << "\")";
return s;
}
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator ==(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {return v0.path == v1.path;}
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator !=(const PISerial::DeviceInfo & v0, const PISerial::DeviceInfo & v1) {return v0.path != v1.path;}
//! \relatesalso PIByteArray
//! \~english Store operator
//! \~russian Оператор сохранения
inline PIByteArray & operator <<(PIByteArray & s, const PISerial::DeviceInfo & v) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
//! \relatesalso PIByteArray
//! \~english Restore operator
//! \~russian Оператор извлечения
inline PIByteArray & operator >>(PIByteArray & s, PISerial::DeviceInfo & v) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}