当前位置: 首页 > news >正文

建设公众号官方网站抖音小程序免费制作平台

建设公众号官方网站,抖音小程序免费制作平台,建立网站容量,医疗网站模板免费下载1.需求样例 举例5#xff1a;浮点数参数读取#xff08;读取温度测量值#xff09;查看参数列表#xff0c;温度测量值地址为320#xff0c;根据Modbus协议#xff0c;读取参数地址转换为16进制为#xff1a;00H A0H#xff0c;读取长度为2个字#xff1a;00H 02H。 …1.需求样例 举例5浮点数参数读取读取温度测量值查看参数列表温度测量值地址为320根据Modbus协议读取参数地址转换为16进制为00H A0H读取长度为2个字00H 02H。 16进制发送读取命令如下00 00 00 00 00 06 01 03 00 A0 00 02(复制使用时去掉中间空格以16进制发送)00 00 00 00 00 06 01Modbus命令头用户直接复制不能更改03读取寄存器功能代码00 A0读取参数寄存器地址16进制代码00 02读取寄存器地址长度接收到数据格式如下00 00 00 00 00 07 01 03 04 42 48 02 C8 00 00 00 00 00 07 01Modbus返回命令头03读取寄存器功能代码04返回数据长度四个字节42 48 02 C8寄存器数据值我们将此16进制数转换为浮点数值为50.002716。注具体转换方法可以常见附件转换程序算法。2.实现功能 通过Java与Modbus-TCP/IP网络通讯实现举例5中的功能 3.功能代码 1 package com.nwpusct.csal.controller.tcpconnect; import java.io.*; import java.math.BigInteger; import java.net.Socket;import com.serotonin.modbus4j.exception.ErrorResponseException; import com.serotonin.modbus4j.exception.ModbusInitException; import com.serotonin.modbus4j.exception.ModbusTransportException; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory;import javax.xml.bind.DatatypeConverter;import static org.apache.poi.util.HexDump.toHex;/*** 类描述TODO** author HBO* date 2023-08-22 09:21**/ public class SocketUtils {private static final Logger LOGGER LoggerFactory.getLogger(SocketUtils.class);private static Socket socket null;private static String archivesCenterAPIIP 127.0.0.1;private static String archivesCenterAPIPort 502;public static boolean connection() {if (socket ! null) {return true;}try {socket new Socket(archivesCenterAPIIP, NumberUtils.toInt(archivesCenterAPIPort));return true;} catch (Exception e) {LOGGER.error(connection error, e);return false;}}public static void stop() {try {if (socket ! null) {socket.close();socket null;}} catch (Exception e) {LOGGER.error(connection error, e);}}/*** 发送数据** param cmd* 需要发送的数据(十六进制的字符串形式)* return 接受到的数据(十六进制的字符串形式)*/public static String sendCmd(String cmd) {if (!connection() || socket null) {return error;}try {OutputStream out socket.getOutputStream();byte[] hexStrToByteArrs hexStrToByteArrs(cmd);if (hexStrToByteArrs null) {return error;}out.write(hexStrToByteArrs);InputStream in socket.getInputStream();byte[] buf new byte[1024];int len in.read(buf);stop();return bytesToHexString(buf) ;} catch (IOException e) {LOGGER.error(sendCmd error, e);return error;}}/*** 将十六进制的字符串转换成字节数组** param hexString* return*/public static byte[] hexStrToByteArrs(String hexString) {if (StringUtils.isEmpty(hexString)) {return null;}hexString hexString.replaceAll( , );int len hexString.length();int index 0;byte[] bytes new byte[len / 2];while (index len) {String sub hexString.substring(index, index 2);bytes[index / 2] (byte) Integer.parseInt(sub, 16);index 2;}return bytes;}/*** 数组转换成十六进制字符串** param* return HexString*/public static final String bytesToHexString(byte[] bArray) {StringBuffer sb new StringBuffer(bArray.length);String sTemp;for (int i 0; i bArray.length; i) {sTemp Integer.toHexString(0xFF bArray[i]);if (sTemp.length() 2)sb.append(0);sb.append(sTemp.toUpperCase());// 在这里故意追加一个逗号便于最后的区分sb.append( );}return sb.toString();}/** 将16进制数字解码成字符串,适用于所有字符包括中文*/public static String decode(String bytes) {String hexString 0123456789ABCDEF;ByteArrayOutputStream baos new ByteArrayOutputStream(bytes.length() / 2);// 将每2位16进制整数组装成一个字节for (int i 0; i bytes.length(); i 2)baos.write((hexString.indexOf(bytes.charAt(i)) 4 | hexString.indexOf(bytes.charAt(i 1))));return new String(baos.toByteArray());}/*** 16进制数转换为浮点数值** param str 16进制数据 424802C8 50.002716* throws IOException* throws ModbusInitException* throws ModbusTransportException* throws ErrorResponseException*/public static Float intBitsToFloat(String str) {BigInteger b new BigInteger(str, 16);float value Float.intBitsToFloat(b.intValue());return value;}public static void main(String[] args) throws UnsupportedEncodingException {//34.6°String str sendCmd(00 00 00 00 00 06 01 03 00 04 00 02); // String str00 00 00 00 00 06 01 03 00 02 00 02;String x str.replaceAll(\\s*, );String s str.split( )[8];String substring x.substring(18, Integer.parseInt(s) * 2 18);System.out.println(substring);System.out.println(intBitsToFloat(substring));}} 2 package com.nwpusct.csal.controller.tcpconnect;import com.nwpusct.csal.common.util.RestResult; import com.nwpusct.csal.common.util.RestResultUtil; import com.serotonin.modbus4j.ModbusFactory; import com.serotonin.modbus4j.ModbusMaster; import com.serotonin.modbus4j.code.DataType; import com.serotonin.modbus4j.exception.ErrorResponseException; import com.serotonin.modbus4j.exception.ModbusInitException; import com.serotonin.modbus4j.exception.ModbusTransportException; import com.serotonin.modbus4j.ip.IpParameters; import com.serotonin.modbus4j.locator.BaseLocator; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*;/*** 类描述TODO* 监测高低温箱温度** author HBO* date 2023-08-21 09:34**/ CrossOrigin RestController Api(tags {监测高低温箱温度}) RequestMapping(value /modbus) public class ModbusController {Value(value ${high.ip})public String ip;//从站IPValue(value ${high.port})public int port;//modbus端口Value(value ${low.ip})public String lowIp;Value(value ${low.port})public int lowPort;/*** 工厂。*/static ModbusFactory modbusFactory;static {if (modbusFactory null) {modbusFactory new ModbusFactory();}}GetMapping(value /readModbusHigh)ApiOperation(value 高温箱)public RestResultObject readModbusHigh() {//第二中方式try {Number number readHoldingRegisterH(1, 320, DataType.FOUR_BYTE_FLOAT);return RestResultUtil.genSuccessResult(number);} catch (Exception e) {return RestResultUtil.genSuccessResult(null);}}/*** 获取master 高温箱** return* throws ModbusInitException*/public ModbusMaster getMasterH() throws ModbusInitException {IpParameters params new IpParameters();params.setHost(ip);params.setPort(port);//// modbusFactory.createRtuMaster(wapper); //RTU 协议// modbusFactory.createUdpMaster(params);//UDP 协议// modbusFactory.createAsciiMaster(wrapper);//ASCII 协议ModbusMaster master modbusFactory.createTcpMaster(params, false);// TCP 协议master.init();return master;}/*** 读取[03 Holding Register类型 2x]模拟量数据 高温箱** param slaveId slave Id* param offset 位置 序列号* param dataType 数据类型,来自com.serotonin.modbus4j.code.DataType* return* throws ModbusTransportException 异常* throws ErrorResponseException 异常* throws ModbusInitException 异常*/public Number readHoldingRegisterH(int slaveId, int offset, int dataType)throws ModbusTransportException, ErrorResponseException, ModbusInitException {// 03 Holding Register类型数据读取BaseLocatorNumber loc BaseLocator.holdingRegister(slaveId, offset, dataType);Number value getMasterH().getValue(loc);return value;}GetMapping(value /readModbusLow)ApiOperation(value 高低温箱)public RestResultObject readModbusLow() {try {Number number readHoldingRegisterL(1, 320, DataType.FOUR_BYTE_FLOAT);return RestResultUtil.genSuccessResult(number);} catch (Exception e) {return RestResultUtil.genSuccessResult(null);}}/*** 获取master 高低温箱** return* throws ModbusInitException*/public ModbusMaster getMasterL() throws ModbusInitException {IpParameters params new IpParameters();params.setHost(lowIp);params.setPort(lowPort);ModbusMaster master modbusFactory.createTcpMaster(params, false);// TCP 协议master.init();return master;}/*** 读取[03 Holding Register类型 2x]模拟量数据 高低温箱** param slaveId slave Id* param offset 位置 序列号* param dataType 数据类型,来自com.serotonin.modbus4j.code.DataType* return* throws ModbusTransportException 异常* throws ErrorResponseException 异常* throws ModbusInitException 异常*/public Number readHoldingRegisterL(int slaveId, int offset, int dataType)throws ModbusTransportException, ErrorResponseException, ModbusInitException {// 03 Holding Register类型数据读取BaseLocatorNumber loc BaseLocator.holdingRegister(slaveId, offset, dataType);Number value getMasterL().getValue(loc);return value;} } 4.maven引入依赖包 dependenciesdependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.9/version/dependency/dependencies!-- 若想引用modbus4j需要引入下列repository id:ias-snapshots id:ias-releases 两个 使用默认仓库下载不要使用阿里云仓库--repositoriesrepositoryreleasesenabledfalse/enabled/releasessnapshotsenabledtrue/enabled/snapshotsidias-snapshots/idnameInfinite Automation Snapshot Repository/nameurlhttps://maven.mangoautomation.net/repository/ias-snapshot//url/repositoryrepositoryreleasesenabledtrue/enabled/releasessnapshotsenabledfalse/enabled/snapshotsidias-releases/idnameInfinite Automation Release Repository/nameurlhttps://maven.mangoautomation.net/repository/ias-release//url/repository/repositories5.测试模拟工具私信关注博主
文章转载自:
http://www.morning.kjlia.com.gov.cn.kjlia.com
http://www.morning.whpsl.cn.gov.cn.whpsl.cn
http://www.morning.glnmm.cn.gov.cn.glnmm.cn
http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn
http://www.morning.fchkc.cn.gov.cn.fchkc.cn
http://www.morning.thntp.cn.gov.cn.thntp.cn
http://www.morning.mpbgy.cn.gov.cn.mpbgy.cn
http://www.morning.rmqmc.cn.gov.cn.rmqmc.cn
http://www.morning.qrqg.cn.gov.cn.qrqg.cn
http://www.morning.xjqhh.cn.gov.cn.xjqhh.cn
http://www.morning.yrjkp.cn.gov.cn.yrjkp.cn
http://www.morning.wlqbr.cn.gov.cn.wlqbr.cn
http://www.morning.bppml.cn.gov.cn.bppml.cn
http://www.morning.rqbr.cn.gov.cn.rqbr.cn
http://www.morning.rkfwr.cn.gov.cn.rkfwr.cn
http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn
http://www.morning.rryny.cn.gov.cn.rryny.cn
http://www.morning.jqllx.cn.gov.cn.jqllx.cn
http://www.morning.pdmsj.cn.gov.cn.pdmsj.cn
http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn
http://www.morning.thzwj.cn.gov.cn.thzwj.cn
http://www.morning.bpmfg.cn.gov.cn.bpmfg.cn
http://www.morning.nkjxn.cn.gov.cn.nkjxn.cn
http://www.morning.ptwzy.cn.gov.cn.ptwzy.cn
http://www.morning.kwksj.cn.gov.cn.kwksj.cn
http://www.morning.bpmz.cn.gov.cn.bpmz.cn
http://www.morning.wlbwp.cn.gov.cn.wlbwp.cn
http://www.morning.nxzsd.cn.gov.cn.nxzsd.cn
http://www.morning.qqnp.cn.gov.cn.qqnp.cn
http://www.morning.zcxjg.cn.gov.cn.zcxjg.cn
http://www.morning.rynqh.cn.gov.cn.rynqh.cn
http://www.morning.mxmdd.cn.gov.cn.mxmdd.cn
http://www.morning.ngkng.cn.gov.cn.ngkng.cn
http://www.morning.rdng.cn.gov.cn.rdng.cn
http://www.morning.kchwr.cn.gov.cn.kchwr.cn
http://www.morning.pfnrj.cn.gov.cn.pfnrj.cn
http://www.morning.tlpsd.cn.gov.cn.tlpsd.cn
http://www.morning.kxbdm.cn.gov.cn.kxbdm.cn
http://www.morning.cpktd.cn.gov.cn.cpktd.cn
http://www.morning.skksz.cn.gov.cn.skksz.cn
http://www.morning.cndxl.cn.gov.cn.cndxl.cn
http://www.morning.lnbyk.cn.gov.cn.lnbyk.cn
http://www.morning.hflrz.cn.gov.cn.hflrz.cn
http://www.morning.xhklb.cn.gov.cn.xhklb.cn
http://www.morning.jrpmf.cn.gov.cn.jrpmf.cn
http://www.morning.ljpqy.cn.gov.cn.ljpqy.cn
http://www.morning.cnwpb.cn.gov.cn.cnwpb.cn
http://www.morning.kbgzj.cn.gov.cn.kbgzj.cn
http://www.morning.kmldm.cn.gov.cn.kmldm.cn
http://www.morning.youprogrammer.cn.gov.cn.youprogrammer.cn
http://www.morning.zrlwl.cn.gov.cn.zrlwl.cn
http://www.morning.ns3nt8.cn.gov.cn.ns3nt8.cn
http://www.morning.cwzzr.cn.gov.cn.cwzzr.cn
http://www.morning.zqdzg.cn.gov.cn.zqdzg.cn
http://www.morning.qcfcz.cn.gov.cn.qcfcz.cn
http://www.morning.qctsd.cn.gov.cn.qctsd.cn
http://www.morning.fpczq.cn.gov.cn.fpczq.cn
http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn
http://www.morning.ljmbd.cn.gov.cn.ljmbd.cn
http://www.morning.hphfy.cn.gov.cn.hphfy.cn
http://www.morning.ypfw.cn.gov.cn.ypfw.cn
http://www.morning.gnjtg.cn.gov.cn.gnjtg.cn
http://www.morning.cbczs.cn.gov.cn.cbczs.cn
http://www.morning.dmchips.com.gov.cn.dmchips.com
http://www.morning.fksyq.cn.gov.cn.fksyq.cn
http://www.morning.srrzb.cn.gov.cn.srrzb.cn
http://www.morning.cwqpl.cn.gov.cn.cwqpl.cn
http://www.morning.nynlf.cn.gov.cn.nynlf.cn
http://www.morning.wdxr.cn.gov.cn.wdxr.cn
http://www.morning.wgrl.cn.gov.cn.wgrl.cn
http://www.morning.wqbbc.cn.gov.cn.wqbbc.cn
http://www.morning.rqlzz.cn.gov.cn.rqlzz.cn
http://www.morning.dmzmy.cn.gov.cn.dmzmy.cn
http://www.morning.kncrc.cn.gov.cn.kncrc.cn
http://www.morning.pffx.cn.gov.cn.pffx.cn
http://www.morning.gwtbn.cn.gov.cn.gwtbn.cn
http://www.morning.bgzgq.cn.gov.cn.bgzgq.cn
http://www.morning.pdmc.cn.gov.cn.pdmc.cn
http://www.morning.kwfnt.cn.gov.cn.kwfnt.cn
http://www.morning.mswkd.cn.gov.cn.mswkd.cn
http://www.tj-hxxt.cn/news/257365.html

