Commit 7138bd9c35b810a747de6c8dd6c0f648332df8b3
authorManfred Steiner <sx@htl-kaindorf.at>
Thu, 1 Oct 2020 15:37:33 +0000 (17:37 +0200)
committerManfred Steiner <sx@htl-kaindorf.at>
Thu, 1 Oct 2020 15:37:33 +0000 (17:37 +0200)
7 files changed:
java_modbusmaster/nbproject/build-impl.xml
java_modbusmaster/nbproject/genfiles.properties
java_modbusmaster/nbproject/project.properties
java_modbusmaster/released/README.TXT [new file with mode: 0644]
java_modbusmaster/released/java_modbusmaster.jar [new file with mode: 0644]
java_modbusmaster/released/lib/jserialcomm.jar [new file with mode: 0644]
java_modbusmaster/src/modbus/ModbusTest.java

index c3a5098747f1e694810709ad8b87f9ed2c359402..cf9698def3682357165c5b4c727afe2a8dcbb4b7 100644 (file)
@@ -154,18 +154,6 @@ is divided into following sections:
                 <istrue value="${not.archive.disabled}"/>
             </or>
         </condition>
-        <condition property="do.mkdist">
-            <and>
-                <isset property="do.archive"/>
-                <isset property="libs.CopyLibs.classpath"/>
-                <not>
-                    <istrue value="${mkdist.disabled}"/>
-                </not>
-                <not>
-                    <istrue value="${modules.supported.internal}"/>
-                </not>
-            </and>
-        </condition>
         <condition property="do.archive+manifest.available">
             <and>
                 <isset property="manifest.available"/>
@@ -1193,13 +1181,27 @@ is divided into following sections:
             <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
         </manifest>
     </target>
-    <target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.mkdist" name="-do-jar-copylibs">
+    <target depends="init,compile" name="-check-do-mkdist">
+        <condition property="do.mkdist">
+            <and>
+                <isset property="do.archive"/>
+                <isset property="libs.CopyLibs.classpath"/>
+                <not>
+                    <istrue value="${mkdist.disabled}"/>
+                </not>
+                <not>
+                    <available file="${build.classes.dir}/module-info.class"/>
+                </not>
+            </and>
+        </condition>
+    </target>
+    <target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-check-do-mkdist" if="do.mkdist" name="-do-jar-copylibs">
         <j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
         <echo level="info">To run this application from the command line without Ant, try:</echo>
         <property location="${dist.jar}" name="dist.jar.resolved"/>
         <echo level="info">java -jar "${dist.jar.resolved}"</echo>
     </target>
-    <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
+    <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-check-do-mkdist" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
         <j2seproject1:jar manifest="${tmp.manifest.file}"/>
         <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
         <property location="${dist.jar}" name="dist.jar.resolved"/>
index 17f9a588e146b7de26c0ad95c0c8ad91c6bb5f42..15c72fdb1414d7059bcf50db7f7c9a2fb40b9067 100644 (file)
@@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=f85dc8f2@1.89.1.48
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
 nbproject/build-impl.xml.data.CRC32=1872cd09
-nbproject/build-impl.xml.script.CRC32=306010fb
-nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.89.1.48
+nbproject/build-impl.xml.script.CRC32=4e2f058b
+nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.95.0.48
index 8eb24e2823d20d5d48ba5837d29e4c8d0a5d1162..fb79f1097293f8c918f26cf5c31c515680aa98e6 100644 (file)
@@ -1,9 +1,10 @@
 annotation.processing.enabled=true
 annotation.processing.enabled.in.editor=false
-annotation.processing.processor.options=
 annotation.processing.processors.list=
 annotation.processing.run.all.processors=true
 annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=java_modbusmaster
+application.vendor=steiner
 build.classes.dir=${build.dir}/classes
 build.classes.excludes=**/*.java,**/*.form
 # This directory is removed when the project is cleaned:
