3.创建S7Util工具类com.github.s7connector s7connector2.1
package com.ximenzi.s7.utils; import com.github.s7connector.api.DaveArea; import com.github.s7connector.api.S7Connector; import com.github.s7connector.api.factory.S7ConnectorFactory; public class S7Util { public void writePlcRegister(String ip , Integer block , byte[] buffer , Integer offset ){ S7Connector connector = S7Util.s7Connector(ip); connector.write(DaveArea.DB,block,offset,buffer); } public byte[] readPlcRegister(String ip , Integer block , Integer buffer , Integer offset){ S7Connector connector = S7Util.s7Connector(ip); return connector.read( //选择区块 DaveArea.DB, // 区块编号 block, //字节 buffer, //偏移 offset); } public static S7Connector s7Connector(String ip){ return S7ConnectorFactory .buildTCPConnector() .withHost(ip) .withPort(102) .withTimeout(10000) .withRack(0) //optional .withSlot(1) //optional .build(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)