Exemplo n.º 1
0
        private void RemoveModule(ModbusSlave module)
        {
            moduleList.Remove(module);
            module.Dispose();

            OnConnectionChange();
        }
Exemplo n.º 2
0
        private void ListenClinetConnect()
        {
            TcpClient tcpClient;
            while (fWaiting)
            {
                try
                {
                    tcpClient = tcpListener.AcceptTcpClient();
                }
                catch (Exception)
                {
                    break;
                }

                //For every client, create a new receive data thread
                ModbusSlave module = new ModbusSlave(tcpClient);
                moduleList.Add(module);
                OnConnectionChange();
                Task newCommunication = communicateTask.StartNew(() =>
                    {
                        GetModbusData(module);
                    },
                    TaskCreationOptions.PreferFairness | TaskCreationOptions.LongRunning | TaskCreationOptions.AttachedToParent);
                //for .Net 3.5 or ealer;
                //ThreadPool.QueueUserWorkItem(new WaitCallback(GetModbusData), module);
            }
        }