@@ -28,19 +29,22 @@ debug.test.modulepath=\
 dist.dir=dist
 dist.jar=${dist.dir}/java_modbusmaster.jar
 dist.javadoc.dir=${dist.dir}/javadoc
+endorsed.classpath=
 excludes=
 includes=**
 jar.compress=false
-javac.classpath=
+javac.classpath=\
+    ${libs.JSerialComm.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=
 javac.deprecation=false
+javac.external.vm=false
 javac.modulepath=
 javac.processormodulepath=
 javac.processorpath=\
     ${javac.classpath}
-javac.source=1.7
-javac.target=1.7
+javac.source=1.8
+javac.target=1.8
 javac.test.classpath=\
     ${javac.classpath}:\
     ${build.classes.dir}
@@ -51,6 +55,7 @@ javac.test.processorpath=\
 javadoc.additionalparam=
 javadoc.author=false
 javadoc.encoding=${source.encoding}
+javadoc.html5=false
 javadoc.noindex=false
 javadoc.nonavbar=false
 javadoc.notree=false
@@ -59,6 +64,8 @@ javadoc.splitindex=true
 javadoc.use=true
 javadoc.version=false
 javadoc.windowtitle=
+jlink.launcher=false
+jlink.launcher.name=java_modbusmaster
 main.class=modbus.ModbusTest
 manifest.file=manifest.mf
 meta.inf.dir=${src.dir}/META-INF
diff --git a/java_modbusmaster/released/README.TXT b/java_modbusmaster/released/README.TXT
new file mode 100644 (file)
index 0000000..5de1d92
--- /dev/null
@@ -0,0 +1,32 @@
+========================
+BUILD OUTPUT DESCRIPTION
+========================
+
+When you build an Java application project that has a main class, the IDE
+automatically copies all of the JAR
+files on the projects classpath to your projects dist/lib folder. The IDE
+also adds each of the JAR files to the Class-Path element in the application
+JAR files manifest file (MANIFEST.MF).
+
+To run the project from the command line, go to the dist folder and
+type the following:
+
+java -jar "java_modbusmaster.jar" 
+
+To distribute this project, zip up the dist folder (including the lib folder)
+and distribute the ZIP file.
+
+Notes:
+
+* If two JAR files on the project classpath have the same name, only the first
+JAR file is copied to the lib folder.
+* Only JAR files are copied to the lib folder.
+If the classpath contains other types of files or folders, these files (folders)
+are not copied.
+* If a library on the projects classpath also has a Class-Path element
+specified in the manifest,the content of the Class-Path element has to be on
+the projects runtime path.
+* To set a main class in a standard Java project, right-click the project node
+in the Projects window and choose Properties. Then click Run and enter the
+class name in the Main Class field. Alternatively, you can manually type the
+class name in the manifest Main-Class element.
diff --git a/java_modbusmaster/released/java_modbusmaster.jar b/java_modbusmaster/released/java_modbusmaster.jar
new file mode 100644 (file)
index 0000000..29c9e3a
Binary files /dev/null and b/java_modbusmaster/released/java_modbusmaster.jar differ
diff --git a/java_modbusmaster/released/lib/jserialcomm.jar b/java_modbusmaster/released/lib/jserialcomm.jar
new file mode 100644 (file)
index 0000000..c987259
Binary files /dev/null and b/java_modbusmaster/released/lib/jserialcomm.jar differ
index d3ae87aac8d508f8a5554b09d91d46f8a40a1016..e606cff103f88fb27622308cdf7c01ebb13aa8d4 100644 (file)
@@ -1,14 +1,12 @@
-
 package modbus;
 
-import modbus.frames.ModbusFrame;
-import at.htlkaindorf.mechatronik.serial.SimpleSerial;
-import gnu.io.SerialPort;
+import com.fazecast.jSerialComm.SerialPort;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.List;
+
+import modbus.frames.ModbusFrame;
 import modbus.frames.ModbusFrameReadCoil;
 import modbus.frames.ModbusFrameReadDiscreteInput;
 import modbus.frames.ModbusFrameReadHoldingRegisters;
@@ -18,178 +16,185 @@ import modbus.frames.ModbusFrameWriteMultipleCoils;
 import modbus.frames.ModbusFrameWriteMultipleRegisters;
 import modbus.frames.ModbusFrameWriteRegister;
 
-
 /**
  *
  * @author sx
  */
-public class ModbusTest
-{
-  private SimpleSerial serial;
-  private BufferedInputStream is;
-  private BufferedOutputStream os;
-  byte [] lastResponse;
-
-
-  public ModbusTest (String port) throws Exception
-  {
-    serial = new SimpleSerial(port);
-    serial.open();
-    serial.setSerialPortParams(57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
-    is = new BufferedInputStream(serial.getInputStream());
-    os = new BufferedOutputStream(serial.getOutputStream());
-  }
-
-  public void close ()
-  {
-    if (serial != null)
-      serial.close();
-  }
-  
-  
-  private void sendModbusFrame (ModbusFrame requestFrame) throws IOException
-  {
-    os.write(requestFrame.getSlaveAddress());
-    os.write(requestFrame.getFuctionCode());
-    byte [] data = requestFrame.getData();
-    if (data != null)
-      os.write(data);
-    os.write(requestFrame.getCrcBytes());
-    os.flush();
-    
-    System.out.print(String.format("request:  %02x %02x", requestFrame.getSlaveAddress(), requestFrame.getFuctionCode()));
-    for (byte b : data)
-      System.out.print(String.format(" %02x", b<0? b+256 : b));
-    byte [] ba = requestFrame.getCrcBytes();
-    for (byte b : ba)
-      System.out.print(String.format(" %02x", b<0? b+256 : b));
-    System.out.println();    
-  }
-
-  private void readResponse() throws InterruptedException, IOException
-  {
-    Thread.sleep(500);
-    if (is.available()>0)
-    {
-      byte [] data = new byte [is.available()];
-      is.read(data);
-      lastResponse = data;
-      //String s = new String (data);
-      //System.out.println(s);
-      System.out.print("response:");
-      for (byte b : data)
-        System.out.print(String.format(" %02x", b));
-      System.out.println();
+public class ModbusTest {
+
+    private final SerialPort serialPort;
+    private final BufferedInputStream is;
+    private final BufferedOutputStream os;
+    byte[] lastResponse;
+
+    public ModbusTest (SerialPort serialPort) throws Exception {
+        this.serialPort = serialPort;
+        this.serialPort.openPort();
+        this.serialPort.setComPortParameters(57600, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY);
+        is = new BufferedInputStream(this.serialPort.getInputStream());
+        os = new BufferedOutputStream(this.serialPort.getOutputStream());
+        System.out.println();
+        System.out.println("Try serial port " + serialPort.getSystemPortName());
+        System.out.println("--------------------------------------------");
     }
-  }
-
-
-  public byte[] getLastResponse()
-  {
-    return lastResponse;
-  }
-  
-  public String getLastResponseString (int startIndex)
-  {
-    StringBuilder sb = new StringBuilder();
-    for (int i=startIndex; i<lastResponse.length; i++)
-    {
-      byte b = lastResponse[i];
-      if (b==0)
-        break;
-      if (b>=20 && b<127)
-        sb.append((char)b);
-      else
-        sb.append('.');
+
+    public void close () {
+        if (serialPort != null && serialPort.isOpen()) {
+            serialPort.closePort();
+        }
+    }
+
+    private void sendModbusFrame (ModbusFrame requestFrame) throws IOException {
+        try {
+            os.write(requestFrame.getSlaveAddress());
+            os.write(requestFrame.getFuctionCode());
+            byte[] data = requestFrame.getData();
+            if (data != null) {
+                os.write(data);
+            }
+            os.write(requestFrame.getCrcBytes());
+            os.flush();
+
+            System.out.print(String.format("request:  %02x %02x", requestFrame.getSlaveAddress(), requestFrame.getFuctionCode()));
+            for (byte b : data) {
+                System.out.print(String.format(" %02x", b < 0 ? b + 256 : b));
+            }
+            byte[] ba = requestFrame.getCrcBytes();
+            for (byte b : ba) {
+                System.out.print(String.format(" %02x", b < 0 ? b + 256 : b));
+            }
+            System.out.println();
+
+        } catch (Exception ex) {
+            System.out.println("ERROR: cannot write to serial port " + serialPort.getSystemPortName());
+        }
+    }
+
+    private void readResponse () throws InterruptedException, IOException {
+        try {
+            Thread.sleep(500);
+            if (is.available() > 0) {
+                byte[] data = new byte[is.available()];
+                is.read(data);
+                lastResponse = data;
+                //String s = new String (data);
+                //System.out.println(s);
+                System.out.print("response:");
+                for (byte b : data) {
+                    System.out.print(String.format(" %02x", b));
+                }
+                System.out.println();
+            }
+        } catch (Exception ex) {
+            System.out.println("ERROR: cannot read from serial port " + serialPort.getSystemPortName());
+        }
     }
-    return sb.toString();
-  }
-  
-  public static void main(String[] args) throws Exception
-  {
-    List<String> ports = SimpleSerial.findAvailableComms();
-    for (String port : ports)
-    {
-      ModbusTest mt = new ModbusTest(port);
-      try
-      {
-        ModbusFrame requestFrame;
-        System.out.println("Modbus function code 0x01 (Read coil)");
-        System.out.println("-------------------------------------");
-        requestFrame = new ModbusFrameReadCoil(2, 0, 4);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("");
-        
-        System.out.println("\nModbus function code 0x02 (Read discrete Input)");
-        System.out.println("-------------------------------------------------");
-        requestFrame = new ModbusFrameReadDiscreteInput(2, 0, 1);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("");
-        
-        System.out.println("\nModbus function code 0x03 (Read holding register)");
-        System.out.println("--------------------------------------------------");
-        requestFrame = new ModbusFrameReadHoldingRegisters(2, 0, 5);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("");
-        
-        System.out.println("\nModbus function code 0x04 (Read input register)");
-        System.out.println("example 1: read temperature from LM75A");
-        System.out.println("--------------------------------------------------");
-        requestFrame = new ModbusFrameReadInputRegisters(2, 0x30, 1);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("");
-        
-        System.out.println("\nModbus function code 0x04 (Read input register)");
-        System.out.println("example 2: read version string");
-        System.out.println("--------------------------------------------------");
-        requestFrame = new ModbusFrameReadInputRegisters(2, 0xfff0, 16);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("response as string: " + mt.getLastResponseString(3));
-        System.out.println("");
-
-        System.out.println("\nModbus function code 0x05 (Write single coil)");
-        System.out.println("-----------------------------------------------");
-        requestFrame = new ModbusFrameWriteSingleCoil(2, 2, true);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("");
-        
-        System.out.println("\nModbus function code 0x06 (Write single (hold) register)");
-        System.out.println("----------------------------------------------------------");
-        requestFrame = new ModbusFrameWriteRegister(2, 2, 10);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("");
-
-        System.out.println("\nModbus function code 0x0f (Write multiple coils)");
-        System.out.println("--------------------------------------------------");
-        boolean [] data = new boolean[4];
-        data[0] = false; data[1] = true; data[2] = true; data[3] = false;
-        requestFrame = new ModbusFrameWriteMultipleCoils(2, 0, data);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("");
-
-        System.out.println("\nModbus function code 0x10 (Write multiple (hold) registers)");
-        System.out.println("-------------------------------------------------------------");
-        int [] regValues = new int[2];
-        regValues[0] = 0xffff; regValues[1] = 0xffff; 
-        requestFrame = new ModbusFrameWriteMultipleRegisters(2, 1, regValues);
-        mt.sendModbusFrame(requestFrame);
-        mt.readResponse();
-        System.out.println("");
-      }
-      finally
-      {
-        mt.close();
-      }
-    }  
-  }
 
+    public byte [] getLastResponse () {
+        return lastResponse;
+    }
+
+    public String getLastResponseString (int startIndex) {
+        StringBuilder sb = new StringBuilder();
+        if (lastResponse != null) {
+            for (int i = startIndex; i < lastResponse.length; i++) {
+                byte b = lastResponse[i];
+                if (b == 0) {
+                    break;
+                }
+                if (b >= 20 && b < 127) {
+                    sb.append((char) b);
+                } else {
+                    sb.append('.');
+                }
+            }
+        }
+        return sb.toString();
+    }
+
+    public static void main (String[] args) throws Exception {
+        final SerialPort[] serialPorts = SerialPort.getCommPorts();
+        for (SerialPort serialPort : serialPorts) {
+            ModbusTest mt = new ModbusTest(serialPort);
+            try {
+                ModbusFrame requestFrame;
+                System.out.println("Modbus function code 0x01 (Read coil)");
+                System.out.println("-------------------------------------");
+                requestFrame = new ModbusFrameReadCoil(2, 0, 4);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("");
+
+                System.out.println("\nModbus function code 0x02 (Read discrete Input)");
+                System.out.println("-------------------------------------------------");
+                requestFrame = new ModbusFrameReadDiscreteInput(2, 0, 1);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("");
+
+                System.out.println("\nModbus function code 0x03 (Read holding register)");
+                System.out.println("--------------------------------------------------");
+                requestFrame = new ModbusFrameReadHoldingRegisters(2, 0, 5);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("");
+
+                System.out.println("\nModbus function code 0x04 (Read input register)");
+                System.out.println("example 1: read temperature from LM75A");
+                System.out.println("--------------------------------------------------");
+                requestFrame = new ModbusFrameReadInputRegisters(2, 0x30, 1);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("");
+
+                System.out.println("\nModbus function code 0x04 (Read input register)");
+                System.out.println("example 2: read version string");
+                System.out.println("--------------------------------------------------");
+                requestFrame = new ModbusFrameReadInputRegisters(2, 0xfff0, 16);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("response as string: " + mt.getLastResponseString(3));
+                System.out.println("");
+
+                System.out.println("\nModbus function code 0x05 (Write single coil)");
+                System.out.println("-----------------------------------------------");
+                requestFrame = new ModbusFrameWriteSingleCoil(2, 2, true);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("");
+
+                System.out.println("\nModbus function code 0x06 (Write single (hold) register)");
+                System.out.println("----------------------------------------------------------");
+                requestFrame = new ModbusFrameWriteRegister(2, 2, 10);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("");
+
+                System.out.println("\nModbus function code 0x0f (Write multiple coils)");
+                System.out.println("--------------------------------------------------");
+                boolean[] data = new boolean[4];
+                data[0] = false;
+                data[1] = true;
+                data[2] = true;
+                data[3] = false;
+                requestFrame = new ModbusFrameWriteMultipleCoils(2, 0, data);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("");
+
+                System.out.println("\nModbus function code 0x10 (Write multiple (hold) registers)");
+                System.out.println("-------------------------------------------------------------");
+                int[] regValues = new int[2];
+                regValues[0] = 0xffff;
+                regValues[1] = 0xffff;
+                requestFrame = new ModbusFrameWriteMultipleRegisters(2, 1, regValues);
+                mt.sendModbusFrame(requestFrame);
+                mt.readResponse();
+                System.out.println("");
+            } finally {
+                mt.close();
+            }
+        }
+    }
 
 }