• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    How to send command to standard serial port

    How-To
    2
    3
    3.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      wf321
      last edited by

      Dear Sir:

      1. I had a hardware(switch), direct connect to computer com1 using R485 line.
      2. I can turn the switch on/off using standard serial test code.
      3. I can also using following rxtx( same version as scadabr using) java code to turn it on/off.

      now with mango, I created modbus serial data source, and it can scan found 1 node. But when create data point,
      there is no "output" option for "Register range", so I do not know how to continue.

      would you please help me how to create data source ( modbus serial or .. ?) ,
      data point and script to turn the switch on/off ?

      Thanks a lot.
      william
      wf321@163.com

      *********************************** RXTX CODE ****************************
      import gnu.io.CommPort;
      import gnu.io.CommPortIdentifier;
      import gnu.io.SerialPort;

      import java.io.FileDescriptor;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.OutputStream;

      public static void main ( String[] args )
      {
      connect("COM1");
      }

      void connect ( String portName ) throws Exception
      {
          CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
          CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
      
                  SerialPort serialPort = (SerialPort) commPort;
      

      serialPort.setSerialPortParams(4800,SerialPort.DATABITS_8,SerialPort.STOPBITS_2,SerialPort.PARITY_NONE);

                  System.out.println(serialPort.getName());
                  InputStream in = serialPort.getInputStream();
                  OutputStream out = serialPort.getOutputStream();
                  
                  // send 8 int to control the switch
                  int len = 8;
                  int[] buffer = new int[len];
      
      
                  buffer[0] = 0x01;  // com1
                  buffer[1] = 0x05;  
                  buffer[2] = 0x00;  // port 0
                  buffer[3] = 0x01;  // channel
                  buffer[4] = 0xff;  // turn the switch on , 0X00 means tuen off
                  buffer[5] = 0x00;
                  buffer[6] = 0xdd;  // check use crc16
                  buffer[7] = 0xfa;  // check use crc16
      
                  
                  for (int i = 0; i < len; i++)
                  {
                      System.out.println(buffer*);
                   out.write(buffer*);
                  }
                  out.flush();
                  
                  commPort.close();
      }
      
      1 Reply Last reply Reply Quote 0
      • M
        mlohbihler
        last edited by

        "output" is not a valid register range. "Input status" and "Input register" are the read-only register ranges.

        Best regards,
        Matthew

        1 Reply Last reply Reply Quote 0
        • First post
          Last post