0

我现在正在尝试通过 USB-RS485 转换器读取传感器数据并使用 C# 中的EasyModbus.dll

但是,我一直收到CRC 检查失败ReadHoldingRegister部分。连接和读取部分如下图所示。

我已经做了很多研究,但仍然无法解决问题。谁能帮我这个?

CRC校验失败将发生在

int[] Read = modbusClient.ReadHoldingRegisters(179, 6);

FT300 Modbus 设置也如下所示:

在此处输入图像描述

图片来自本手册,第 34 页

   void getavailableports() // get available COM
   {
        comboBox1.Items.Clear();
        string[] ports = SerialPort.GetPortNames();
        comboBox1.Items.AddRange(ports);
   }
   private void comboBox1_MouseClick(object sender, MouseEventArgs e) //let user choose COM
   {
        getavailableports();
   }
   private void Start_Click(object sender, EventArgs e) // Start button being pressed
   {
        try
        {
            Invoke(new EventHandler(ChangeColor));
            //FT300Port.PortName = comboBox1.Text;
            //.BaudRate = Convert.ToInt32(BaudRate.Text);
            //FT300Port.Open();
            modbusClient.UnitIdentifier = 9; // default slaveID = 1
            modbusClient.Baudrate = Convert.ToInt32(BaudRate.Text); // default baudrate = 9600
            modbusClient.Parity = System.IO.Ports.Parity.None;
            modbusClient.StopBits = System.IO.Ports.StopBits.One;
            modbusClient.ConnectionTimeout = 500;
            modbusClient.Connect();
            lb_status.Text = "Connected";
            timer_Modbus.Enabled = true;
        }
        catch(Exception ex)
        {
            lb_status.Text = ex.ToString();
            throw;
        }
    }
    private void ChangeColor(object sender, EventArgs e)
    {
        Start.Text = "Streaming";
        Start.BackColor = Color.Red;
    }
    private void Disconnect_Click(object sender, EventArgs e)
    {
        modbusClient.Disconnect();
        Start.Text = "Start";
        Start.BackColor = Color.DarkGray;
        lb_status.Text = "Disconnected";
        timer_Modbus.Enabled = false;
    }
    private void timer_Modbus_Tick(object sender, EventArgs e)
    {
        timer_Modbus.Enabled = false;

        //modbusClient.WriteMultipleCoils(179, new bool[] { true, true, true, true, true, true});    
        //Write Coils starting with Address 180
        //bool[] readCoils = modbusClient.ReadCoils(179, 6);
        **int[] Read = modbusClient.ReadHoldingRegisters(179, 6);**

      /*textBox1.Text = Convert.ToString(Read[0]);
        textBox2.Text = Convert.ToString(Read[1]);
        textBox3.Text = Convert.ToString(Read[2]);
        textBox4.Text = Convert.ToString(Read[3]);
        textBox5.Text = Convert.ToString(Read[4]);
        textBox6.Text = Convert.ToString(Read[5]);*/

        timer_Modbus.Enabled = true;
    }
4

0 回答 0