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;
            }
相关推荐
阿杆3 小时前
如何在 Spring Boot 中接入 Amazon ElastiCache
java·数据库·redis
cheems95273 小时前
锁策略的介绍
java·开发语言
清水白石0083 小时前
《Python × 数据库:用 SQLAlchemy 解锁高效 ORM 编程的艺术》
开发语言·python·json
武子康4 小时前
Java-199 JMS Queue/Topic 集群下如何避免重复消费:ActiveMQ 虚拟主题与交付语义梳理
java·分布式·消息队列·rabbitmq·activemq·mq·java-activemq
风中月隐4 小时前
C语言中以坐标的方式图解“字母金字塔”的绘制
c语言·开发语言·算法·字母金子塔·坐标图解法
LSL666_4 小时前
12 MyBatis的连接池
java·服务器·mybatis
Arva .4 小时前
说说线程的生命周期和状态
java·开发语言
1001101_QIA4 小时前
C++中不能复制只能移动的类型
开发语言·c++
tryxr4 小时前
HashTable、HashMap、ConcurrentHashMap 之间的区别
java·开发语言·hash
serendipity_hky4 小时前
【go语言 | 第5篇】channel——多个goroutine之间通信
开发语言·后端·golang