Class SerialPortReader

  • All Implemented Interfaces:
    java.lang.Runnable

    public class SerialPortReader
    extends java.lang.Thread
    Read in bytes from the serial port connection and provide them to the ReaderM class for decoding of the unique packet format used by the IMU sensors.
    Since:
    Ptolemy II 11.0
    Version:
    $Id$, $Id$
    Author:
    Hunter Massey
    See Also:
    SerialPortController, ReaderM
    Pt.AcceptedRating:
    Pt.ProposedRating:
    Yellow Hunter
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      SerialPortReader()
      Construct a serial port reader.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void closePort()
      Closes the serial port connection.
      int init​(int portNumber)
      Initialize the serial port and connect a BufferedInputStream to the serialPort.
      java.lang.String readFromPort()
      Takes the next single value from the buffer of Characters read from the input stream.
      void run()
      Run method for this class.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • SerialPortReader

        public SerialPortReader()
        Construct a serial port reader. Determines OS and chooses serial port name prefix accordingly.
    • Method Detail

      • init

        public int init​(int portNumber)
        Initialize the serial port and connect a BufferedInputStream to the serialPort.
        Parameters:
        portNumber - The number of theport
        Returns:
        1 if the initialization was successfull, -1 otherwise.
      • run

        public void run()
        Run method for this class. Starts a thread that constantly reads in from serial port stream A BufferedInputStream connected to the serial port is read into a LinkedBlockingQueue.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • readFromPort

        public java.lang.String readFromPort()
        Takes the next single value from the buffer of Characters read from the input stream.
        Returns:
        the character read from serial port as a String
      • closePort

        public void closePort()
        Closes the serial port connection. Called by class that owns this object to stop serial port connection