1、引入依赖
<dependency> <groupId>com.github.dathlin</groupId> <artifactId>HslCommunication</artifactId> <version>3.1.1</version> </dependency>
2、使用SiemensS7Net获取opc数据
/** * 测试90 */ public static void test90() { SiemensS7Net siemensTcpNet = new SiemensS7Net(SiemensPLCS.S1500, "172.18.1.90"); // 有符号的16位 地址:DB5.DBW528 字段名称:new_silo2_high_voltage_in //byte[] getBytes = siemensTcpNet.Read(DaveArea.DB, 5, 2, 528); //OperateResultExOne<byte[]> read = siemensTcpNet.Read("DB572.48", (short) 4); OperateResultExOne<byte[]> read = siemensTcpNet.Read("DB5.DBW524", (short) 2); //String str = getBinaryStrFromByte(getBytes[0]); //System.out.println("getDoubleData:"+str); //105代表读取的长度 //OperateResultExOne<byte[]> read = siemensTcpNet.Read("I32", (short) 1); OperateResultExOne<boolean[]> read1 = siemensTcpNet.ReadBool("I188", (short) 1); OperateResultExOne<Boolean> i188 = siemensTcpNet.ReadBool("I188.4"); OperateResultExOne<Boolean> i1881 = siemensTcpNet.ReadBool("I188.5"); OperateResultExOne<Boolean> i1882 = siemensTcpNet.ReadBool("I188.6"); if (read.IsSuccess) { // I74: 10100101 // 2:1 4:0 0:1 3:0 // I188: 11000100 // 4:0 5:0 3:0 2:1 7:1 6:1 byte[] content = read.Content; String str = getBinaryStrFromByte(content[0]); System.out.println("getDoubleData:"+str); //2是下标 //short no = siemensTcpNet.getByteTransform().TransInt16(content, 2); //System.out.println(no); } }View Code
源码:https://gitee.com/caesarthegreat/opc.git
标签:HslCommunication,Java,read,ReadBool,s7,short,opc,siemensTcpNet,OperateResultExOn From: https://www.cnblogs.com/caesar-the-great/p/17071984.html