예제 #1
0
 private void UpdateDataGridView(object sender)
 {
     for (int i = 0; i < dataGridView1.RowCount - 1; i++)
     {
         foreach (ConnectionProperties connectionProperty in easyModbusManager.connectionPropertiesList)
         {
             if (dataGridView1[0, i].Value != null)
             {
                 if (connectionProperty.ConnectionName.Equals(dataGridView1[0, i].Value.ToString()))
                 {
                     foreach (FunctionProperties functionProperty in connectionProperty.FunctionPropertiesList)
                     {
                         if (dataGridView1[1, i].Value != null)
                         {
                             for (int j = 0; j < functionProperty.Quantity; j++)
                             {
                                 if (EasyModbusManager.getAddress(functionProperty.FunctionCode, functionProperty.StartingAdress, functionProperty.Quantity, j).Equals(dataGridView1[1, i].Value.ToString()))
                                 {
                                     if (functionProperty.values.GetType().Equals(typeof(Boolean[])))
                                     {
                                         dataGridView1[4, i].Value = ((bool[])functionProperty.values)[j].ToString();
                                     }
                                     else
                                     {
                                         if (dataGridView1[3, i].Value != null)
                                         {
                                             if (dataGridView1[3, i].Value.Equals("UINT16 (0...65535)"))
                                             {
                                                 if (((int[])functionProperty.values)[j] < 0)
                                                 {
                                                     dataGridView1[4, i].Value = (65536 + ((int[])functionProperty.values)[j]).ToString();
                                                 }
                                                 else
                                                 {
                                                     dataGridView1[4, i].Value = ((int[])functionProperty.values)[j].ToString();
                                                 }
                                             }
                                             else
                                             {
                                                 dataGridView1[4, i].Value = ((int[])functionProperty.values)[j].ToString();
                                             }
                                         }
                                         else
                                         {
                                             dataGridView1[4, i].Value = ((int[])functionProperty.values)[j].ToString();
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 private void UpdateDataGridView(object sender)
 {
     for (int i = 0; i < dataGridView1.RowCount - 1; i++)
     {
         foreach (ConnectionProperties connectionProperty in easyModbusManager.connectionPropertiesList)
         {
             if (dataGridView1[0, i].Value != null)
             {
                 if (connectionProperty.ConnectionName.Equals(dataGridView1[0, i].Value.ToString()))
                 {
                     foreach (FunctionProperties functionProperty in connectionProperty.FunctionPropertiesList)
                     {
                         if (dataGridView1[1, i].Value != null)
                         {
                             for (int j = 0; j < functionProperty.Quantity; j++)
                             {
                                 if (EasyModbusManager.getAddress(functionProperty.FunctionCodeRead, functionProperty.StartingAdress, functionProperty.Quantity, j).Equals(dataGridView1[1, i].Value.ToString()))
                                 {
                                     functionProperty.DataGridRow = i;
                                     if (functionProperty.values.GetType().Equals(typeof(Boolean[])))
                                     {
                                         dataGridView1[4, i].Value = ((bool[])functionProperty.values)[j].ToString();
                                     }
                                     else
                                     {
                                         if (dataGridView1[3, i].Value != null)
                                         {
                                             if (dataGridView1[3, i].Value.Equals("UINT16 (0...65535)"))
                                             {
                                                 if (((int[])functionProperty.values)[j] < 0)
                                                 {
                                                     dataGridView1[4, i].Value = (65536 + ((int[])functionProperty.values)[j]).ToString();
                                                 }
                                                 else
                                                 {
                                                     dataGridView1[4, i].Value = ((int[])functionProperty.values)[j].ToString();
                                                 }
                                             }
                                             else if (dataGridView1[3, i].Value.Equals("ASCII"))
                                             {
                                                 string str = "";
                                                 for (int tt = 0; tt < ((int[])functionProperty.values).Length; tt++)
                                                 {
                                                     int value = ((int[])functionProperty.values)[tt];
                                                     str += "" + (char)((value & 0xff00) >> 8) + (char)((value & 0x00ff));
                                                 }
                                                 dataGridView1[4, i].Value = "" + str;
                                             }
                                             else
                                             {
                                                 dataGridView1[4, i].Value = ((int[])functionProperty.values)[j].ToString();
                                             }
                                         }
                                         else
                                         {
                                             dataGridView1[4, i].Value = ((int[])functionProperty.values)[j].ToString();
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }