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;
            }
相关推荐
leaves falling7 分钟前
Qt 项目:计算圆面积
开发语言·qt
xiaoye37088 分钟前
某大厂java面试题二面20260313
java·开发语言·spring
Full Stack Developme13 分钟前
Java -jar 命令 可以有哪些参数设置
java·开发语言·jar
独隅30 分钟前
Python `with` 语句 (上下文管理器) 深度解析与避坑指南
开发语言·python
做怪小疯子33 分钟前
Python 基础学习
开发语言·python·学习
一只程序熊37 分钟前
vite-cool-unix-ctx] Unexpected token l in JSON at position 0
java·服务器·前端
晨晖242 分钟前
idea2017的下载,破解及使用
java·ide·intellij-idea
denggun123451 小时前
结构化并发(Structured Concurrency)
开发语言·ios·swift
OKkankan1 小时前
红黑树的原理及实现
开发语言·数据结构·c++·算法
摇滚侠1 小时前
Java 项目教程《黑马商城-MQ 篇》,分布式架构项目,从开发到部署
java·分布式·架构