Announcement

Collapse
No announcement yet.

RXTX java API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • RXTX java API

    How can I import and use RXTX java api in javascript writer and how to deal with listener event also?
    In Java code
    import gnu.io.*;

    When I wrote in mirth connect
    importPackage(gnu.io.*);

    An error occured and told that gnu is not defined.

  • #2
    Code:
    importPackage(Packages.gnu.io);

    Comment


    • #3
      Java code:
      SerialPort serialPort;
      OutputStream outputStream;
      outputStream = serialPort.getOutputStream();

      How to write in mirth connect?

      I wrote like that:
      var serialPort = Packages.gnu.io.SerialPort();
      var outputStream = java.io.OutputStream;
      outputStream = serialPort.getOutputStream();

      Caused an error:
      Java class "gnu.io.SerialPort" has no public instance field or method named "getOutputStream".
      Java class "java.io.OutputStream" has no public instance field or method named "write".

      Comment


      • #4
        FYI, the "Packages" is only required because "gnu" is not one of the common top level package names. You can leave Packages off from the beginning if the package name starts with java, javax, com, org, net, or edu (as you did with java.io.OutputStream.)

        As far as Java to Javascript conversion...
        var serialPort = Packages.gnu.io.SerialPort();
        While it works both ways, this would normally be written in the following way to show that you are calling the constructor and instantiating a new object.
        Code:
        var serialPort = new Packages.gnu.io.SerialPort();
        var outputStream = java.io.OutputStream;
        outputStream = serialPort.getOutputStream();
        Once again, this works, but the first assignment is not necessary and doesn't actually do anything helpful.
        Code:
        var outputStream = serialPort.getOutputStream();

        That being said, the error is telling you that serialPort.getOutputStream() is not a valid call. I've never used RXTX before, but I assume you need to select a port and actually open it before you can get an OutputStream. That library also looks to be really old and not maintained. Maybe try https://fazecast.github.io/jSerialComm/ instead? I've never used that one either, but it seems to be recommended in this SO question.

        Comment

        Working...
        X