Examples of RpSerialPort


Examples of promauto.utils.RpSerialPort

  public RpSerialPort getPort(int portnum) {
    return ports.get(portnum);
  }

  private RpSerialPort getPortForConsoleCommand(String[] cmd) throws Exception {
    RpSerialPort port = getPort(Integer.parseInt(cmd[2]));
    if (port==null)
      throw new Exception();
    return port;
  }
View Full Code Here

Examples of promauto.utils.RpSerialPort

    if (result) {

      // Command - list
      if (cmd[1].equals("list") || cmd[1].equals("l")) {
        TreeSet<Integer> set = new TreeSet<Integer>( ports.keySet() );
        RpSerialPort port;
        for (Integer portnum: set) {
          port = ports.get(portnum);
          svcConsole.write("  " + portnum + ":   "  +port.getName() + "\n" );
        }
      } else
       
      // Command - readstr
      if (cmd[1].equals("readstr") || cmd[1].equals("rs")) {
        RpSerialPort port = getPortForConsoleCommand(cmd);
        svcConsole.write(JRoboStrings.SVCSERIAL_READ_FROM + port.getName()+": "+ port.readAllString() +"\n" );
      } else
         
      // Command - readhex
      if (cmd[1].equals("readhex") || cmd[1].equals("rh")) {
        RpSerialPort port = getPortForConsoleCommand(cmd);
        byte[] bin = new byte[2048];
        int n = port.readBytes(bin);
        byte[] bb = Arrays.copyOfRange(bin, 0, Math.abs(n));
        svcConsole.write(JRoboStrings.SVCSERIAL_READ_FROM + port.getName()+": "+ RpHyperstring.bytesToHexString(bb) +"\n" );
      } else
         
      // Command - write and read string
      if (cmd[1].equals("str") || cmd[1].equals("s")) {
        RpSerialPort port = getPortForConsoleCommand(cmd);
        svcConsole.write(JRoboStrings.SVCSERIAL_WRITE_TO + port.getName()+": "+cmd[3]+"\n" );
        port.writeString(cmd[3]+"\n");
        Thread.sleep(500);
        svcConsole.write(JRoboStrings.SVCSERIAL_READ_FROM + port.getName()+": "+ port.readAllString() +"\n" );
      } else
     
      // Command - write and read hex
      if (cmd[1].equals("hex") || cmd[1].equals("h")) {
        RpSerialPort port = getPortForConsoleCommand(cmd);
        byte[] bout = RpHyperstring.hexStringToBytes(cmd, 3);
        svcConsole.write(JRoboStrings.SVCSERIAL_WRITE_TO + port.getName()+": "+ RpHyperstring.bytesToHexString(bout) +"\n" );
        port.writeBytes(bout);
        byte[] bin = new byte[2048];
        int n = port.readBytes(bin);
        byte[] bb = Arrays.copyOfRange(bin, 0, Math.abs(n));
        svcConsole.write(JRoboStrings.SVCSERIAL_READ_FROM + port.getName()+": "+ RpHyperstring.bytesToHexString(bb) +"\n" );
      } else
     
      // somebody else's command
        result = false;
    }
View Full Code Here

Examples of promauto.utils.RpSerialPort

          int databits = Integer.parseInt(p[2]);
          int parity = convertCharParity(p[3]);
          int stopbits = Integer.parseInt(p[4]);
          int timeout = Integer.parseInt(p[5]);

          RpSerialPort port = new RpSerialPortRXTX();
          port.setPortParameters(p[0], baud, databits, parity, stopbits, timeout);
          ports.put(portnum, port);
        }
        catch (NumberFormatException e) {
          JRoboUtils.logError(
              JRoboStrings.INVALID_SERIAL_CFG + m.getKey() +
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.