The Serial class manages connection with serial devices including Bluetooth. Serial communication is still the predominat method to communicate with astronomical devices such as mounts, focusers, filter wheels..etc. The default connection parameters are 9600 8N1 (9600 Baud Rate, 8 data bits, no parity, 1 stop bit). All the parameters can be updated and read via the getters and setters of the class. The default port is /dev/ttyUSB0 under Linux and /dev/cu.usbserial under MacOS. After serial connection is established successfully,.
More...
#include <connectionserial.h>
|
| enum | BaudRate {
B_1200
, B_2400
, B_4800
, B_9600
,
B_19200
, B_38400
, B_57600
, B_115200
,
B_230400
, B_COUNT
} |
| | Supported baud rates. More...
|
| |
| enum | Type {
CONNECTION_NONE = 1 << 0
, CONNECTION_SERIAL = 1 << 1
, CONNECTION_TCP = 1 << 2
, CONNECTION_USB = 1 << 3
,
CONNECTION_I2C = 1 << 4
, CONNECTION_CUSTOM = 1 << 15
} |
| |
|
| | Serial (INDI::DefaultDevice *dev, IPerm permission=IP_RW) |
| |
| virtual | ~Serial () |
| |
| virtual bool | Connect () override |
| | Connect Connect to device via the implemented communication medium. Do not perform any handshakes.
|
| |
| virtual bool | Disconnect () override |
| | Disconnect Disconnect from device.
|
| |
| virtual void | Activated () override |
| | Activated Function called by the framework when the plugin is activated (i.e. selected by the user). It is usually used to define properties pertaining to the specific plugin functionalities.
|
| |
| virtual void | Deactivated () override |
| | Deactivated Function called by the framework when the plugin is deactivated. It is usually used to delete properties by were defined previously since the plugin is no longer active.
|
| |
| virtual std::string | name () override |
| |
| virtual std::string | label () override |
| |
| virtual const char * | port () |
| |
| virtual uint32_t | baud () |
| |
| void | setDefaultPort (const char *port) |
| | setDefaultPort Set default port. Call this function in initProperties() of your driver if you want to change default port.
|
| |
| void | setDefaultBaudRate (BaudRate newRate) |
| | setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by this function. Call this function in initProperties() of your driver.
|
| |
| void | setPortMatchPattern (const std::string &pattern) |
| | setPortMatchPattern Set a regex pattern used to automatically select a serial port from the discovered system ports. When the system ports are scanned, if any port path matches this pattern AND the previously-saved config port is no longer available (neither detected among the system ports nor still present on disk), the first matching port is automatically selected as the active port.
|
| |
| int | getPortFD () const |
| |
| virtual bool | ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n) override |
| |
| virtual bool | ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n) override |
| |
| virtual bool | saveConfigItems (FILE *fp) override |
| |
| bool | Refresh (bool silent=false) |
| |
| uint8_t | getWordSize () const |
| |
| void | setWordSize (const uint8_t &value) |
| | setWordSize Set word size to be used in the serial connection. Default 8
|
| |
| uint8_t | getParity () const |
| |
| void | setParity (const uint8_t &value) |
| | setParity Set parity to be used in the serial connection. Default 0 (NONE)
|
| |
| uint8_t | getStopBits () const |
| |
| void | setStopBits (const uint8_t &value) |
| | setStopBits Set stop bits to be used in the serial connection. Default 0
|
| |
| virtual Type | type () |
| | type Return connection type
|
| |
| virtual bool | ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n) |
| |
| virtual bool | ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) |
| |
| void | registerHandshake (std::function< bool()> callback) |
| | registerHandshake Register a handshake function to be called once the initial connection to the device is established.
|
| |
The Serial class manages connection with serial devices including Bluetooth. Serial communication is still the predominat method to communicate with astronomical devices such as mounts, focusers, filter wheels..etc. The default connection parameters are 9600 8N1 (9600 Baud Rate, 8 data bits, no parity, 1 stop bit). All the parameters can be updated and read via the getters and setters of the class. The default port is /dev/ttyUSB0 under Linux and /dev/cu.usbserial under MacOS. After serial connection is established successfully,.
Definition at line 41 of file connectionserial.h.
◆ anonymous enum
◆ BaudRate
Supported baud rates.
- Note
- : Default baud rate is 9600. To change default baud rate, use setDefaultBaudrate(..) function.
| Enumerator |
|---|
| B_1200 | |
| B_2400 | |
| B_4800 | |
| B_9600 | |
| B_19200 | |
| B_38400 | |
| B_57600 | |
| B_115200 | |
| B_230400 | |
| B_COUNT | |
Definition at line 49 of file connectionserial.h.
◆ Serial()
◆ ~Serial()
| Connection::Serial::~Serial |
( |
| ) |
|
|
virtualdefault |
◆ Activated()
| void Connection::Serial::Activated |
( |
| ) |
|
|
overridevirtual |
Activated Function called by the framework when the plugin is activated (i.e. selected by the user). It is usually used to define properties pertaining to the specific plugin functionalities.
Implements Connection::Interface.
Definition at line 335 of file connectionserial.cpp.
◆ baud()
| uint32_t Connection::Serial::baud |
( |
| ) |
|
|
virtual |
- Returns
- Currently active baud rate raw value (e.g. 9600, 19200..etc)
Definition at line 403 of file connectionserial.cpp.
◆ Connect() [1/2]
| bool Connection::Serial::Connect |
( |
| ) |
|
|
overridevirtual |
Connect Connect to device via the implemented communication medium. Do not perform any handshakes.
- Returns
- True if successful, false otherwise.
Implements Connection::Interface.
Definition at line 186 of file connectionserial.cpp.
◆ Connect() [2/2]
| bool Connection::Serial::Connect |
( |
const char * |
port, |
|
|
uint32_t |
baud |
|
) |
| |
|
protectedvirtual |
Connect to serial port device. Default parameters are 8 bits, 1 stop bit, no parity. Override if different from default.
- Parameters
-
| port | Port to connect to. |
| baud | Baud rate |
- Returns
- True if connection is successful, false otherwise
- Warning
- Do not call this function directly, it is called by Connection::Serial Connect() function.
Definition at line 297 of file connectionserial.cpp.
◆ Deactivated()
| void Connection::Serial::Deactivated |
( |
| ) |
|
|
overridevirtual |
Deactivated Function called by the framework when the plugin is deactivated. It is usually used to delete properties by were defined previously since the plugin is no longer active.
Implements Connection::Interface.
Definition at line 348 of file connectionserial.cpp.
◆ Disconnect()
| bool Connection::Serial::Disconnect |
( |
| ) |
|
|
overridevirtual |
◆ getParity()
| uint8_t Connection::Serial::getParity |
( |
| ) |
const |
|
inline |
◆ getPortFD()
| int Connection::Serial::getPortFD |
( |
| ) |
const |
|
inline |
- Returns
- Return port file descriptor. If connection is successful, PortFD is a positive integer otherwise it is set to -1
Definition at line 121 of file connectionserial.h.
◆ getStopBits()
| uint8_t Connection::Serial::getStopBits |
( |
| ) |
const |
|
inline |
◆ getWordSize()
| uint8_t Connection::Serial::getWordSize |
( |
| ) |
const |
|
inline |
◆ ISNewSwitch()
| bool Connection::Serial::ISNewSwitch |
( |
const char * |
dev, |
|
|
const char * |
name, |
|
|
ISState * |
states, |
|
|
char * |
names[], |
|
|
int |
n |
|
) |
| |
|
overridevirtual |
◆ ISNewText()
| bool Connection::Serial::ISNewText |
( |
const char * |
dev, |
|
|
const char * |
name, |
|
|
char * |
texts[], |
|
|
char * |
names[], |
|
|
int |
n |
|
) |
| |
|
overridevirtual |
◆ label()
| virtual std::string Connection::Serial::label |
( |
| ) |
|
|
inlineoverridevirtual |
◆ name()
| virtual std::string Connection::Serial::name |
( |
| ) |
|
|
inlineoverridevirtual |
◆ port()
| virtual const char * Connection::Serial::port |
( |
| ) |
|
|
inlinevirtual |
◆ processHandshake()
| bool Connection::Serial::processHandshake |
( |
| ) |
|
|
protectedvirtual |
◆ Refresh()
| bool Connection::Serial::Refresh |
( |
bool |
silent = false | ) |
|
◆ saveConfigItems()
| bool Connection::Serial::saveConfigItems |
( |
FILE * |
fp | ) |
|
|
overridevirtual |
◆ setDefaultBaudRate()
| void Connection::Serial::setDefaultBaudRate |
( |
BaudRate |
newRate | ) |
|
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by this function. Call this function in initProperties() of your driver.
- Parameters
-
Definition at line 385 of file connectionserial.cpp.
◆ setDefaultPort()
| void Connection::Serial::setDefaultPort |
( |
const char * |
port | ) |
|
setDefaultPort Set default port. Call this function in initProperties() of your driver if you want to change default port.
- Parameters
-
| port | Name of desired default port |
Definition at line 376 of file connectionserial.cpp.
◆ setParity()
| void Connection::Serial::setParity |
( |
const uint8_t & |
value | ) |
|
|
inline |
setParity Set parity to be used in the serial connection. Default 0 (NONE)
- Parameters
-
| value | 0 for NONE, 1 for EVEN, 2 for ODD |
Definition at line 155 of file connectionserial.h.
◆ setPortMatchPattern()
| void Connection::Serial::setPortMatchPattern |
( |
const std::string & |
pattern | ) |
|
setPortMatchPattern Set a regex pattern used to automatically select a serial port from the discovered system ports. When the system ports are scanned, if any port path matches this pattern AND the previously-saved config port is no longer available (neither detected among the system ports nor still present on disk), the first matching port is automatically selected as the active port.
This is particularly useful for devices whose USB serial paths embed the device name (e.g. Pegasus Astro devices under /dev/serial/by-id/), allowing the correct port to be selected without blind handshake attempts against every port.
Call this function in initProperties() of your driver. The matching is case-insensitive. If the pattern is empty (the default), no auto-selection is performed.
- Parameters
-
| pattern | Case-insensitive regex pattern (e.g. "FocusCube", "FlatMaster", "Falcon") |
Definition at line 398 of file connectionserial.cpp.
◆ setStopBits()
| void Connection::Serial::setStopBits |
( |
const uint8_t & |
value | ) |
|
|
inline |
setStopBits Set stop bits to be used in the serial connection. Default 0
Definition at line 167 of file connectionserial.h.
◆ setWordSize()
| void Connection::Serial::setWordSize |
( |
const uint8_t & |
value | ) |
|
|
inline |
setWordSize Set word size to be used in the serial connection. Default 8
Definition at line 142 of file connectionserial.h.
◆ AutoSearchSP
◆ BaudRateSP
◆ m_ConfigBaudRate
| int Connection::Serial::m_ConfigBaudRate {-1} |
|
protected |
◆ m_ConfigPort
| std::string Connection::Serial::m_ConfigPort |
|
protected |
◆ m_Permission
◆ m_PortMatchPattern
| std::string Connection::Serial::m_PortMatchPattern |
|
protected |
◆ m_SystemPorts
| std::vector<std::string> Connection::Serial::m_SystemPorts |
|
protected |
◆ parity
| uint8_t Connection::Serial::parity = 0 |
|
protected |
◆ PortFD
| int Connection::Serial::PortFD = -1 |
|
protected |
◆ PortTP
◆ RefreshSP
◆ stopBits
| uint8_t Connection::Serial::stopBits = 1 |
|
protected |
◆ SystemPortSP
◆ wordSize
| uint8_t Connection::Serial::wordSize = 8 |
|
protected |
The documentation for this class was generated from the following files: