Example #1
0
        protected override void OnStart(string[] args)
        {
            tcp1 = new TCPFunctionsAsync(null, IPAddress.Parse(Settings.Default.SourceIP), Settings.Default.SourcePort,
                                         Settings.Default.SourceActive);
            tcp2 = new TCPFunctionsAsync(null, IPAddress.Parse(Settings.Default.DestinationIP), Settings.Default.DestinationPort,
                                         Settings.Default.DestinationActive);

            tcp1.DataRecieved += (data, tcpClient) => tcp2.SendData(data);
            tcp2.DataRecieved += (data, tcpClient) => tcp1.SendData(data);

            tcp1.Start();
            tcp2.Start();
        }
Example #2
0
 private void cmdConnect_Click(object sender, EventArgs e)
 {
     if (tcpFunc != null)
     {
         tcpFunc.AutoReConnect = false;
         tcpFunc.Dispose();
         tcpFunc = null;
         cmdConnect.BackColor = Color.FromArgb(224, 224, 224);
     }
     else
     {
         tcpFunc = new TCPFunctionsAsync(SynchronizationContext.Current, IPAddress.Parse(txtIP.Text), Int32.Parse(txtPort.Text), chkActive.Checked);
         tcpFunc.DataRecieved += tcpFunc_DataRecieved;
         tcpFunc.ConnectionEstablished += tcpFunc_ConnectionEstablished;
         tcpFunc.ConnectionClosed += tcpFunc_ConnectionClosed;
         tcpFunc.AutoReConnect = true;
         cmdConnect.BackColor = Color.Orange;
         tcpFunc.Start();
     }
 }
        private void OpenStoragesAndCreateTriggers(bool CreateTriggers, bool StartedAsService)
        {
            foreach (DatasetConfig datasetConfig in akConfig.Datasets)
            {
                try
                {
                    IDBInterface akDBInterface = null;

                    akDBInterface = StorageHelper.GetStorage(akConfig, datasetConfig.Storage, RemotingServer.ClientComms.CallNotifyEvent);
                    akDBInterface.ThreadExceptionOccured += new ThreadExceptionEventHandler(tmpTrigger_ThreadExceptionOccured);

                    DatabaseInterfaces.Add(datasetConfig, akDBInterface);

                    Logging.LogText("DB Interface: " + datasetConfig.Name + " is starting...", Logging.LogLevel.Information);

                    akDBInterface.Initiate(datasetConfig);

                    if (CreateTriggers)
                        if (datasetConfig.Trigger == DatasetTriggerType.Tags_Handshake_Trigger || datasetConfig.Trigger == DatasetTriggerType.Tags_Handshake_Trigger_only_one_Tag)
                        {
                            PLCTagTriggerThread tmpTrigger = new PLCTagTriggerThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService, datasetConfig.Trigger == DatasetTriggerType.Tags_Handshake_Trigger_only_one_Tag);
                            tmpTrigger.StartTrigger();
                            tmpTrigger.ThreadExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            myDisposables.Add(tmpTrigger);
                        }
                        else if (datasetConfig.Trigger == DatasetTriggerType.Time_Trigger)
                        {
                            TimeTriggerThread tmpTrigger = new TimeTriggerThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService);
                            tmpTrigger.StartTrigger();
                            tmpTrigger.ThreadExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            myDisposables.Add(tmpTrigger);
                        }
                        else if (datasetConfig.Trigger == DatasetTriggerType.Time_Trigger_With_Value_Comparison)
                        {
                            TimeTriggerWithCheckForChangesThread tmpTrigger = new TimeTriggerWithCheckForChangesThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService);
                            tmpTrigger.StartTrigger();
                            tmpTrigger.ThreadExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            myDisposables.Add(tmpTrigger);
                        }
                        else if (datasetConfig.Trigger == DatasetTriggerType.Quartz_Trigger)
                        {
                            QuartzTriggerThread tmpTrigger = new QuartzTriggerThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService);
                            tmpTrigger.StartTrigger();
                            tmpTrigger.ThreadExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            myDisposables.Add(tmpTrigger);
                        }
                        else if (datasetConfig.Trigger == DatasetTriggerType.Triggered_By_Incoming_Data_On_A_TCPIP_Connection)
                        {
                            TCPIPConfig tcpipConnConf = datasetConfig.TriggerConnection as TCPIPConfig;

                            tcpipConnConf.MultiTelegramme = tcpipConnConf.MultiTelegramme <= 0 ? 1 : tcpipConnConf.MultiTelegramme;

                            if (tcpipConnConf.MultiTelegramme == 0)
                                tcpipConnConf.MultiTelegramme = 1;
                            TCPFunctionsAsync tmpConn = new TCPFunctionsAsync(null, tcpipConnConf.IPasIPAddress, tcpipConnConf.Port, !tcpipConnConf.PassiveConnection, tcpipConnConf.DontUseFixedTCPLength ? -1 : ReadData.GetCountOfBytesToRead(datasetConfig.DatasetConfigRows) * tcpipConnConf.MultiTelegramme);
                            tmpConn.AllowMultipleClients = tcpipConnConf.AcceptMultipleConnections;
                            tmpConn.UseKeepAlive = tcpipConnConf.UseTcpKeepAlive;
                            tmpConn.AsynchronousExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            tmpConn.AutoReConnect = true;
                            var conf = datasetConfig;
                            tmpConn.DataRecieved += (bytes, tcpClient) =>
                                                        {
                                                            if (tcpipConnConf.MultiTelegramme == 0)
                                                                tcpipConnConf.MultiTelegramme = 1;
                                                            for (int j = 1; j <= tcpipConnConf.MultiTelegramme; j++)
                                                            {
                                                                var ln = bytes.Length / tcpipConnConf.MultiTelegramme;
                                                                byte[] tmpArr = new byte[ln];
                                                                Array.Copy(bytes, ((j - 1) * ln), tmpArr, 0, ln);

                                                                IEnumerable<object> values = ReadData.ReadDataFromByteBuffer(conf, conf.DatasetConfigRows, tmpArr, StartedAsService);
                                                                if (values != null)
                                                                    akDBInterface.Write(values);
                                                            }
                                                        };
                            tmpConn.ConnectionEstablished += (TcpClient tcp) =>
                                                                 {
                                                                     Logging.LogText("Connection established: " + tcpipConnConf.IPasIPAddress + ", " + tcpipConnConf.Port, Logging.LogLevel.Information);
                                                                 };
                            tmpConn.ConnectionClosed += (TcpClient tcp) =>
                                                            {
                                                                Logging.LogText("Connection closed: " + tcpipConnConf.IPasIPAddress + ", " + tcpipConnConf.Port, Logging.LogLevel.Information);
                                                            };
                            Logging.LogText("Connection prepared: " + tcpipConnConf.IPasIPAddress + ", " + tcpipConnConf.Port, Logging.LogLevel.Information);
                            tmpConn.Start();
                            ConnectionList.Add(tcpipConnConf, tmpConn);
                            myDisposables.Add(tmpConn);
                        }
                }
                catch (Exception ex)
                {
                    Logging.LogText("Error in OpenStorragesAndCreateTriggers occured!", ex, Logging.LogLevel.Error);
                }
            }
        }