private void cmdAddPLCStorage_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Be carefull, writing to the PLC as a Storrage is BETA and not much tested yet!"); string val = "Storage_" + (grdStorages.Items.Count + 1); if (DotNetSiemensPLCToolBoxLibrary.General.InputBox.Show("Storage-Name", "Name of the Storage", ref val) == DialogResult.OK) { foreach (var tmp in ProtokollerConfiguration.ActualConfigInstance.Storages) { if (tmp.Name.ToLower().Trim() == val.ToLower().Trim()) { MessageBox.Show("A Storage with this Name already Exists!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } PLCConnectionConfiguration myIntConfig = new PLCConnectionConfiguration(val.Trim(), LibNodaveConnectionConfigurationType.ObjectSavedConfiguration); myIntConfig = DotNetSiemensPLCToolBoxLibrary.Communication.Configuration.ShowConfiguration(myIntConfig); if (myIntConfig != null) { var storage = new PLCConfig() { Name = val }; storage.Configuration = myIntConfig; ProtokollerConfiguration.ActualConfigInstance.Storages.Add(storage); } } }
public void ConnectPlc(PLCConnectionConfiguration config) { conf = config; //_dc = new TcpNETdave(conf.CpuIP, conf.Port, conf.CpuRack, conf.CpuSlot); _dc = new TcpNETdave(conf); _dc.connectPLC(); }
public DotNetPlcSiemensInterface(string ipAddress, int rack, int slot) { IpAddress = ipAddress; Rack = rack; Slot = slot; var cfg = new PLCConnectionConfiguration { CpuIP = ipAddress, Port = 102, CpuRack = rack, CpuSlot = slot, TimeoutIPConnect = TimeSpan.FromSeconds(5), Timeout = TimeSpan.FromSeconds(5), ConnectionType = LibNodaveConnectionTypes.ISO_over_TCP, ConnectionName = "S7_Connection", Routing = false, RoutingDestinationRack = 0, RoutingDestinationSlot = 0, RoutingDestination = String.Empty }; cfg.SaveConfiguration(); _plcConnection = new PLCConnection(cfg); _dataReadTimer = new Timer(500); _dataReadTimer.Elapsed += _dataReadTimer_Elapsed; _dataReadTimer.Start(); }
private void cmdAddConnection_Click(object sender, RoutedEventArgs e) { string val = "Connection_" + (grdConnections.Items.Count + 1); if (DotNetSiemensPLCToolBoxLibrary.General.InputBox.Show("Connectionname", "Name of the PLC Connection", ref val) == DialogResult.OK) { foreach (ConnectionConfig plcConnectionConfiguration in ProtokollerConfiguration.ActualConfigInstance.Connections) { if (plcConnectionConfiguration.Name.ToLower().Trim() == val.ToLower().Trim()) { MessageBox.Show("A Connection with this Name already Exists!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } PLCConnectionConfiguration myIntConfig = new PLCConnectionConfiguration(val.Trim(), LibNodaveConnectionConfigurationType.ObjectSavedConfiguration); myIntConfig = DotNetSiemensPLCToolBoxLibrary.Communication.Configuration.ShowConfiguration(myIntConfig); if (myIntConfig != null) { LibNoDaveConfig myConfig = new LibNoDaveConfig(); myConfig.Configuration = myIntConfig; ProtokollerConfiguration.ActualConfigInstance.Connections.Add(myConfig); } //grdConnections.Items.Add(myConfig); } }
public TcpNETdave(PLCConnectionConfiguration conf)//string ip, int port, int con_rack, int con_slot) { //msgIn = new byte[daveMaxRawLen]; config = conf; connection_port = conf.Port; rack = conf.CpuRack; slot = conf.CpuSlot; plc_ip = conf.CpuIP; //context = new SynchronizationContext(); }
private void DBStructresizer_Load(object sender, EventArgs e) { lstConnections.Items.Clear(); lstConnections.Items.AddRange(PLCConnectionConfiguration.GetConfigurationNames()); if (lstConnections.Items.Count > 0) { lstConnections.SelectedItem = lstConnections.Items[0]; } }
private void button5_Click(object sender, EventArgs e) { var cfg = new PLCConnectionConfiguration() { ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration, ConnectionName = "MyPrivateConnection" }; Configuration.ShowConfiguration(cfg); myConn = new PLCConnection(cfg); }
private void cmdExportAllConnections_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = "*.connconf|*.connconf"; if (saveDlg.ShowDialog().Value) { System.IO.FileStream jj = new FileStream(saveDlg.FileName, FileMode.Create); System.Xml.Serialization.XmlSerializer myXml = new XmlSerializer(typeof(List <PLCConnectionConfiguration>)); myXml.Serialize(jj, PLCConnectionConfiguration.ExportConfigurations()); jj.Close(); } }
private void BuildConnectionList() { _connectionDictionary.Clear(); Connections = new ObservableCollection <string>(PLCConnectionConfiguration.GetConfigurationNames()); foreach (var item in Connections) { if (!DictonaryConnectionSymboltables.ContainsKey(item)) { DictonaryConnectionSymboltables.Add(item, null); } _connectionDictionary.Add(item, new PLCConnection(item)); } RefreshSymbols(); }
private void cmdConfig_Click(object sender, EventArgs e) { errtxt.Text = ""; var tmp = lstConnections.SelectedItem; Configuration.ShowConfiguration("Verbindung_1", false); lstConnections.Items.Clear(); lstConnections.Items.AddRange(PLCConnectionConfiguration.GetConfigurationNames()); if (tmp != null && lstConnections.Items.Contains(tmp)) { lstConnections.SelectedItem = tmp; } }
private void OnScanner_NewAdressFound(object sender, IPScanner.AdressFoundEventArgs e) { try { PLCConnectionConfiguration S7Setting = new PLCConnectionConfiguration(); S7Setting.ConnectionType = LibNodaveConnectionTypes.ISO_over_TCP; S7Setting.Port = 102; S7Setting.CpuIP = e.Adress.Address.ToString(); SearchCPUs(S7Setting); } catch (Exception ex) { Debug.WriteLine("An error ocurred while an new PLC was found: {0}", ex.Message); } }
private void cmdImportAllConnections_Click(object sender, RoutedEventArgs e) { OpenFileDialog opnDlg = new OpenFileDialog(); opnDlg.Filter = "Alle Unterstützten Datentypen (*.connconf)|*.connconf"; var retVal = opnDlg.ShowDialog(); if (retVal == true) { System.IO.FileStream jj = new FileStream(opnDlg.FileName, FileMode.Open); System.Xml.Serialization.XmlSerializer myXml = new XmlSerializer(typeof(List <PLCConnectionConfiguration>)); var saved = (List <PLCConnectionConfiguration>)myXml.Deserialize(jj); PLCConnectionConfiguration.ImportConfigurations(saved); this.BuildConnectionList(); } }
protected override void OnStart(string[] args) { base.OnStart(args); var cfg = new PLCConnectionConfiguration("myConnection", LibNodaveConnectionConfigurationType.ObjectSavedConfiguration); cfg.ConnectionType = LibNodaveConnectionTypes.ISO_over_TCP; cfg.CpuIP = "192.168.1.185"; cfg.CpuSlot = 2; myConn = new PLCConnection(cfg); myConn.Connect(); threadShouldRun = true; myThread = new Thread(new ThreadStart(this.ThreadProc)); myThread.Start(); }
private void configConnectionToolStripMenuItem_Click(object sender, EventArgs e) { myConn = null; var tmp = lstConnections.SelectedItem; Configuration.ShowConfiguration("Verbindung_1", false); lstConnections.Items.Clear(); var lstConn = PLCConnectionConfiguration.GetConfigurationNames(); if (lstConn != null) { lstConnections.Items.AddRange(lstConn); } if (tmp != null && lstConnections.Items.Contains(tmp)) { lstConnections.SelectedItem = tmp; } }
private void Form1_Load(object sender, EventArgs e) { tableLayoutPanelVisu.ColumnStyles[1].Width = 0; lstConnections.Items.Clear(); var itms = PLCConnectionConfiguration.GetConfigurationNames(); if (itms != null) { lstConnections.Items.AddRange(itms); } if (lstConnections.Items.Count > 0) { lstConnections.SelectedItem = lstConnections.Items[0]; } try { if (Settings.Default.OpenedProjects != null) { foreach (string prj in Settings.Default.OpenedProjects) { loadPrj(prj); } } } catch (Exception ex) { lblStatus.Text = ex.Message; } if (!string.IsNullOrEmpty(Settings.Default.ProjectsPath)) { lstProjects.Items.Clear(); lstProjects.Items.AddRange(Projects.GetStep7ProjectsFromDirectory(Settings.Default.ProjectsPath)); } }
public FetchWriteConnection(PLCConnectionConfiguration configuration) { this._tcp = new TCPFunctionsAsync(null, IPAddress.Parse(configuration.CpuIP), configuration.Port, true); _tcp.ConnectionEstablished += _tcp_ConnectionEstablished; _tcp.ConnectionClosed += _tcp_ConnectionClosed; _tcp.DoNotUseRecieveEvent = true; _tcp.UseKeepAlive = true; if (configuration.WritePort != 0) { if (configuration.WritePort == configuration.Port) { _tcpWrite = _tcp; } else { this._tcpWrite = new TCPFunctionsAsync(null, IPAddress.Parse(configuration.CpuIP), configuration.WritePort, true); _tcpWrite.DoNotUseRecieveEvent = true; _tcpWrite.UseKeepAlive = true; } _tcpWrite.ConnectionEstablished += _tcpWrite_ConnectionEstablished; _tcpWrite.ConnectionClosed += _tcpWrite_ConnectionClosed; } }
/// <summary> /// Go through all reasonable Configurations for S7 Connections, and return one that works /// </summary> /// <param name="plcConfig"></param> private void SearchCPUs(PLCConnectionConfiguration plcConfig) { //go through Slot 0 to 5 and return all found CPU's, this is because S7-400 may have several CPU's in different Slots in one rack for (int i = 0; i <= 5; i++) { PLCConnectionConfiguration Conf = new PLCConnectionConfiguration(); Conf.ConnectionType = plcConfig.ConnectionType; Conf.CpuIP = plcConfig.CpuIP; Conf.Port = plcConfig.Port; Conf.CpuRack = plcConfig.CpuRack; Conf.CpuSlot = i; PLCConnection Con = new PLCConnection(Conf); try { Con.Connect(); FoundPlc FoundPlc = new FoundPlc(); FoundPlc.S7ConnectionSettings = Conf; //Read name of PLC var HWInfos = Con.PLCGetSZL(0x1c, 0); foreach (xy1CDataset HWInfo in HWInfos.SZLDaten) { switch (HWInfo.Index) { case 1: FoundPlc.S7ConnectionSettings.ConnectionName = HWInfo.Text; FoundPlc.PlcName = HWInfo.Text; break; case 2: FoundPlc.ModuleName = HWInfo.Text; break; case 3: FoundPlc.PlantIdentification = HWInfo.Text; break; case 4: FoundPlc.Copyright = HWInfo.Text; break; case 5: FoundPlc.ModuleSerialNumber = HWInfo.Text; break; case 6: break; case 7: FoundPlc.ModuleTypeName = HWInfo.Text; break; case 8: break; case 9: FoundPlc.Manufacturer = HWInfo.Text; break; case 10: break; case 11: FoundPlc.Location = HWInfo.Text; break; } } //Check if we actually found an CPU //This is because some S7-400 CPUs also accept connections to Modules other than CPU, such as CP or similiar. But //these are not wat we are looking for. if (!FoundPlc.ModuleTypeName.ToLower().Contains("cpu") && !FoundPlc.ModuleName.ToLower().Contains("cpu")) { Debug.WriteLine("Found an available interface that accepted the connection but apparently was not an CPU. The adress was {0} and the Slot was {1}", plcConfig.CpuIP, plcConfig.CpuSlot); continue; } lock (_DiscoveredPLCs) { _DiscoveredPLCs.Add(FoundPlc); } NewPlcFound?.Invoke(this, new PlcFoundEventArgs { FoundPlc = FoundPlc }); System.Threading.Thread.Sleep(100); //Some CPUs, especially IBH Softec Simulatin CPUs dont like it when the request are coming to fast. IBH chrashes } catch (Exception ex) { continue;//Ignore erorr and try next Slot } finally { Con.Disconnect(); } } }
private void Button_Click(object sender, RoutedEventArgs e) { Configuration.ShowConfiguration(); this.Connections = new ObservableCollection <string>((IEnumerable <string>)PLCConnectionConfiguration.GetConfigurationNames()); }
public DockableContentOnlineConnections() { this.Connections = new ObservableCollection <string>((IEnumerable <string>)PLCConnectionConfiguration.GetConfigurationNames()); InitializeComponent(); this.DataContext = this; }