因為我剛從事IT不久,所以有還不是很成熟請多包涵,我用的編譯軟體是Eclipse,主要是要讀取Modbus的欄位,Modbus。想請教一下各位高手。
主要用的程式:JAVA
編譯器:Eclipse
我想請問一下這是我用的程式碼。現在主要是想連Modbus讀取他的欄位。我有import進Easymodbus的jar包了,我也有開啟Modbus的連線。
package ConExcel;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import de.re.easymodbus.modbusclient.*;
import de.re.easymodbus.exceptions.ModbusException;
public class TestModbus {
public static void main(String[] args) {
ModbusClient modbusClient = new ModbusClient("127.0.0.1" ,502);
try {
modbusClient.Connect();
modbusClient.WriteSingleCoil(0,true);
modbusClient.WriteSingleRegister(0,1234);
modbusClient.WriteMultipleRegisters(11, ModbusClient.ConvertFloatToTwoRegisters((float)123.56));
System.out.println(modbusClient.ReadCoils(0, 1)[0]);
System.out.println(modbusClient.ReadHoldingRegisters(0, 1)[0]);
System.out.println(modbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(11,2)));
}catch(Exception e) {
}
}
}
然後報錯:
Exception in thread "main" java.lang.NoClassDefFoundError: de/re/easymodbus/modbusclient/ModbusClient
at ConExcel.TestModbus.main(TestModbus.java:13)
Caused by: java.lang.ClassNotFoundException: de.re.easymodbus.modbusclient.ModbusClient
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more