Skip to main content

python_porthandler

  • Description

Base class for serial communication.

  • Members
MembersDescription
DEFAULT_BAUDRATE_:=1000000 Default Baudrate
is_using_Shows whether the port is in-use
  • Methods
MethodsDescription
PortHandlerInitializes parameters for serial port control
openPortOpens a serial port
closePortCloses a serial port
clearPortRefreshes a serial port
setPortNameSets a device name
getPortNameGets a device name
setBaudrateSets a baudrate
getBaudrateGets a baudrate
getBytesAvailableChecks how many bytes can be read in port buffer
readPortReads bytes from port buffer
writePortWrites bytes to port buffer
setPacketTimeoutSets timeout
isPacketTimeoutChecks whether communication has been succeeded in timeout
  • Enumerator

    None

Method References

PortHandler
  • Syntax
PortHandler(port_name)
  • Parameters
ParametersDescription
port_namePort name
  • Detailed Description

    The function initializes the parameters for port control.

openPort
  • Syntax
openPort()
  • Parameters

None

  • Detailed Description

    This function opens the port by setBaudRate function using default baudrate(1M). If the baudrate is needed to be changed to another baudrate value, setBaudRate function should be called again after calling openPort function. 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
ParametersDescription
port_namePort 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
ParametersDescription
baudrateTarget 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
ParametersDescription
lengthByte length for read
  • Description

    This function gets the byte data from port buffer and returns the byte data.

writePort
  • Syntax
writePort(packet)
  • Parameters
ParametersDescription
packetThe number of data bytes to write
lengthByte length for write
  • Description

    This function transmits byte data, and returns how much the data was written.

setPacketTimeout
  • Syntax
setPacketTimeout(packet_length)
  • Parameters
ParametersDescription
Packet_lengthTarget 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
ParametersDescription
msecMiliseconds
  • Description

    This function sets the start time with msec milisecond 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.