private void cmdConnect_Click(object sender, RoutedEventArgs e) { if (tcpFunc != null) { tcpFunc.AutoReConnect = false; tcpFunc.Dispose(); tcpFunc = null; cmdConnect.Background = null; } else { IPAddress ip; if (!Properties.Settings.Default.Active) { ip = IPAddress.Any; } else { if (!IPAddress.TryParse(Properties.Settings.Default.IP, out ip)) { IPAddress[] addresslist = Dns.GetHostAddresses(Properties.Settings.Default.IP); foreach (var ipAddress in addresslist) { if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { ip = ipAddress; break; } } } } try { if (Properties.Settings.Default.RecieveFixedLength > 0) { tcpFunc = new TCPFunctionsAsync(SynchronizationContext.Current, ip, Int32.Parse(Properties.Settings.Default.Port), Properties.Settings.Default.Active, Properties.Settings.Default.RecieveFixedLength); } else { tcpFunc = new TCPFunctionsAsync(SynchronizationContext.Current, ip, Int32.Parse(Properties.Settings.Default.Port), Properties.Settings.Default.Active); } tcpFunc.DataRecieved += tcpFunc_DataRecieved; tcpFunc.ConnectionEstablished += tcpFunc_ConnectionEstablished; tcpFunc.ConnectionClosed += tcpFunc_ConnectionClosed; tcpFunc.AutoReConnect = true; cmdConnect.Background = Brushes.Orange; tcpFunc.Start(); } catch (Exception ex) { MessageBox.Show("Fehler Creating Connection:" + ex.Message); } } }
public void Connect() { _tcp.AutoReConnect = true; _tcp.Start(); if (_tcp != _tcpWrite && _tcpWrite != null) { _tcpWrite.AutoReConnect = true; _tcpWrite.Start(); } }
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(); }
private void cmdConnect_Click(object sender, EventArgs e) { if (myTCP_send != null) { myTCP_send.Dispose(); } if (myTCP_rec != null) { myTCP_rec.Dispose(); } myTCP_send = null; myTCP_rec = null; picConnection1.BackColor = Color.Orange; picConnection2.BackColor = Color.Orange; quittConf = new TCPFunctions.QuittConfig(); quittConf.QuittReplacmentBytes.AddRange(Settings.Default.QuittData.ToArray()); quittConf.SequenceNumberPosition = Convert.ToInt32(Settings.Default.SequenceNumberPosition); quittConf.LengthSequenceNumber = Convert.ToInt32(Settings.Default.SequenceNumberLength); quittConf.AutomaticQuitt = Settings.Default.AutomaticQuitt; myTCP_send = new TCPFunctionsAsync(SynchronizationContext.Current, Settings.Default.SendConnectionActive ? IPAddress.Parse(Settings.Default.IpAddress) : null, Convert.ToInt32(Settings.Default.SendPort), Settings.Default.SendConnectionActive); myTCP_send.DataRecieved += myTCP_TelegrammRecievedSend; myTCP_send.ConnectionEstablished += (c) => myTCP_ConnectionEstablished(1); myTCP_send.ConnectionClosed += (c) => myTCP_ConnectionClosed(1); myTCP_send.Start(); if (!Settings.Default.UseOnlyOneConnection) { myTCP_rec = new TCPFunctionsAsync(SynchronizationContext.Current, Settings.Default.RecieveConnectionActive ? IPAddress.Parse(Settings.Default.IpAddress) : null, Convert.ToInt32(Settings.Default.RecievePort), Settings.Default.RecieveConnectionActive); myTCP_rec.DataRecieved += myTCP_TelegrammRecievedRecieve; myTCP_rec.ConnectionEstablished += (c) => myTCP_ConnectionEstablished(2); myTCP_rec.ConnectionClosed += (c) => myTCP_ConnectionClosed(2); myTCP_rec.Start(); } else { //myTCP_send.DataRecieved += myTCP_TelegrammRecievedRecieve; } }
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(datasetConfig, 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) { PLCTagTriggerThread tmpTrigger = new PLCTagTriggerThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService); 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); } } }