java s7接收Byte字节,接收word转16位二进制

1图:

2.图:

bash 复制代码
  try {

                List list = getNameList();
				//接收base64
                S7Connector s7Connector = S7ConnectorFactory.buildTCPConnector()
                        .withHost("192.168.46.52")
                        .withPort(102)
                        .withTimeout(1000) //连接超时时间
                        .withRack(0)
                        .withSlot(3)
                        .build();

                List list1 = new ArrayList();
                byte[] cmdByte = s7Connector.read(DaveArea.DB,101,544,4848);
                for (int i = 0; i < 272; i++) {
                    int num1 = intCon.extract(Integer.class, cmdByte, 0+((i+1)-1)*2, 2+((i+1)-1)*2);
                    String binary = Integer.toBinaryString(num1);
                    String binary2 = String.format("%16s",binary).replace(' ','0');
                    String dataByte = binary2.substring(4, 5);
                    int dataByte1 = Integer.valueOf(dataByte);
                    list1.add(dataByte1);
                }
                s7Connector.close();




                S7Connector s7Connector2 = S7ConnectorFactory.buildTCPConnector()
                        .withHost("192.168.46.52")
                        .withPort(102)
                        .withTimeout(1000) //连接超时时间
                        .withRack(0)
                        .withSlot(3)
                        .build();

                List list2 = new ArrayList();
                for(int i=0; i<544; i+=2){
                    byte[] cmdByte2 = s7Connector2.read(DaveArea.DB,105,1,i);
                    list2.add(String.valueOf(cmdByte2[0]));
                }
                s7Connector2.close();

                doInsertBCU(list,list1,list2);

                sleep(5000);
            } catch (Exception e) {
                e.printStackTrace();
                //continue;
            }
相关推荐
Rain的Java大神之路3 分钟前
面了 50 个候选人,90% 都挂在 LeetCode 3 无重复字符的最长子串:滑动窗口的 5 个致命坑
java·后端·leetcode
西凉的悲伤4 分钟前
Jsoup 库 HTML 解析详解
java·前端·html·jsoup
qq_4017004110 分钟前
Qt Modbus 源码剖析:从 QModbusClient 到工业级通信框架
开发语言·qt·系统架构
星夜离尘5612 分钟前
MATLAB 角度解缠遇到丢样:先分段,再说明圈数为什么不可恢复
开发语言·matlab
十碗饭吃不饱16 分钟前
Apache POI 踩坑:setFontFamily 二次设置字体不生效、样式残留问题深度解析
java·word·apache
我命由我1234520 分钟前
6-2.Python 异常处理 - 异常捕获(捕获指定异常、常见异常类型、异常信息)
java·运维·开发语言·python·http·https·java-ee
ZoeLandia22 分钟前
React08:自定义 Hook
开发语言·前端·react.js·typescript
zaizai100736 分钟前
STL深度剖析2
java·c++·算法
染指111038 分钟前
157.Agent-LangGraph-工具(实现ReAct Agent模式)
开发语言·人工智能·python·langchain·agents
程序猿乐锅1 小时前
【从0-1学习Python | 第九篇】继承
开发语言·后端·python·学习·fastapi