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;
            }
相关推荐
源代码•宸15 小时前
Golang面试题库(Interface、GMP)
开发语言·经验分享·后端·面试·golang·gmp·调度过程
西京刀客15 小时前
Go 语言中的 toolchain 指令-toolchain go1.23.6的作用和目的
开发语言·后端·golang·toolchain
@ chen15 小时前
Spring MVC 核心知识
java·spring·mvc
weisian15115 小时前
JVM--2-打破刻板印象:在Java中创建一个对象,一定是分配到堆内存吗?
java·开发语言·jvm·tlab·逃逸分析·标量替换
onkel in blog15 小时前
【Java】Gradle 多模块项目实战:Spring Boot 微服务搭建全流程
java·spring boot·微服务·gradle
心语星光15 小时前
用python语言的pyautogui库实现伪批量将xdf文件打印为pdf文件
开发语言·python·pdf·自动化
想要一只奶牛猫15 小时前
Spring IOC&DI(上)
java·后端·spring
cyforkk15 小时前
10、Java 基础硬核复习:多线程(并发核心)的核心逻辑与面试考点
java·开发语言·面试
2301_8223827615 小时前
嵌入式C++实时内核
开发语言·c++·算法
Max_uuc15 小时前
【C++ 硬核】拒绝单位混淆:利用 Phantom Types (幻影类型) 实现零开销的物理量安全计算
开发语言·c++