Esempio n. 1
0
 private void GetValuesThread(object obj)
 {
     if (locked)
     {
         System.Threading.Thread.Sleep(100);
     }
     if (!locked)
     {
         locked = true;
     }
     lock (locker) {
         GetValuesThreadObject getValuesThreadObject = (GetValuesThreadObject)obj;
         try {
             if (getValuesThreadObject.functionPropertyIndex != 0)
             {
                 easyModbusManager.GetValues(getValuesThreadObject.connectionProperty, getValuesThreadObject.functionPropertyIndex);
             }
             else
             {
                 easyModbusManager.GetValues(getValuesThreadObject.connectionProperty);
             }
         } catch (Exception exc) {
             getValuesThreadObject.connectionProperty.timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
             getValuesThreadObject.connectionProperty.modbusClient.Disconnect();
             MessageBox.Show(exc.Message, "Exception Reading values", MessageBoxButtons.OK, MessageBoxIcon.Error);
         } finally {
             UpdateNodesConnectedStatus();
             locked = false;
         }
         locked = false;
     }
 }
Esempio n. 2
0
        void StartSingleJobToolStripMenuItemClick(object sender, EventArgs e)
        {
            GetValuesThreadObject getValuesThreadObject = new GetValuesThreadObject();

            getValuesThreadObject.connectionProperty    = easyModbusManager.connectionPropertiesList[treeView1.SelectedNode.Parent.Index];
            getValuesThreadObject.functionPropertyIndex = treeView1.SelectedNode.Index;
            if (getValuesThreadObject.connectionProperty.timer == null)
            {
                getValuesThreadObject.connectionProperty.timer = new System.Threading.Timer(GetValuesThread, getValuesThreadObject, easyModbusManager.connectionPropertiesList[treeView1.SelectedNode.Parent.Index].CycleTime, easyModbusManager.connectionPropertiesList[treeView1.SelectedNode.Parent.Index].CycleTime);
            }
            else
            {
                getValuesThreadObject.connectionProperty.timer.Change(easyModbusManager.connectionPropertiesList[treeView1.SelectedNode.Parent.Index].CycleTime, easyModbusManager.connectionPropertiesList[treeView1.SelectedNode.Parent.Index].CycleTime);
            }
            getValuesThreadObject.connectionProperty.modbusClient.ReceiveDataChanged -= new EasyModbusSecure.ModbusClient.ReceiveDataChangedHandler(UpdateTextBoxReceive);
            getValuesThreadObject.connectionProperty.modbusClient.SendDataChanged    -= new EasyModbusSecure.ModbusClient.SendDataChangedHandler(UpdateTextBoxSend);
        }
Esempio n. 3
0
 void StartAllJobsToolStripMenuItemClick(object sender, EventArgs e)
 {
     foreach (ConnectionProperties connectionProperty in easyModbusManager.connectionPropertiesList)
     {
         connectionProperty.modbusClient.ReceiveDataChanged += new EasyModbusSecure.ModbusClient.ReceiveDataChangedHandler(UpdateTextBoxReceive);
         connectionProperty.modbusClient.SendDataChanged    += new EasyModbusSecure.ModbusClient.SendDataChangedHandler(UpdateTextBoxSend);
         GetValuesThreadObject getValuesThreadObject = new GetValuesThreadObject();
         getValuesThreadObject.connectionProperty = connectionProperty;
         if (connectionProperty.timer == null)
         {
             connectionProperty.timer = new System.Threading.Timer(GetValuesThread, getValuesThreadObject, connectionProperty.CycleTime, connectionProperty.CycleTime);
         }
         else
         {
             connectionProperty.timer.Change(connectionProperty.CycleTime, connectionProperty.CycleTime);
         }
     }
     UpdateNodesConnectedStatus();
 }