0

I'm right now trying to read sensor data through USB-RS485 converter and utilizing the EasyModbus.dll in C#.

However, I've kept receiving CRC checked failed at the ReadHoldingRegister part. The connection and reading part is shown below.

I've already done lots of research but still can't solve the issue. Can anyone help me with this?

The CRC checked failed will occur at

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

The FT300 Modbus Setting is also shown below:

enter image description here

Image is stolen from this manual, page 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;
    }
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Harry
  • 15
  • 5
  • Please check if you can access the register using a utility such as [modpoll](https://www.modbusdriver.com/modpoll.html) - this will help confirm if the issue is with your code or something external. – Brits Sep 07 '20 at 08:10
  • I've tried other utility but none of them can reach the data. However, the official utility built by ROBOTIQ can read the data. – Harry Sep 08 '20 at 08:26
  • In that case I'd suggest contacting the vendor for guidance (if a range of utilities are failing then its likely that the issue is something other than the software). Note that the manual does mention that the "data parts of ModbusRTU messages" are sent in little endiain byte order; if that includes the CRC it would explain the error you are seeing. – Brits Sep 08 '20 at 09:30
  • @Brits Normally Modbus is in Big endian byte order. I'm not sure whether the device will be operated correctly under different endian rule. Thanks for your comment! – Harry Sep 10 '20 at 06:51

0 Answers0