Python 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 |
|---|---|
| PortHandler | Initializes parameters for serial port control |
| 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
PortHandler
- Syntax
PortHandler(port_name) - Parameters
| Parameters | Description |
|---|---|
| port_name | Port name |
-
Detailed Description
The function initializes the parameters for port control.
openPort
- Syntax
openPort() - Parameters
None
-
Detailed Description
This function opens the port by
setBaudRatefunction using default baudrate(1M). If the baudrate is needed to be changed to another baudrate value,setBaudRatefunction should be called again after callingopenPortfunction. When the port succeeds to be opened, this function will return true, and if not, then false.
closePort
- Syntax
closePort() - Parameters
None
-
Detailed Description
This function closes the port.
clearPort
- Syntax
clearPort() - Parameters
None
-
Detailed Description
This function clears the port.
setPortName
- Syntax
setPortName(port_name) - Parameters
| Parameters | Description |
|---|---|
| port_name | Port name |
-
Detailed Description
This function sets the device name as port_name.
getPortName
- Syntax
getPortName() - Parameters
None
-
Detailed Description
This function returns the device name which the port is using.
setBaudrate
- Syntax
setBaudrate(baudrate)
- Parameters
| Parameters | Description |
|---|---|
| baudrate | Target baudrate |
-
Description
This function checks whether the baudrate is available in selected operating system at first. If the baudrate is not available, it returns -1.
getBaudrate
- Syntax
getBaudrate()
- Parameters
None
-
Description
This function returns the baudrate value previously set.
getBytesAvailable
- Syntax
getBytesAvailable()
- Parameters
None
-
Description
This function checks how much the data can be read, and returns its length.
readPort
- Syntax
readPort(length)
- Parameters
| Parameters | Description |
|---|---|
| length | Byte length for read |
-
Description
This function gets the byte data from port buffer and returns the byte data.
writePort
- Syntax
writePort(packet)
- Parameters
| Parameters | Description |
|---|---|
| packet | The number of data bytes to write |
| length | Byte length for write |
-
Description
This function transmits byte data, and returns how much the data was written.
setPacketTimeout
- Syntax
setPacketTimeout(packet_length)
- Parameters
| Parameters | Description |
|---|---|
| Packet_length | Target byte length for write |
-
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.
setPacketTimeoutMillis
- Syntax
setPacketTimeoutMillis(msec)
- Parameters
| Parameters | Description |
|---|---|
| msec | Miliseconds |
-
Description
This function sets the start time with
msecmilisecond value when it transmits the packet, and set the timeout of packet transmission to be ready for deciding communication result.
isPacketTimeout
- Syntax
isPacketTimeout()
- Parameters
None
-
Description
This function decides the timeover of packet communication. If the time limit is over, it returns false.