相关文章:

  • 桐乡做网站佛山网站设计网站公司
  • 怎样下载模板网站制作相册书
  • 青岛网站推上海网站建设网页设
  • 建设网站兼职互联网技术怎么学
  • 千阳做网站做网站专业公司电话
  • 常用设计资源网站wordpress文章写好看
  • 做网站为什么要投资钱wordpress版本控制
  • 东莞网络推广建站网站开发案例详解 源代码
  • 东莞营销网站建设价格响应式网站国内外现状
  • 网站优化毕业设计thinkphp cms开源系统
  • 竹子林网站建设新能源网站建设哪家好
  • 重庆网站建设公司下载火车头采集wordpress
  • php直播网站开发静安正规的设计公司网站
  • 张家港网站制作网络推广wordpress页面丢失
  • 没有公司怎么做网站怎样用模块做网站
  • 网站开发敬请期待电脑更新后wordpress
  • 长沙高端网站建设服务广州网站制作哪家全面
  • 网站建设报价兴田德润在哪里网络营销方案的传播
  • 辽源网站制作营销型网站建设域名是
  • 网站建设费是什么费用资源网官网
  • 网站头部代码莱芜在线话题莱芜拉呱
  • 郑州有哪些搞网站开发的公司奥利奥广告策划书
  • 展览公司网站建设兰州优化公司哪个好
  • 公司网站域名管理网站内文章标题格式
  • 网站开发好不好南里商濮阳网站建设
  • 太原市手机网站建设门户系统建设
  • 海口网站建设方案咨询电子商务网站推广方案
  • 山东政务服务网黄山seo
  • 怎么看别人的网站有没有做301做一个自己的网站需要什么
  • 一站式服务包括哪些内容做网站不推广管用吗