Beispiel #1
0
        private void btSaveAll_Click(object sender, RoutedEventArgs e)
        {
            modbusResponseGrid MrGrid = new modbusResponseGrid();

            btSaveAll.IsEnabled = false;

            int          lstCnt   = grdModbus.Items.Count;
            StreamWriter confFile = new StreamWriter("MBResponse.csv");

            // write Header
            confFile.Write("Register Address" + ";" + " Value in Decimal" + ";" + "Value in Hex" + " \n");

            for (int i = 0; i < lstCnt; i++)
            {
                MrGrid = (modbusResponseGrid)grdModbus.Items.GetItemAt(i);

                try
                {
                    confFile.Write(MrGrid.regAdd + ";" + MrGrid.val + ";" + MrGrid.valHex + " \n");
                }
                catch (excepetion ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            confFile.Close();
            btSaveAll.IsEnabled = true;
            MessageBox.Show(" data grid saved in .csv file in parenet folder of exe file ");
        }
Beispiel #2
0
        private void btAdd_Click(object sender, RoutedEventArgs e)
        {
            modbusResponseGrid msGrid = new modbusResponseGrid();

            msGrid.regAdd = 500.ToString();
            msGrid.val    = 100.ToString();
            msGrid.valHex = utility.U16ToHex(100);
            grdModbus.Items.Add(msGrid);
        }
Beispiel #3
0
        private void handleModbusReadRequest(ushort startAdd, ushort nReg, ushort [] rxBuf)
        {
            int rxReg = -1;

            try
            {
                rxReg = mrAccess.readModbusRegister(startAdd, nReg, rxBuf);
                if (rxReg == -1)
                {
                    switch (rxBuf[0])
                    {
                    case 1:
                        lblMBException.Content = "ILLEGAL FUNCTION";
                        break;

                    case 2:
                        lblMBException.Content = "ILLEGAL DATA ADDRESS";
                        break;

                    case 3:
                        lblMBException.Content = "ILLEGAL DATA VALUE";
                        break;

                    case 4:
                        lblMBException.Content = "SLAVE DEVICE FAILURE";
                        break;

                    case 6:
                        lblMBException.Content = "SLAVE DEVICE BUSY";
                        break;

                    default:
                        lblMBException.Content = rxBuf[0].ToString();
                        break;
                    }
                }
                else
                {
                    lblMBException.Content = "Success !";
                    modbusResponseGrid[] msGrid = new modbusResponseGrid[nReg];
                    for (int i = 0; i < nReg; i++)
                    {
                        msGrid[i]        = new modbusResponseGrid();
                        msGrid[i].regAdd = (startAdd + i).ToString();
                        msGrid[i].val    = rxBuf[i].ToString();
                        msGrid[i].valHex = utility.U16ToHex(rxBuf[i]);
                        grdModbus.Items.Add(msGrid[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #4
0
        private void handleDGChnage_DBClick(object sender, MouseButtonEventArgs e)
        {
            int index = grdModbus.SelectedIndex;

            if (index >= 0)
            {
                modbusResponseGrid entry = (modbusResponseGrid)grdModbus.Items[index];
                mbWriteWin         win2  = new mbWriteWin();
                win2.txtmbAdd.Text        = entry.regAdd.ToString();
                win2.txtVal.Text          = entry.val.ToString();
                win2.txtValHex.Text       = entry.valHex.ToString();
                win2.slaveInfo.slaveIPAdd = txtSlaveIP.Text.ToString();
                win2.slaveInfo.tcpPortId  = 502;
                win2.slaveInfo.slaveUid   = 1;
                win2.Show();
            }
        }