zoukankan      html  css  js  c++  java
  • C# 读取Modbus

               using (TcpClient client = new TcpClient("127.0.0.1", 1502))
                {
                    var factory = new ModbusFactory();
                    IModbusMaster master = factory.CreateMaster(client);
    
                    // read five input values
                    ushort startAddress = 100;
                    ushort numInputs = 5;
                    //bool[] inputs = master.ReadInputs(1, startAddress, numInputs);
    
                    ushort[] registers = master.ReadHoldingRegisters(1, 4003, 1);
    
                   
                   
                }
    
                for (int i = 0; i < this.dataGridViewReadConfig.Rows.Count-1; i++)
                {
                    string unit = textBoxUnit.Text.ToString();
                    string startAddress = this.dataGridViewReadConfig.Rows[i].Cells[1].Value.ToString();
                  
                    string number = this.dataGridViewReadConfig.Rows[i].Cells[2].Value.ToString();
                    var shortData = client.ReadHoldingRegisters<ushort>(1, 4003,  1);
    
                    foreach (var item in shortData)
                    {
                        this.dataGridViewReadConfig.Rows[i].Cells[4].Value = item+",";
                    }
                   
                }
    
    		使用组件库
    		FluentModbus
    		NModbus
    本博客是个人工作中记录,遇到问题可以互相探讨,没有遇到的问题可能没有时间去特意研究,勿扰。
    另外建了几个QQ技术群:
    2、全栈技术群:616945527,加群口令abc123
    2、硬件嵌入式开发: 75764412
    3、Go语言交流群:9924600

    闲置域名www.nsxz.com出售(等宽等高字符四字域名)。
  • 相关阅读:
    JavaScript作用域
    JavaScript数据类型
    CSS页面布局(二)
    CSS页面布局(一)
    CCS界面组件
    JavaScript面向对象设计
    python-序列化与反序列化
    python-常用模块
    python-re模块
    python-匿名函数
  • 原文地址:https://www.cnblogs.com/zhaogaojian/p/15655226.html
Copyright © 2011-2022 走看看