Home Programming

Discussion

Left ArrowBack to discussions page
Hao0420Hao0420 Posts: 2 Recruit

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:


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;
    }

Comments

Sign In or Register to comment.
Left ArrowBack to discussions page