TwiceAsNice  2019-02-18
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Connection::Serial Class Reference

The Serial class manages connection with serial devices including Bluetooth. More...

#include <connectionserial.h>

Inheritance diagram for Connection::Serial:
Inheritance graph
Collaboration diagram for Connection::Serial:
Collaboration graph

Public Types

enum  BaudRate {
  B_9600, B_19200, B_38400, B_57600,
  B_115200, B_230400, B_9600, B_19200,
  B_38400, B_57600, B_115200, B_230400
}
 Supported baud rates. More...
 
enum  BaudRate {
  B_9600, B_19200, B_38400, B_57600,
  B_115200, B_230400, B_9600, B_19200,
  B_38400, B_57600, B_115200, B_230400
}
 
- 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, CONNECTION_NONE = 1 << 0, CONNECTION_SERIAL = 1 << 1, CONNECTION_TCP = 1 << 2,
  CONNECTION_USB = 1 << 3, CONNECTION_CUSTOM = 1 << 15
}
 
enum  Type {
  CONNECTION_NONE = 1 << 0, CONNECTION_SERIAL = 1 << 1, CONNECTION_TCP = 1 << 2, CONNECTION_USB = 1 << 3,
  CONNECTION_CUSTOM = 1 << 15, 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 ()
 Connect Connect to device via the implemented communication medium. More...
 
virtual bool Disconnect ()
 Disconnect Disconnect from device. More...
 
virtual void Activated ()
 Activated Function called by the framework when the plugin is activated (i.e. More...
 
virtual void Deactivated ()
 Deactivated Function called by the framework when the plugin is deactivated. More...
 
virtual std::string name ()
 
virtual std::string label ()
 
virtual const char * port ()
 
virtual uint32_t baud ()
 
void setDefaultPort (const char *defaultPort)
 setDefaultPort Set default port. More...
 
void setDefaultBaudRate (BaudRate newRate)
 setDefaultBaudRate Set default baud rate. More...
 
int getPortFD () const
 
virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
 
virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
 
virtual bool saveConfigItems (FILE *fp)
 
bool Refresh (bool silent=false)
 Refresh the list of system ports. More...
 
uint8_t getWordSize () const
 
void setWordSize (const uint8_t &value)
 setWordSize Set word size to be used in the serial connection. More...
 
uint8_t getParity () const
 
void setParity (const uint8_t &value)
 setParity Set parity to be used in the serial connection. More...
 
uint8_t getStopBits () const
 
void setStopBits (const uint8_t &value)
 setStopBits Set stop bits to be used in the serial connection. More...
 
 Serial (INDI::DefaultDevice *dev)
 
virtual ~Serial ()
 
virtual bool Connect ()
 Connect Connect to device via the implemented communication medium. More...
 
virtual bool Disconnect ()
 Disconnect Disconnect from device. More...
 
virtual void Activated ()
 Activated Function called by the framework when the plugin is activated (i.e. More...
 
virtual void Deactivated ()
 Deactivated Function called by the framework when the plugin is deactivated. More...
 
virtual std::string name ()
 
virtual std::string label ()
 
virtual const char * port ()
 
virtual uint32_t baud ()
 
void setDefaultPort (const char *defaultPort)
 setDefaultPort Set default port. More...
 
void setDefaultBaudRate (BaudRate newRate)
 setDefaultBaudRate Set default baud rate. More...
 
int getPortFD () const
 
virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
 
virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
 
virtual bool saveConfigItems (FILE *fp)
 
bool Refresh (bool silent=false)
 Refresh the list of system ports. More...
 
uint8_t getWordSize () const
 
void setWordSize (const uint8_t &value)
 setWordSize Set word size to be used in the serial connection. More...
 
uint8_t getParity () const
 
void setParity (const uint8_t &value)
 setParity Set parity to be used in the serial connection. More...
 
uint8_t getStopBits () const
 
void setStopBits (const uint8_t &value)
 setStopBits Set stop bits to be used in the serial connection. 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)
 
void registerHandshake (std::function< bool()> callback)
 registerHandshake Register a handshake function to be called once the intial connection to the device is established. More...
 
virtual Type type ()
 type Return connection type More...
 
virtual bool ISNewNumber (const char *dev, const char *name, double values[], 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 Member Functions

virtual bool Connect (const char *port, uint32_t baud)
 Connect to serial port device. More...
 
virtual bool processHandshake ()
 
virtual bool Connect (const char *port, uint32_t baud)
 Connect to serial port device. More...
 
virtual bool processHandshake ()
 
- Protected Member Functions inherited from Connection::Interface
 Interface (INDI::DefaultDevice *dev, Type type=CONNECTION_NONE)
 
virtual ~Interface ()
 
const char * getDeviceName ()
 
 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
 
- 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,

Member Enumeration Documentation

◆ BaudRate [1/2]

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 
B_9600 
B_19200 
B_38400 
B_57600 
B_115200 
B_230400 

◆ BaudRate [2/2]

Enumerator
B_9600 
B_19200 
B_38400 
B_57600 
B_115200 
B_230400 
B_9600 
B_19200 
B_38400 
B_57600 
B_115200 
B_230400 

Constructor & Destructor Documentation

◆ Serial() [1/2]

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

◆ ~Serial() [1/2]

Connection::Serial::~Serial ( )
virtual

◆ Serial() [2/2]

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

◆ ~Serial() [2/2]

virtual Connection::Serial::~Serial ( )
virtual

Member Function Documentation

◆ Activated() [1/2]

void Connection::Serial::Activated ( )
virtual

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.

◆ Activated() [2/2]

virtual void Connection::Serial::Activated ( )
virtual

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.

◆ baud() [1/2]

uint32_t Connection::Serial::baud ( )
virtual
Returns
Currently active baud rate raw value (e.g. 9600, 19200..etc)

◆ baud() [2/2]

virtual uint32_t Connection::Serial::baud ( )
virtual
Returns
Currently active baud rate raw value (e.g. 9600, 19200..etc)

◆ Connect() [1/4]

bool Connection::Serial::Connect ( )
virtual

Connect Connect to device via the implemented communication medium.

Do not perform any handshakes.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

◆ Connect() [2/4]

virtual bool Connection::Serial::Connect ( )
virtual

Connect Connect to device via the implemented communication medium.

Do not perform any handshakes.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

◆ Connect() [3/4]

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.

◆ Connect() [4/4]

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

◆ Deactivated() [1/2]

void Connection::Serial::Deactivated ( )
virtual

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.

◆ Deactivated() [2/2]

virtual void Connection::Serial::Deactivated ( )
virtual

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.

◆ Disconnect() [1/2]

bool Connection::Serial::Disconnect ( )
virtual

Disconnect Disconnect from device.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

◆ Disconnect() [2/2]

virtual bool Connection::Serial::Disconnect ( )
virtual

Disconnect Disconnect from device.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

◆ getParity() [1/2]

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

◆ getParity() [2/2]

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

◆ getPortFD() [1/2]

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

◆ getPortFD() [2/2]

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

◆ getStopBits() [1/2]

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

◆ getStopBits() [2/2]

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

◆ getWordSize() [1/2]

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

◆ getWordSize() [2/2]

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

◆ ISNewSwitch() [1/2]

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

Reimplemented from Connection::Interface.

◆ ISNewSwitch() [2/2]

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

Reimplemented from Connection::Interface.

◆ ISNewText() [1/2]

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

Reimplemented from Connection::Interface.

◆ ISNewText() [2/2]

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

Reimplemented from Connection::Interface.

◆ label() [1/2]

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

Implements Connection::Interface.

◆ label() [2/2]

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

Implements Connection::Interface.

◆ name() [1/2]

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

Implements Connection::Interface.

◆ name() [2/2]

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

Implements Connection::Interface.

◆ port() [1/2]

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

◆ port() [2/2]

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

◆ processHandshake() [1/2]

virtual bool Connection::Serial::processHandshake ( )
protectedvirtual

◆ processHandshake() [2/2]

bool Connection::Serial::processHandshake ( )
protectedvirtual

◆ Refresh() [1/2]

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

Refresh the list of system ports.

◆ Refresh() [2/2]

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

Refresh the list of system ports.

◆ saveConfigItems() [1/2]

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

Reimplemented from Connection::Interface.

◆ saveConfigItems() [2/2]

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

Reimplemented from Connection::Interface.

◆ setDefaultBaudRate() [1/2]

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

◆ setDefaultBaudRate() [2/2]

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

◆ setDefaultPort() [1/2]

void Connection::Serial::setDefaultPort ( const char *  defaultPort)

setDefaultPort Set default port.

Call this function in initProperties() of your driver if you want to change default port.

Parameters
defaultPortName of desired default port

◆ setDefaultPort() [2/2]

void Connection::Serial::setDefaultPort ( const char *  defaultPort)

setDefaultPort Set default port.

Call this function in initProperties() of your driver if you want to change default port.

Parameters
defaultPortName of desired default port

◆ setParity() [1/2]

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

◆ setParity() [2/2]

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

◆ setStopBits() [1/2]

void Connection::Serial::setStopBits ( const uint8_t value)
inline

setStopBits Set stop bits to be used in the serial connection.

Default 0

◆ setStopBits() [2/2]

void Connection::Serial::setStopBits ( const uint8_t value)
inline

setStopBits Set stop bits to be used in the serial connection.

Default 0

◆ setWordSize() [1/2]

void Connection::Serial::setWordSize ( const uint8_t value)
inline

setWordSize Set word size to be used in the serial connection.

Default 8

◆ setWordSize() [2/2]

void Connection::Serial::setWordSize ( const uint8_t value)
inline

setWordSize Set word size to be used in the serial connection.

Default 8

Member Data Documentation

◆ AutoSearchS

ISwitch Connection::Serial::AutoSearchS
protected

◆ AutoSearchSP

ISwitchVectorProperty Connection::Serial::AutoSearchSP
protected

◆ BaudRateS

ISwitch Connection::Serial::BaudRateS
protected

◆ BaudRateSP

ISwitchVectorProperty Connection::Serial::BaudRateSP
protected

◆ parity

uint8_t Connection::Serial::parity =0
protected

◆ PortFD

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

◆ PortT

IText Connection::Serial::PortT {}
protected

◆ PortTP

ITextVectorProperty Connection::Serial::PortTP
protected

◆ RefreshS

ISwitch Connection::Serial::RefreshS
protected

◆ RefreshSP

ISwitchVectorProperty Connection::Serial::RefreshSP
protected

◆ stopBits

uint8_t Connection::Serial::stopBits =1
protected

◆ SystemPortS

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

◆ SystemPortSP

ISwitchVectorProperty Connection::Serial::SystemPortSP
protected

◆ wordSize

uint8_t Connection::Serial::wordSize =8
protected

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