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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM