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;
            }
相关推荐
思麟呀几秒前
C++工业级日志项目(四)日志落地
linux·开发语言·c++·windows
小熊Coding4 分钟前
Python二手图书市场行为分析系统
开发语言·爬虫·python·django·计算机毕业设计·数据可视化分析·二手图书分析系统
AllData公司负责人7 分钟前
亲测丝滑,体验跃迁|AllData通过集成开源项目Cube-Studio,降低机器学习落地门槛
java·大数据·数据库·人工智能·机器学习·开源·cube-studio
MC皮蛋侠客18 分钟前
C++17 多线程系列(二):共享数据与同步——mutex 与 condition_variable
开发语言·c++·多线程
愈努力俞幸运20 分钟前
python 三引号
android·开发语言·python
止语Lab23 分钟前
Go跨平台编译的决策树:从\
开发语言·决策树·golang
Das124 分钟前
【408】C语言标识符
c语言·开发语言
zxd02031129 分钟前
DevOps + CI/CD:从理念到 Jenkins 实战落地
java·开发语言
qq_白羊座29 分钟前
GitLab CI + Jenkins 双流水线模式Jenkins 端实现
java·开发语言
say_fall29 分钟前
8086汇编程序设计_从基础到实战
开发语言·汇编·8086