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;
            }
相关推荐
CodeBlossom4 分钟前
java加强 -stream流
java·windows·python
lsswear6 分钟前
php fiber 应用
开发语言·php
(・Д・)ノ11 分钟前
python打卡day28
开发语言·python
理想奋斗中14 分钟前
idea中Lombok失效的解决方案
java·intellij-idea·lombok
保利九里15 分钟前
java中的方法详解
java·开发语言·python
旋风菠萝17 分钟前
项目复习(1)
java·数据库·八股·八股文·复习·项目、
灏瀚星空27 分钟前
Python标准库完全指南:os、sys与math模块详解与实战应用
开发语言·python·microsoft
坐吃山猪29 分钟前
Python-Flask-Dive
开发语言·python·flask
Chandler2438 分钟前
Go语言 GORM框架 使用指南
开发语言·后端·golang·orm
.又是新的一天.1 小时前
使用IDEA创建Maven版本的web项目以及lombok的使用
java·maven·intellij-idea