Instrument Neutral Distributed Interface INDI  2.0.2
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_9600 , B_19200 , B_38400 , B_57600 ,
  B_115200 , B_230400
}
 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_CUSTOM = 1 << 15
}
 

Public Member Functions

 Serial (INDI::DefaultDevice *dev)
 
virtual ~Serial ()
 
virtual bool Connect () override
 Connect Connect to device via the implemented communication medium. Do not perform any handshakes. More...
 
virtual bool Disconnect () override
 Disconnect Disconnect from device. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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 More...
 
uint8_t getParity () const
 
void setParity (const uint8_t &value)
 setParity Set parity to be used in the serial connection. Default 0 (NONE) More...
 
uint8_t getStopBits () const
 
void setStopBits (const uint8_t &value)
 setStopBits Set stop bits to be used in the serial connection. Default 0 More...
 
- Public Member Functions inherited from Connection::Interface
virtual Type type ()
 type Return connection type More...
 
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 intial connection to the device is established. More...
 

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

ITextVectorProperty PortTP
 
IText PortT [1] {}
 
ISwitch BaudRateS [6]
 
ISwitchVectorProperty BaudRateSP
 
ISwitch AutoSearchS [2]
 
ISwitchVectorProperty AutoSearchSP
 
ISwitchSystemPortS = nullptr
 
ISwitchVectorProperty SystemPortSP
 
ISwitch RefreshS [1]
 
ISwitchVectorProperty RefreshSP
 
int PortFD = -1
 
uint8_t wordSize = 8
 
uint8_t parity = 0
 
uint8_t stopBits = 1
 
std::string m_ConfigPort
 
int m_ConfigBaudRate {-1}
 
std::vector< std::string > m_SystemPorts
 
- Protected Attributes inherited from Connection::Interface
std::function< bool()> Handshake
 
INDI::DefaultDevicem_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 39 of file connectionserial.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
SERIAL_DEV 
USB_ID_DEV 
BLUETOOTH_DEV 

Definition at line 165 of file connectionserial.h.

◆ BaudRate

Supported baud rates.

Note
: Default baud rate is 9600. To change default baud rate, use setDefaultBaudrate(..) function.
Enumerator
B_9600 
B_19200 
B_38400 
B_57600 
B_115200 
B_230400 

Definition at line 47 of file connectionserial.h.

Constructor & Destructor Documentation

◆ Serial()

Connection::Serial::Serial ( INDI::DefaultDevice dev)

Definition at line 37 of file connectionserial.cpp.

◆ ~Serial()

Connection::Serial::~Serial ( )
virtual

Definition at line 90 of file connectionserial.cpp.

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 331 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 382 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 293 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 340 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 321 of file connectionserial.cpp.

◆ getParity()

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

Definition at line 127 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 101 of file connectionserial.h.

◆ getStopBits()

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

Definition at line 140 of file connectionserial.h.

◆ getWordSize()

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

Definition at line 115 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 65 of file connectionserial.h.

◆ name()

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

Implements Connection::Interface.

Definition at line 60 of file connectionserial.h.

◆ port()

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

Definition at line 73 of file connectionserial.h.

◆ processHandshake()

bool Connection::Serial::processHandshake ( )
protectedvirtual

Definition at line 274 of file connectionserial.cpp.

◆ Refresh()

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

Refresh the list of system ports

Definition at line 436 of file connectionserial.cpp.

◆ saveConfigItems()

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

Reimplemented from Connection::Interface.

Definition at line 351 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 369 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 360 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 135 of file connectionserial.h.

◆ 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 147 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 122 of file connectionserial.h.

Member Data Documentation

◆ AutoSearchS

ISwitch Connection::Serial::AutoSearchS[2]
protected

Definition at line 179 of file connectionserial.h.

◆ AutoSearchSP

ISwitchVectorProperty Connection::Serial::AutoSearchSP
protected

Definition at line 180 of file connectionserial.h.

◆ BaudRateS

ISwitch Connection::Serial::BaudRateS[6]
protected

Definition at line 176 of file connectionserial.h.

◆ BaudRateSP

ISwitchVectorProperty Connection::Serial::BaudRateSP
protected

Definition at line 177 of file connectionserial.h.

◆ m_ConfigBaudRate

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

Definition at line 196 of file connectionserial.h.

◆ m_ConfigPort

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

Definition at line 195 of file connectionserial.h.

◆ m_SystemPorts

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

Definition at line 197 of file connectionserial.h.

◆ parity

uint8_t Connection::Serial::parity = 0
protected

Definition at line 192 of file connectionserial.h.

◆ PortFD

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

Definition at line 188 of file connectionserial.h.

◆ PortT

IText Connection::Serial::PortT[1] {}
protected

Definition at line 174 of file connectionserial.h.

◆ PortTP

ITextVectorProperty Connection::Serial::PortTP
protected

Definition at line 173 of file connectionserial.h.

◆ RefreshS

ISwitch Connection::Serial::RefreshS[1]
protected

Definition at line 185 of file connectionserial.h.

◆ RefreshSP

ISwitchVectorProperty Connection::Serial::RefreshSP
protected

Definition at line 186 of file connectionserial.h.

◆ stopBits

uint8_t Connection::Serial::stopBits = 1
protected

Definition at line 193 of file connectionserial.h.

◆ SystemPortS

ISwitch* Connection::Serial::SystemPortS = nullptr
protected

Definition at line 182 of file connectionserial.h.

◆ SystemPortSP

ISwitchVectorProperty Connection::Serial::SystemPortSP
protected

Definition at line 183 of file connectionserial.h.

◆ wordSize

uint8_t Connection::Serial::wordSize = 8
protected

Definition at line 191 of file connectionserial.h.


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