Instrument Neutral Distributed Interface INDI 2.2.5
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
Connection::Serial Class Reference

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>

Inheritance diagram for Connection::Serial:
Connection::Interface

Public Types

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...
 
- Public Types inherited from Connection::Interface
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
}
 

Public Member Functions

 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
 
- Public Member Functions inherited from Connection::Interface
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.
 

Protected Types

enum  { SERIAL_DEV , USB_ID_DEV , BLUETOOTH_DEV }
 

Protected Member Functions

virtual bool Connect (const char *port, uint32_t baud)
 Connect to serial port device. Default parameters are 8 bits, 1 stop bit, no parity. Override if different from default.
 
virtual bool processHandshake ()
 
- Protected Member Functions inherited from Connection::Interface
 Interface (INDI::DefaultDevice *dev, Type type=CONNECTION_NONE)
 
virtual ~Interface ()
 
const char * getDeviceName ()
 

Protected Attributes

INDI::PropertyText PortTP {1}
 
INDI::PropertySwitch BaudRateSP {B_COUNT}
 
INDI::PropertySwitch AutoSearchSP {2}
 
INDI::PropertySwitch SystemPortSP {0}
 
INDI::PropertySwitch RefreshSP {1}
 
int PortFD = -1
 
uint8_t wordSize = 8
 
uint8_t parity = 0
 
uint8_t stopBits = 1
 
IPerm m_Permission = IP_RW
 
std::string m_ConfigPort
 
int m_ConfigBaudRate {-1}
 
std::vector< std::string > m_SystemPorts
 
std::string m_PortMatchPattern
 
- Protected Attributes inherited from Connection::Interface
std::function< bool()> Handshake
 
INDI::DefaultDevice * m_Device { nullptr }
 
Type m_Type { CONNECTION_NONE }
 

Detailed Description

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.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
SERIAL_DEV 
USB_ID_DEV 
BLUETOOTH_DEV 

Definition at line 185 of file connectionserial.h.

◆ 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.

Constructor & Destructor Documentation

◆ Serial()

Connection::Serial::Serial ( INDI::DefaultDevice *  dev,
IPerm  permission = IP_RW 
)

Definition at line 38 of file connectionserial.cpp.

◆ ~Serial()

Connection::Serial::~Serial ( )
virtualdefault

Member Function Documentation

◆ 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
portPort to connect to.
baudBaud 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

Disconnect Disconnect from device.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

Definition at line 325 of file connectionserial.cpp.

◆ getParity()

uint8_t Connection::Serial::getParity ( ) const
inline

Definition at line 147 of file connectionserial.h.

◆ 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

Definition at line 160 of file connectionserial.h.

◆ getWordSize()

uint8_t Connection::Serial::getWordSize ( ) const
inline

Definition at line 135 of file connectionserial.h.

◆ ISNewSwitch()

bool Connection::Serial::ISNewSwitch ( const char *  dev,
const char *  name,
ISState *  states,
char *  names[],
int  n 
)
overridevirtual

Reimplemented from Connection::Interface.

Definition at line 124 of file connectionserial.cpp.

◆ ISNewText()

bool Connection::Serial::ISNewText ( const char *  dev,
const char *  name,
char *  texts[],
char *  names[],
int  n 
)
overridevirtual

Reimplemented from Connection::Interface.

Definition at line 95 of file connectionserial.cpp.

◆ label()

virtual std::string Connection::Serial::label ( )
inlineoverridevirtual
Returns
Plugin friendly label presented to the client/user.

Implements Connection::Interface.

Definition at line 67 of file connectionserial.h.

◆ name()

virtual std::string Connection::Serial::name ( )
inlineoverridevirtual
Returns
Plugin name

Implements Connection::Interface.

Definition at line 62 of file connectionserial.h.

◆ port()

virtual const char * Connection::Serial::port ( )
inlinevirtual
Returns
Currently active device port

Definition at line 75 of file connectionserial.h.

◆ processHandshake()

bool Connection::Serial::processHandshake ( )
protectedvirtual

Definition at line 276 of file connectionserial.cpp.

◆ Refresh()

bool Connection::Serial::Refresh ( bool  silent = false)

Refresh the list of system ports

Definition at line 458 of file connectionserial.cpp.

◆ saveConfigItems()

bool Connection::Serial::saveConfigItems ( FILE *  fp)
overridevirtual

Reimplemented from Connection::Interface.

Definition at line 364 of file connectionserial.cpp.

◆ 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
newRateDesired new rate

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
portName 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
value0 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
patternCase-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.

Member Data Documentation

◆ AutoSearchSP

INDI::PropertySwitch Connection::Serial::AutoSearchSP {2}
protected

Definition at line 197 of file connectionserial.h.

◆ BaudRateSP

INDI::PropertySwitch Connection::Serial::BaudRateSP {B_COUNT}
protected

Definition at line 195 of file connectionserial.h.

◆ m_ConfigBaudRate

int Connection::Serial::m_ConfigBaudRate {-1}
protected

Definition at line 214 of file connectionserial.h.

◆ m_ConfigPort

std::string Connection::Serial::m_ConfigPort
protected

Definition at line 213 of file connectionserial.h.

◆ m_Permission

IPerm Connection::Serial::m_Permission = IP_RW
protected

Definition at line 211 of file connectionserial.h.

◆ m_PortMatchPattern

std::string Connection::Serial::m_PortMatchPattern
protected

Definition at line 217 of file connectionserial.h.

◆ m_SystemPorts

std::vector<std::string> Connection::Serial::m_SystemPorts
protected

Definition at line 215 of file connectionserial.h.

◆ parity

uint8_t Connection::Serial::parity = 0
protected

Definition at line 208 of file connectionserial.h.

◆ PortFD

int Connection::Serial::PortFD = -1
protected

Definition at line 204 of file connectionserial.h.

◆ PortTP

INDI::PropertyText Connection::Serial::PortTP {1}
protected

Definition at line 193 of file connectionserial.h.

◆ RefreshSP

INDI::PropertySwitch Connection::Serial::RefreshSP {1}
protected

Definition at line 202 of file connectionserial.h.

◆ stopBits

uint8_t Connection::Serial::stopBits = 1
protected

Definition at line 209 of file connectionserial.h.

◆ SystemPortSP

INDI::PropertySwitch Connection::Serial::SystemPortSP {0}
protected

Definition at line 200 of file connectionserial.h.

◆ wordSize

uint8_t Connection::Serial::wordSize = 8
protected

Definition at line 207 of file connectionserial.h.


The documentation for this class was generated from the following files: