CPP PortHandler
- Description
Base class for serial communication.
- Members
Members | Description |
---|---|
DEFAULT_BAUDRATE_ | :=1000000 Default Baudrate |
is_using_ | Shows whether the port is in-use |
- Methods
Methods | Description |
---|---|
getPortHandler | Gets a child class (PortHandlerLinux or PortHandlerWindows) instance |
~PortHandler | None |
openPort | Opens a serial port |
closePort | Closes a serial port |
clearPort | Refreshes a serial port |
setPortName | Sets a device name |
getPortName | Gets a device name |
setBaudrate | Sets a baudrate |
getBaudrate | Gets a baudrate |
getBytesAvailable | Checks how many bytes can be read in port buffer |
readPort | Reads bytes from port buffer |
writePort | Writes bytes to port buffer |
setPacketTimeout | Sets timeout |
isPacketTimeout | Checks whether communication has been succeeded in timeout |
-
Enumerator
None
Method References
CPP PortHandlerWindows
-
Description
Child class for serial communication on Windows OS.
-
Members
None
-
Methods
Methods | Description |
---|---|
PortHandlerWindows | Initializes PortHandlerWindows instance |
~PortHandlerWindows | Closes a serial port |
openPort | Opens a serial port |
closePort | Closes a serial port |
clearPort | Refreshes a serial port |
setPortName | Sets a device name |
getPortName | Gets a device name |
setBaudrate | Sets a baudrate |
getBaudrate | Gets a baudrate |
getBytesAvailable | Checks how many bytes can be read in port buffer |
readPort | Reads bytes from port buffer |
writePort | Writes bytes to port buffer |
setPacketTimeout | Sets timeout |
isPacketTimeout | Checks whether communication has been succeeded in timeout |
-
Enumerator
None
Method References
openPort
- Syntax
bool openPort()
-
Parameters
None
-
Detailed Description
This function opens the port by
setBaudRate()
function usingDEFAULT_BAUDRATE_
. If the baudrate is needed to be changed to another baudrate value,setBaudRate()
function should be called after callingopenPort()
function. When the port succeeds to be opened, this function will return true, and if not, then false.
closePort
- Syntax
void closePort()
-
Parameters
None
-
Detailed Description
This function closes the port by closing the file descriptor.
clearPort
- Syntax
void clearPort()
-
Parameters
None
-
Detailed Description
This function clears the port by flushing the file descriptor.
setPortName
- Syntax
void setPortName(const char* port_name)
- Parameters
Parameters | Description |
---|---|
port_name | Port name |
-
Detailed Description
This function sets the device name as port_name.
getPortName
- Syntax
char* getPortName()
-
Parameters
None
-
Detailed Description
This function returns the device name which the port is using.
setBaudrate
- Syntax
bool setBaudRate(const int baudrate)
- Parameters
Parameters | Description |
---|---|
baudrate | Target baudrate |
-
Description
This function converts baudrate to baudrate type value at first. Secondly, it closes the port with
closePort()
function, and opens the port withsetupPort()
function again. If the value of baudrate is not in the baudrate list shown in thegetCFlagBaud()
function, thesetCustomBaudrate()
function suggests the baudrate value which is closest of available baudrate value. Finally, it returns false.
getBaudrate
- Syntax
int getBaudRate()
-
Parameters
None
-
Description
This function returns the baudrate value previously set.
getBytesAvailable
- Syntax
int getBytesAvailable()
-
Parameters
None
-
Description
This function checks how much the data can be read, and returns its length.
readPort
- Syntax
int readPort(UINT8_T* packet, int length)
- Parameters
Parameters | Description |
---|---|
packet | The number of data bytes read previously |
length | Byte length for read |
-
Description
This function gets length byte data from port buffer and returns a number of read data bytes. On end-of-file, 0 is returned, on error it returns -1.
writePort
- Syntax
int writePort(UINT8_T* packet, int length)
- Parameters
Parameters | Description |
---|---|
packet | The number of data bytes to write |
length | Byte length for write |
-
Description
This function transmits length byte, and returns how much the data was written. On error, it returns -1.
setPacketTimeout
- Syntax
void setPacketTimeout (UINT16_T packet_length)
void setPacketTimeout (double msec)
- Parameters
Parameters | Description |
---|---|
Packet_length | Target byte length for write |
msec | Miliseconds |
-
Description
This function sets the start time when it transmits the packet, and set the timeout of packet transmission to be ready for deciding communication result.
isPacketTimeout
- Syntax
bool isPacketTimeout ()
-
Parameters
None
-
Description
This function decides the timeover of packet communication. If the time limit is over, it returns false.
CPP PortHandlerLinux
-
Description
Child class for serial communication on Linux OS.
-
Members
None
-
Methods
Methods | Description |
---|---|
PortHandlerLinux | Initializes PortHandlerLinux instance |
~PortHandlerLinux | Closes a serial port |
openPort | Opens a serial port |
closePort | Closes a serial port |
clearPort | Refreshes a serial port |
setPortName | Sets a device name |
getPortName | Gets a device name |
setBaudrate | Sets a baudrate |
getBaudrate | Gets a baudrate |
getBytesAvailable | Checks how many bytes can be read in port buffer |
readPort | Reads bytes from port buffer |
writePort | Writes bytes to port buffer |
setPacketTimeout | Sets timeout |
isPacketTimeout | Checks whether communication has been succeeded in timeout |
-
Enumerator
None
Method References
openPort
- Syntax
bool openPort()
-
Parameters
None
-
Detailed Description
This function opens the port by
setBaudRate()
function usingDEFAULT_BAUDRATE_
. If the baudrate is needed to be changed to another baudrate value,setBaudRate()
function should be called after callingopenPort()
function. When the port succeeds to be opened, this function will return true, and if not, then false.
closePort
- Syntax
void closePort()
-
Parameters
None
-
Detailed Description
This function closes the port by closing the file descriptor.
clearPort
- Syntax
void clearPort()
-
Parameters
None
-
Detailed Description
This function clears the port by flushing the file descriptor.
setPortName
- Syntax
void setPortName(const char* port_name)
- Parameters
Parameters | Description |
---|---|
port_name | Port name |
-
Detailed Description
This function sets the device name as port_name.
getPortName
- Syntax
char* getPortName()
-
Parameters
None
-
Detailed Description
This function returns the device name which the port is using.
setBaudrate
- Syntax
bool setBaudRate(const int baudrate)
- Parameters
Parameters | Description |
---|---|
baudrate | Target baudrate |
-
Description
This function converts baudrate to baudrate type value at first. Secondly, it closes the port with
closePort()
function, and opens the port withsetupPort()
function again. If the value of baudrate is not in the baudrate list shown in thegetCFlagBaud()
function, thesetCustomBaudrate()
function suggests the baudrate value which is closest of available baudrate value. Finally, it returns false.
getBaudrate
- Syntax
int getBaudRate()
-
Parameters
None
-
Description
This function returns the baudrate value previously set.
getBytesAvailable
- Syntax
int getBytesAvailable()
-
Parameters
None
-
Description
This function checks how much the data can be read, and returns its length.
readPort
- Syntax
int readPort(UINT8_T* packet, int length)
- Parameters
Parameters | Description |
---|---|
packet | The number of data bytes read previously |
length | Byte length for read |
-
Description
This function gets length byte data from port buffer and returns a number of read data bytes. On end-of-file, 0 is returned, on error it returns -1.
writePort
- Syntax
int writePort(UINT8_T* packet, int length)
- Parameters
Parameters | Description |
---|---|
packet | The number of data bytes to write |
length | Byte length for write |
-
Description
This function transmits length byte, and returns how much the data was written. On error, it returns -1.
setPacketTimeout
- Syntax
void setPacketTimeout (UINT16_T packet_length)
void setPacketTimeout (double msec)
- Parameters
Parameters | Description |
---|---|
Packet_length | Target byte length for write |
msec | Miliseconds |
-
Description
This function sets the start time when it transmits the packet, and set the timeout of packet transmission to be ready for deciding communication result.
isPacketTimeout
- Syntax
bool isPacketTimeout ()
-
Parameters
None
-
Description
This function decides the timeover of packet communication. If the time limit is over, it returns false.
CPP PortHandlerMac
openPort
- Syntax
bool openPort()
-
Parameters
None
-
Detailed Description
This function opens the port by
setBaudRate()
function usingDEFAULT_BAUDRATE_
. If the baudrate is needed to be changed to another baudrate value,setBaudRate()
function should be called after callingopenPort()
function. When the port succeeds to be opened, this function will return true, and if not, then false.
closePort
- Syntax
void closePort()
-
Parameters
None
-
Detailed Description
This function closes the port by closing the file descriptor.
clearPort
- Syntax
void clearPort()
-
Parameters
None
-
Detailed Description
This function clears the port by flushing the file descriptor.
setPortName
- Syntax
void setPortName(const char* port_name)
- Parameters
Parameters | Description |
---|---|
port_name | Port name |
-
Detailed Description
This function sets the device name as port_name.
getPortName
- Syntax
char* getPortName()
-
Parameters
None
-
Detailed Description
This function returns the device name which the port is using.
setBaudrate
- Syntax
bool setBaudRate(const int baudrate)
- Parameters
Parameters | Description |
---|---|
baudrate | Target baudrate |
-
Description
This function converts baudrate to baudrate type value at first. Secondly, it closes the port with
closePort()
function, and opens the port withsetupPort()
function again. If the value of baudrate is not in the baudrate list shown in thegetCFlagBaud()
function, thesetCustomBaudrate()
function suggests the baudrate value which is closest of available baudrate value. Finally, it returns false.
getBaudrate
- Syntax
int getBaudRate()
-
Parameters
None
-
Description
This function returns the baudrate value previously set.
getBytesAvailable
- Syntax
int getBytesAvailable()
-
Parameters
None
-
Description
This function checks how much the data can be read, and returns its length.
readPort
- Syntax
int readPort(UINT8_T* packet, int length)
- Parameters
Parameters | Description |
---|---|
packet | The number of data bytes read previously |
length | Byte length for read |
-
Description
This function gets length byte data from port buffer and returns a number of read data bytes. On end-of-file, 0 is returned, on error it returns -1.
writePort
- Syntax
int writePort(UINT8_T* packet, int length)
- Parameters
Parameters | Description |
---|---|
packet | The number of data bytes to write |
length | Byte length for write |
-
Description
This function transmits length byte, and returns how much the data was written. On error, it returns -1.
setPacketTimeout
- Syntax
void setPacketTimeout (UINT16_T packet_length)
void setPacketTimeout (double msec)
- Parameters
Parameters | Description |
---|---|
Packet_length | Target byte length for write |
msec | Miliseconds |
-
Description
This function sets the start time when it transmits the packet, and set the timeout of packet transmission to be ready for deciding communication result.
isPacketTimeout
- Syntax
bool isPacketTimeout ()
-
Parameters
None
-
Description
This function decides the timeover of packet communication. If the time limit is over, it returns false.