public DataBlockValueSaver(string ConnectionName) { this.ConnectionName = ConnectionName; InitializeComponent(); myConn = new PLCConnection(ConnectionName); }
public void TestReading3() { var wrapper = new ConnectionWrapper(480); var conn = new PLCConnection(new PLCConnectionConfiguration(), wrapper); var listTag = new List <PLCTag>(); listTag.Add(new PLCTag("DB781.DBX5.0")); listTag.Add(new PLCTag("DB781.DBX7.0")); listTag.Add(new PLCTag("DB781.DBX9.0")); listTag.Add(new PLCTag("DB781.DBX11.0")); listTag.Add(new PLCTag("DB781.DBX13.0")); listTag.Add(new PLCTag("DB781.DBX4.2")); listTag.Add(new PLCTag("DB781.DBX6.2")); listTag.Add(new PLCTag("DB781.DBX8.2")); listTag.Add(new PLCTag("DB781.DBX10.2")); listTag.Add(new PLCTag("DB781.DBX12.2")); listTag.Add(new PLCTag("DB781.DBX3.1")); listTag.Add(new PLCTag("DB781.DBX5.1")); listTag.Add(new PLCTag("DB781.DBX7.1")); listTag.Add(new PLCTag("DB781.DBX9.1")); listTag.Add(new PLCTag("DB781.DBX11.1")); listTag.Add(new PLCTag("DB781.DBX13.1")); conn.ReadValues(listTag, true); var pdus = wrapper.PDUs; string req = string.Join(Environment.NewLine, pdus); string t = "READ Area:132, DBnum:781, Start:3, Bytes:11"; Assert.AreEqual(req, t); }
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 mnuConfig_Click(object sender, RoutedEventArgs e) { App.clientForm.lblStatus.Text = ""; Configuration.ShowConfiguration("WPFToolboxForSiemensPLCs", true); Connection = new PLCConnection("WPFToolboxForSiemensPLCs"); }
private void button2_Click(object sender, EventArgs e) { try { PLCConnection myConn = new PLCConnection(lstConnections.SelectedItem.ToString()); myConn.Connect(); int anz = readBytes.Length / Convert.ToInt32(txtSize.Text); int olen = Convert.ToInt32(txtSize.Text); int len = Convert.ToInt32(txtNewSize.Text); for (int n = 0; n < anz; n++) { PLCTag plcTag = new PLCTag() { TagDataType = TagDataType.ByteArray, TagDataSource = MemoryArea.Datablock, DataBlockNumber = Convert.ToInt32(txtDB.Text), ByteAddress = Convert.ToInt32(txtStartByte.Text) + n * Convert.ToInt32(txtNewSize.Text), ArraySize = Convert.ToInt32(txtSize.Text) }; byte[] ctrlV = new byte[len]; Array.Copy(readBytes, olen * n, ctrlV, 0, olen); plcTag.Controlvalue = ctrlV; myConn.WriteValue(plcTag); } lblState.Text = anz.ToString() + " Strukturen a " + len.ToString() + " Bytes geschrieben!"; } catch (Exception ex) { lblState.Text = ex.Message; } }
private void button4_Click(object sender, EventArgs e) { myConn = new PLCConnection("SimpleCSharpDemonstrationConnection"); myConn.Connect(); //var _tags = new List<PLCTag>(); //var j = 0; //for (var i = 0; i < 96; i++) //{ // Console.WriteLine("DB1.DBD" + j.ToString(CultureInfo.InvariantCulture)); // _tags.Add(new PLCTag("DB1.DBD" + j.ToString(CultureInfo.InvariantCulture)) // { // TagDataType = TagDataType.Float // }); // j += 4; //} //myConn.ReadValues(_tags, false); var tag = new PLCTag(); tag.TagDataType = TagDataType.Word; tag.SymbolicAccessKey = "8a0e000124134d054000000a"; myConn.ReadValue(tag); /*tag.Controlvalue = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 88, 1, 2, 3, 4, 5, 6, 7, 8, 9, 77 }; myConn.WriteValue(tag); var db = myConn.PLCGetBlockInMC7("DB99"); MessageBox.Show("DB:" + Encoding.ASCII.GetString(db)); myConn.PLCPutBlockFromMC7toPLC("DB98", db);*/ }
private void button2_Click(object sender, EventArgs e) { try { PLCConnection myConn = new PLCConnection(lstConnections.SelectedItem.ToString()); myConn.Connect(); int anz = readBytes.Length/Convert.ToInt32(txtSize.Text); int olen = Convert.ToInt32(txtSize.Text); int len = Convert.ToInt32(txtNewSize.Text); for (int n = 0; n < anz; n++) { PLCTag plcTag = new PLCTag() {TagDataType = TagDataType.ByteArray, TagDataSource = MemoryArea.Datablock, DataBlockNumber = Convert.ToInt32(txtDB.Text), ByteAddress = Convert.ToInt32(txtStartByte.Text) + n*Convert.ToInt32(txtNewSize.Text), ArraySize = Convert.ToInt32(txtSize.Text)}; byte[] ctrlV = new byte[len]; Array.Copy(readBytes, olen*n, ctrlV, 0, olen); plcTag.Controlvalue = ctrlV; myConn.WriteValue(plcTag); } lblState.Text = anz.ToString() + " Strukturen a " + len.ToString() + " Bytes geschrieben!"; } catch (Exception ex) { lblState.Text = ex.Message; } }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (_myconn == null) { _myconn = new PLCConnection(_connname); _myconn.Connect(); foreach (string itm in _myconn.PLCListBlocks(PLCBlockType.AllEditableBlocks)) { BlockList.Items.Add(itm); } } else { if (dispatcherTimer != null) { dispatcherTimer.Stop(); } if (myDiag != null) { myDiag.Close(); myDiag.RemoveDiagnosticData(); textEditor.Text = myBlock.ToString(); } _myconn.Dispose(); _myconn = null; myDiag = null; BlockList.Items.Clear(); blockName.Content = "FCxx"; Upload.IsEnabled = false; Optimize.IsEnabled = false; Diag.IsEnabled = false; } }
private void cmdConfig_Click(object sender, RoutedEventArgs e) { Configuration.ShowConfiguration("BackupRestoreBlocks", true); myConn = new PLCConnection("BackupRestoreBlocks"); lblConnection.Content = myConn.Configuration.ToString(); }
private void synchronizePLCTimes(object tmp) { foreach (ConnectionConfig connectionConfig in akConfig.Connections) { LibNoDaveConfig plcConnConf = connectionConfig as LibNoDaveConfig; if (plcConnConf != null) { PLCConnection tmpConn = (PLCConnection)ConnectionList[connectionConfig]; if (plcConnConf.SynchronizePLCTime) { try { if (!tmpConn.Connected) { Logging.LogTextToLog4Net("synchronizePLCTimes() => \"" + plcConnConf.Name + "\" => Connect..."); tmpConn.Connect(); } tmpConn.PLCSetTime(DateTime.Now); if (!plcConnConf.StayConnected) { Logging.LogTextToLog4Net("synchronizePLCTimes() => \"" + plcConnConf.Name + "\" Discconnect because !StayConnected"); tmpConn.Disconnect(); } } catch (Exception ex) { } } } } }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (_myconn == null) { _myconn = new PLCConnection(_connname); _myconn.Connect(); foreach (string itm in _myconn.PLCListBlocks(PLCBlockType.AllEditableBlocks)) BlockList.Items.Add(itm); } else { if (dispatcherTimer!=null) dispatcherTimer.Stop(); if (myDiag != null) { myDiag.Close(); myDiag.RemoveDiagnosticData(); textEditor.Text = myBlock.ToString(); } _myconn.Dispose(); _myconn = null; myDiag = null; BlockList.Items.Clear(); blockName.Content = "FCxx"; Upload.IsEnabled = false; Optimize.IsEnabled = false; Diag.IsEnabled = false; } }
private static void UploadNcFile(string ipAddress = "192.168.214.1") { using (var con = new PLCConnection("UploadNcFile")) { con.Configuration.CpuIP = ipAddress; con.Configuration.CpuSlot = 4; con.Connect(); try { if (!con.Connected) { con.Connect(); } bool F_XFER = true; // false for system ini files string NcPath = "/_N_CST_DIR/_N_PROG_EVENT_SPF"; string sEditFile = con.UploadNcFile(NcPath, F_XFER); } catch (Exception ex) { System.Diagnostics.Debugger.Break(); } } }
private void ReEstablishConnectionsThreadProc(object config) { try { LibNoDaveConfig connectionConfig = config as LibNoDaveConfig; while (true) { if (ConnectionList.ContainsKey(connectionConfig)) { PLCConnection plcConn = ConnectionList[connectionConfig] as PLCConnection; if (plcConn != null && !plcConn.Connected && ((LibNoDaveConfig)connectionConfig).StayConnected) { try { plcConn.Connect(); Logging.LogText("Connection: " + connectionConfig.Name + " connected", Logging.LogLevel.Information); } catch (ThreadAbortException ex) { throw ex; } catch (Exception ex) { Logging.LogText("Connection: " + connectionConfig.Name, ex, Logging.LogLevel.Warning); } } } Thread.Sleep(connectionConfig.ReconnectInterval); } } catch (ThreadAbortException) { } }
private void button4_Click(object sender, EventArgs e) { myConn = new PLCConnection("SimpleCSharpDemonstrationConnection"); myConn.Connect(); //var _tags = new List<PLCTag>(); //var j = 0; //for (var i = 0; i < 96; i++) //{ // Console.WriteLine("DB1.DBD" + j.ToString(CultureInfo.InvariantCulture)); // _tags.Add(new PLCTag("DB1.DBD" + j.ToString(CultureInfo.InvariantCulture)) // { // TagDataType = TagDataType.Float // }); // j += 4; //} //myConn.ReadValues(_tags, false); var tag = new PLCTag(); tag.TagDataType = TagDataType.Word; tag.SymbolicAccessKey = "8a0e000124134d054000000a"; myConn.ReadValue(tag); /*tag.Controlvalue = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 88, 1, 2, 3, 4, 5, 6, 7, 8, 9, 77 }; * myConn.WriteValue(tag); * var db = myConn.PLCGetBlockInMC7("DB99"); * MessageBox.Show("DB:" + Encoding.ASCII.GetString(db)); * myConn.PLCPutBlockFromMC7toPLC("DB98", db);*/ }
static void Main(string[] args) { if (args.Length > 0) { if (args[0] == "/config" || args[0] == "-config" || args[0] == "--config") { Configuration.ShowConfiguration("CommandWhenBitSetConn", true); } } else { try { PLCConnection myConn = new PLCConnection("CommandWhenBitSetConn"); myConn.Connect(); PLCTag tag = new PLCTag(Settings.Default.PLCVar); myConn.ReadValue(tag); if ((bool)tag.Value == true) { Process P = new Process(); P.StartInfo.FileName = Settings.Default.CommandToRun; P.StartInfo.Arguments = Settings.Default.CommandToRun; P.Start(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
private void startConnection() { plcConnection = new List <PLCConnection>(); try { PLCConnection akConn = new PLCConnection("conf"); //Erstellen der Verbindungskonfiguration akConn.Configuration.ConnectionType = LibNodaveConnectionTypes.ISO_over_TCP; akConn.Configuration.CpuIP = "192.168.1.205"; akConn.Configuration.CpuRack = 0; akConn.Configuration.CpuSlot = 1; akConn.Configuration.ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration; akConn.Configuration.PLCConnectionType = LibNodaveConnectionResource.OP; plcConnection.Add(akConn); plcConnection[0].Connect(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); closeConnections(); return; } }
private void synchronizePLCTimes(object tmp) { foreach (ConnectionConfig connectionConfig in akConfig.Connections) { LibNoDaveConfig plcConnConf = connectionConfig as LibNoDaveConfig; if (plcConnConf != null) { PLCConnection tmpConn = (PLCConnection)ConnectionList[connectionConfig]; if (plcConnConf.SynchronizePLCTime) { try { if (!tmpConn.Connected) { tmpConn.Connect(); } tmpConn.PLCSetTime(DateTime.Now); if (!plcConnConf.StayConnected) { tmpConn.Disconnect(); } } catch (Exception ex) { } } } } }
private static void DownloadNcFile(string ipAddress = "192.168.214.1") { using (var con = new PLCConnection("DownloadNcFile")) { con.Configuration.CpuIP = ipAddress; con.Configuration.CpuSlot = 4; con.Connect(); try { if (!con.Connected) { con.Connect(); } string s = "Hallo NC"; string NcPath = "/_N_MPF_DIR/_N_MY_TEST_MPF"; con.DownloadToNC(NcPath, null, s); } catch (Exception ex) { System.Diagnostics.Debugger.Break(); } } }
public override void Connect_To_Database(StorageConfig config) { myConfig = config as PLCConfig; _plcConnection = new PLCConnection(myConfig.Configuration); _plcConnection.AutoConnect = true; _plcConnection.Connect(); }
private void lstConnections_SelectedIndexChanged_1(object sender, EventArgs e) { myConn = new PLCConnection((string)lstConnections.SelectedItem); if (lstConnections.SelectedItem != null) { lblConnInfo.Text = new PLCConnectionConfiguration((string)lstConnections.SelectedItem).ToString(); } }
public MainWindow() { InitializeComponent(); lblVersion.Text = "Version: " + String.Format("{0}", Assembly.GetExecutingAssembly().GetName().Version.ToString()); this.DataContext = this; Connection = new PLCConnection("WPFToolboxForSiemensPLCs"); }
private void button4_Click(object sender, EventArgs e) { myConn = new PLCConnection("SimpleCSharpDemonstrationConnection"); myConn.Connect(); var db = myConn.PLCGetBlockInMC7("DB99"); MessageBox.Show("DB:" + Encoding.ASCII.GetString(db)); myConn.PLCPutBlockFromMC7toPLC("DB98", db); }
public override void Connect_To_Database(StorageConfig config) { myConfig = config as PLCConfig; _plcConnection = new PLCConnection(myConfig.Configuration); _plcConnection.AutoConnect = true; _plcConnection.Connect(); Logging.LogTextToLog4Net("Connect_To_Database() => \"" + _plcConnection.Name + "\" => Connect..."); }
public MainWindow() { InitializeComponent(); lblVersion.Text = "Version: "+ String.Format("{0}", Assembly.GetExecutingAssembly().GetName().Version.ToString()); this.DataContext = this; Connection = new PLCConnection("WPFToolboxForSiemensPLCs"); }
private void button5_Click(object sender, EventArgs e) { var cfg = new PLCConnectionConfiguration() { ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration, ConnectionName = "MyPrivateConnection" }; Configuration.ShowConfiguration(cfg); myConn = new PLCConnection(cfg); }
public MainWindow() { InitializeComponent(); lblFolder.Text = Environment.CurrentDirectory; LoadFiles(); myConn = new PLCConnection("BackupRestoreBlocks"); lblConnection.Content = myConn.Configuration.ToString(); }
private void button2_Click(object sender, EventArgs e) { try { myConn = new PLCConnection("SimpleCSharpDemonstrationConnection"); myConn.Connect(); timer.Enabled = true; } catch(Exception ex) { } }
private void button2_Click(object sender, EventArgs e) { try { myConn = new PLCConnection("SimpleCSharpDemonstrationConnection"); myConn.Connect(); timer.Enabled = true; } catch (Exception ex) { } }
public PLC(byte address, string portName, int baudRate) { Address = address; Connection = new PLCConnection(portName, baudRate); Provider = new PLCDataProvider(this); DataIn = new DataStorage<CommunicationData>(); RemoteSubscribers = new DataStorage<RemoteSubscriberData>(); Consumer = new PLCDataConsumer(this); Consumer.AttachStorageSource(DataIn); }
public PLCTagTriggerThread(IDBInterface dbInterface, DatasetConfig datasetConfig, Dictionary <ConnectionConfig, Object> activConnections, bool StartedAsService) { this.StartedAsService = StartedAsService; this.dbInterface = dbInterface; this.datasetConfig = datasetConfig; this.activConnections = activConnections; this.triggerConn = (PLCConnection)activConnections[datasetConfig.TriggerConnection]; this.readBit = datasetConfig.TriggerReadBit; this.quittBit = datasetConfig.TriggerQuittBit; ak_interval = NoDataInterval; }
public PLCTagTriggerThread(IDBInterface dbInterface, DatasetConfig datasetConfig, Dictionary<ConnectionConfig, Object> activConnections, bool StartedAsService) { this.StartedAsService = StartedAsService; this.dbInterface = dbInterface; this.datasetConfig = datasetConfig; this.activConnections = activConnections; this.triggerConn = (PLCConnection) activConnections[datasetConfig.TriggerConnection]; this.readBit = datasetConfig.TriggerReadBit; this.quittBit = datasetConfig.TriggerQuittBit; ak_interval = NoDataInterval; }
public void TestTriggers(DatasetConfig testDataset) { if (testDataset.Trigger == DatasetTriggerType.Tags_Handshake_Trigger) { EstablishConnections(); PLCConnection conn = ConnectionList[testDataset.TriggerConnection] as PLCConnection; if (conn != null) { conn.ReadValue(testDataset.TriggerReadBit); conn.ReadValue(testDataset.TriggerQuittBit); } } }
private void ConnectPLC() { plcConnection = new List <PLCConnection>(); try { PLCConnection akConn = new PLCConnection(conn[0]); plcConnection.Add(akConn); akConn.Connect(); } catch (Exception ex) { DisconnectPLC(); return; } }
public void TestReading2() { var wrapper = new ConnectionWrapper(480); var conn = new PLCConnection(new PLCConnectionConfiguration(), wrapper); var listTag = new List <PLCTag>(); listTag.Add(new PLCTag("DB2.DBB0")); listTag.Add(new PLCTag("DB2.DBB1")); listTag.Add(new PLCTag("DB2.DBB2")); conn.ReadValues(listTag, true); var pdus = wrapper.PDUs; string req = string.Join(Environment.NewLine, pdus); string t = "READ Area:132, DBnum:2, Start:0, Bytes:3"; Assert.AreEqual(req, t); }
private void ReadPlcTagsFromConnection(PLCConnection conn) { var values = from rw in varTabRows where rw.Connection == conn && rw.LibNoDaveValue != null select rw.LibNoDaveValue; if (ReadTagsConfig == 0) { conn.ReadValues(values); } else { var rq = conn.ReadValuesWithVarTabFunctions(values, (PLCTriggerVarTab)ReadTagsConfig + 1); rq.RequestData(); } }
private void DownloadBlock_Load(object sender, EventArgs e) { try { myConn = new PLCConnection(ConnectionName); label1.Text = ConnectionName + "\r\n" + (new PLCConnectionConfiguration(ConnectionName)).ToString(); myConn.Connect(); listBox1.Items.AddRange(myConn.PLCListBlocks(PLCBlockType.AllEditableBlocks).ToArray()); //myConn.PLCSendPassword("admin"); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Close(); } }
private void DownloadBlock_Load(object sender, EventArgs e) { try { myConn = new PLCConnection(ConnectionName); label1.Text = ConnectionName + "\r\n" + (new PLCConnectionConfiguration(ConnectionName)).ToString(); myConn.Connect(); listBox1.Items.AddRange(myConn.PLCListBlocks(PLCBlockType.AllEditableBlocks).ToArray()); //myConn.PLCSendPassword("admin"); } catch(Exception ex) { MessageBox.Show(ex.Message); this.Close(); } }
protected override void OnStart(string[] args) { base.OnStart(args); var cfg = new PLCConnectionConfiguration("myConnection", LibNodaveConnectionConfigurationType.ObjectSavedConfiguration); cfg.ConnectionType = (int) 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 searchPasswordToolStripMenuItem_Click(object sender, EventArgs e) { char[] zeichen = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; myConn = new PLCConnection((string)lstConnections.SelectedItem); myConn.Connect(); Int64 anz = 0; bool pwdCorr = false; string pwd = "12345678"; int[] cnt = new int[8]; while (!pwdCorr) { cnt[0]++; for (int n = 0; n < 7; n++) { if (cnt[n] >= zeichen.Length) { cnt[n + 1]++; cnt[n] = 0; } } if (cnt[7] >= zeichen.Length) { MessageBox.Show("Password not found!"); return; } pwd = ""; for (int n = 0; n < 8; n++) { pwd += zeichen[cnt[n]]; } anz++; pwdCorr = myConn.PLCSendPassword(pwd.Trim()); } MessageBox.Show("Passwort:" + pwd + "\n" + "Anzahl geprüfter Kennwörter:" + anz.ToString()); }
private void button1_Click(object sender, EventArgs e) { try { PLCConnection myConn = new PLCConnection(lstConnections.SelectedItem.ToString()); myConn.Connect(); PLCTag plcTag=new PLCTag(){TagDataType = TagDataType.ByteArray, TagDataSource = MemoryArea.Datablock, DataBlockNumber = Convert.ToInt32(txtDB.Text), ByteAddress = Convert.ToInt32(txtStartByte.Text), ArraySize = Convert.ToInt32(txtBytes.Text)}; myConn.ReadValue(plcTag); readBytes = (byte[]) plcTag.Value; myConn.Disconnect(); lblState.Text = readBytes.Length.ToString() + " Bytes gelesen"; MessageBox.Show("So nun den neuen DB übertragen...."); } catch (Exception ex) { lblState.Text = ex.Message; } }
private void button2_Click(object sender, EventArgs e) { label2.Text = "Trying to connect..."; myConn = new PLCConnection("JFK-TestConnection"); Application.DoEvents(); try { //myConn.Connect(this.Handle.ToInt32()); button2.Enabled = false; button6.Enabled = true; lblConn.Visible = true; backgroundWorker1.RunWorkerAsync(this.Handle.ToInt32()); } catch (Exception ex) { label2.Text = "Error connecting: " + ex.Message; } }
private void cmdConnect_Click(object sender, EventArgs e) { try { if (lstConnections.SelectedItem != null) { this.myConn = new PLCConnection(lstConnections.SelectedItem.ToString()); this.myConn.Connect(); cmdConnect.BackColor = Color.LightGreen; } else { MessageBox.Show("Please Select the Connection Configuration wich i should use in the Listbox!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void startToolStripMenuItem_Click(object sender, EventArgs e) { plcConnections = new List<PLCConnection>(); try { for (int n = 0; n < 6; n++) { PLCConnection akConn = new PLCConnection(conn[n]); plcConnections.Add(akConn); akConn.Connect(); } } catch (Exception ex) { closeConnections(); MessageBox.Show("Fehler beim Verbindungsaufbau: " + ex.Message); } read_timer_plc1.Enabled = true; read_timer_plc2.Enabled = true; }
public void TestReading() { var wrapper = new ConnectionWrapper(480); var conn = new PLCConnection(new PLCConnectionConfiguration(), wrapper); var listTag = new List<PLCTag>(); listTag.Add(new PLCTag("P#DB60.DBX0 BYTE 300")); listTag.Add(new PLCTag("P#DB10.DBX10 BYTE 300")); conn.ReadValues(listTag, true); var pdus = wrapper.PDUs; string req = string.Join(Environment.NewLine, pdus); string t = @"READ Area:132, DBnum:10, Start:10, Bytes:300 READ Area:132, DBnum:60, Start:0, Bytes:300"; Assert.AreEqual(req, t); var wrapper2 = new ConnectionWrapper(480); var conn2 = new PLCConnection(new PLCConnectionConfiguration(), wrapper2); var listTag2 = new List<PLCTag>(); listTag2.Add(new PLCTag("P#DB60.DBX0 BYTE 300")); listTag2.Add(new PLCTag("P#DB10.DBX10 BYTE 300")); conn2._TestNewReadValues(listTag2, true); var pdus2 = wrapper2.PDUs; string req2 = string.Join(Environment.NewLine, pdus2); string t2 = "READ Area:132, DBnum:10, Start:10, Bytes:300\r\nREAD Area:132, DBnum:60, Start:0, Bytes:300"; Assert.AreEqual(req2, t2); var wrapper3 = new ConnectionWrapper(480); var conn3 = new PLCConnection(new PLCConnectionConfiguration(), wrapper3); var listTag3 = new List<PLCTag>(); listTag3.Add(new PLCTag("P#DB60.DBX0 BYTE 300") { DontSplitValue = false }); listTag3.Add(new PLCTag("P#DB10.DBX10 BYTE 300") { DontSplitValue = false }); conn3.ReadValues(listTag3, true); var pdus3 = wrapper3.PDUs; string req3 = string.Join(Environment.NewLine, pdus3); string t3 = "READ Area:132, DBnum:10, Start:10, Bytes:300\r\nREAD Area:132, DBnum:60, Start:0, Bytes:140\r\nREAD Area:132, DBnum:60, Start:140, Bytes:160"; Assert.AreEqual(req3, t3); var wrapper4 = new ConnectionWrapper(480); var conn4 = new PLCConnection(new PLCConnectionConfiguration(), wrapper4); var listTag4 = new List<PLCTag>(); listTag4.Add(new PLCTag("P#DB1.DBX0 BYTE 4") { DontSplitValue = false }); listTag4.Add(new PLCTag("P#DB1.DBX8 BYTE 4") { DontSplitValue = false }); listTag4.Add(new PLCTag("P#DB1.DBX10 BYTE 4") { DontSplitValue = false }); listTag4.Add(new PLCTag("P#DB1.DBX30 BYTE 4") { DontSplitValue = false }); listTag4.Add(new PLCTag("P#DB1.DBX50 BYTE 4") { DontSplitValue = false }); listTag4.Add(new PLCTag("P#DB1.DBX80 BYTE 4") { DontSplitValue = false }); conn4.ReadValues(listTag4, true); var pdus4 = wrapper4.PDUs; string req4 = string.Join(Environment.NewLine, pdus4); string t4 = "READ Area:132, DBnum:1, Start:0, Bytes:14\r\nREAD Area:132, DBnum:1, Start:30, Bytes:4\r\nREAD Area:132, DBnum:1, Start:50, Bytes:4\r\nREAD Area:132, DBnum:1, Start:80, Bytes:4"; Assert.AreEqual(req4, t4); var wrapper5 = new ConnectionWrapper(240); var conn5 = new PLCConnection(new PLCConnectionConfiguration(), wrapper5); var listTag5 = new List<PLCTag>(); listTag5.Add(new PLCTag("P#DB1.DBX0 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX8 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX10 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX30 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX50 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX80 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX90 BYTE 30") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX100 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX140 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX160 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX180 BYTE 44") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX230 BYTE 20") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX240 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX250 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX260 BYTE 4") { DontSplitValue = false }); listTag5.Add(new PLCTag("P#DB1.DBX270 BYTE 4") { DontSplitValue = false }); conn5.ReadValues(listTag5, true); var pdus5 = wrapper5.PDUs; string req5 = string.Join(Environment.NewLine, pdus5); string t5 = "READ Area:132, DBnum:1, Start:0, Bytes:14\r\nREAD Area:132, DBnum:1, Start:30, Bytes:4\r\nREAD Area:132, DBnum:1, Start:50, Bytes:4\r\nREAD Area:132, DBnum:1, Start:80, Bytes:4\r\nREAD Area:132, DBnum:1, Start:90, Bytes:30\r\nREAD Area:132, DBnum:1, Start:140, Bytes:4\r\nREAD Area:132, DBnum:1, Start:160, Bytes:4\r\nREAD Area:132, DBnum:1, Start:180, Bytes:44\r\nREAD Area:132, DBnum:1, Start:230, Bytes:24\r\nREAD Area:132, DBnum:1, Start:260, Bytes:4\r\nREAD Area:132, DBnum:1, Start:270, Bytes:4"; Assert.AreEqual(req5, t5); //var tag=new PLCNckTag() { TagDataType = TagDataType.Float, NckArea = 0xa, NckUnit = 0x8,NckColumn = 0x23, NckLine = 0x1,NckModule = 0x1a,NckLinecount = 0x1}; }
public string CheckConfiguration(bool TestConnections) { string error = ""; var ConnectionList = new Dictionary<ConnectionConfig, PLCConnection>(); //Try to Connect to the PLCs if (TestConnections) foreach (ConnectionConfig connectionConfig in Connections) { LibNoDaveConfig lConn = connectionConfig as LibNoDaveConfig; if (lConn != null) { using (PLCConnection myConn = new PLCConnection(lConn.Configuration)) { try { myConn.Connect(); ConnectionList.Add(connectionConfig, myConn); } catch (Exception ex) { error += "Error: Error connecting \"" + lConn.Name + "\" : " + ex.Message + Environment.NewLine; } } } } var TCPIPKeys = new Dictionary<string, int>(); foreach (DatasetConfig datasetConfig in Datasets) { var DatasetConnectionKeys = new Dictionary<string, object>(); //Look if TCPIP Connection is only used in one Dataset, because we need the length for each Connection! try { if (datasetConfig.DatasetConfigRows.Count > 0) { if (datasetConfig.DatasetConfigRows[0].Connection != null) { var tcp = datasetConfig.DatasetConfigRows[0].Connection as TCPIPConfig; var byteCount = ReadData.GetCountOfBytesToRead(datasetConfig.DatasetConfigRows); if (tcp != null && !tcp.DontUseFixedTCPLength) { if (!TCPIPKeys.ContainsKey(datasetConfig.DatasetConfigRows[0].Connection.Name)) { TCPIPKeys.Add(datasetConfig.DatasetConfigRows[0].Connection.Name, byteCount); } if (TCPIPKeys[datasetConfig.DatasetConfigRows[0].Connection.Name] != byteCount) { error += "Error: Dataset \"" + datasetConfig.Name + "\" - The same TCP/IP Connection is used in more than one Dataset with differnet bytes sizes, but fixed Length should be used!" + Environment.NewLine; } } } } else { error += "Error: Dataset \"" + datasetConfig.Name + "\" - No DatasetConfigRow is set!" + Environment.NewLine; } } catch { error += "Error: Dataset \"" + datasetConfig.Name + "\" - The same TCP/IP Connection is used in more than one Dataset!" + Environment.NewLine; } //Look if Trigger on a Dataset with TCP/IP Connection is Incoming Data, and that this trigger is not used on a Connection without TCP/IP try { if (!(datasetConfig.TriggerConnection is TCPIPConfig) && (datasetConfig.Trigger == DatasetTriggerType.Triggered_By_Incoming_Data_On_A_TCPIP_Connection)) error += "Error: Dataset \"" + datasetConfig.Name + "\" - The selected Connection for incoming Trigger is no TCP/IP Connection !" + Environment.NewLine; } catch { } //Look if Trigger Connection was selected (Handshake Trigger) if (datasetConfig.Trigger == DatasetTriggerType.Tags_Handshake_Trigger && datasetConfig.TriggerConnection == null) error += "Error: Dataset \"" + datasetConfig.Name + "\" Trigger Connection not set!" + Environment.NewLine; //Look if Trigger Connection was selected (TCPIP Trigger) if (datasetConfig.Trigger == DatasetTriggerType.Triggered_By_Incoming_Data_On_A_TCPIP_Connection && datasetConfig.TriggerConnection == null) error += "Error: Dataset \"" + datasetConfig.Name + "\" Trigger Connection not set!" + Environment.NewLine; if (datasetConfig.Storage == null) error += "Error: Dataset \"" + datasetConfig.Name + " - Storage is not set!" + Environment.NewLine; foreach (DatasetConfigRow datasetConfigRow in datasetConfig.DatasetConfigRows) { if (datasetConfigRow.Connection == null && datasetConfig.Trigger != DatasetTriggerType.Triggered_By_Incoming_Data_On_A_TCPIP_Connection) error += "Error: Dataset \"" + datasetConfig.Name + "\" Row \"" + datasetConfigRow.DatabaseField + "\" - Connection not Set!" + Environment.NewLine; } if (datasetConfig.Trigger==DatasetTriggerType.Tags_Handshake_Trigger && datasetConfig.TriggerConnection==null) error += "Error: Dataset \"" + datasetConfig.Name + "\" Trigger Connection not set!" + Environment.NewLine; foreach (DatasetConfigRow datasetConfigRow in datasetConfig.DatasetConfigRows) { //Look if PLC-Connection was selected if (datasetConfigRow.Connection == null && datasetConfig.Trigger != DatasetTriggerType.Triggered_By_Incoming_Data_On_A_TCPIP_Connection) error += "Error: Dataset \"" + datasetConfig.Name + "\" Row \"" + datasetConfigRow.DatabaseField + "\" - Connection not Set!" + Environment.NewLine; //Look if DatabaseFieldType was selected if (datasetConfigRow.DatabaseFieldType == "") error += "Error: Dataset \"" + datasetConfig.Name + "\" Row \"" + datasetConfigRow.DatabaseField + "\" - DatabaseFieldType not Set!" + Environment.NewLine; ////Look if PLC-ValueType was selected if (datasetConfigRow.PLCTag.TagDataType == null) error += "Error: Dataset \"" + datasetConfig.Name + "\" Row \"" + datasetConfigRow.DatabaseField + "\" - PLC-ValueType not Set!" + Environment.NewLine; if (TestConnections && datasetConfig.Trigger != DatasetTriggerType.Triggered_By_Incoming_Data_On_A_TCPIP_Connection) { PLCConnection conn = null as PLCConnection; if (datasetConfigRow.Connection != null) { try { conn = ConnectionList[datasetConfigRow.Connection] as PLCConnection; } catch { conn = null; } } else conn = null; if (conn != null) { try { conn.ReadValue(datasetConfigRow.PLCTag); if (datasetConfigRow.PLCTag.ItemDoesNotExist) error += "Error: Dataset \"" + datasetConfig.Name + "\" Row \"" + datasetConfigRow.DatabaseField + "\" - Error Reading Value on Address " + datasetConfigRow.PLCTag.S7FormatAddress + " !" + Environment.NewLine; } catch (Exception ex) { error += "Error: Dataset \"" + datasetConfig.Name + "\" Row \"" + datasetConfigRow.DatabaseField + "\" - Error Reading Value on Address " + datasetConfigRow.PLCTag.S7FormatAddress + " !" + Environment.NewLine; } } } } } //Look if Connection Name exists only once var ConnectionNames = new List<string>(); var ConnectionKeys = new Dictionary<string, object>(); foreach (ConnectionConfig item in Connections) { if (ConnectionKeys.ContainsKey(item.Name)) error += "Error: Connection name \"" + item.Name + "\" - exist more than once!" + Environment.NewLine; else ConnectionKeys.Add(item.Name, null); } //Look if Storrage Name exists only once var StorageNames = new List<string>(); var StoragesKeys = new Dictionary<string, object>(); foreach (StorageConfig item in Storages) { if (StoragesKeys.ContainsKey(item.Name)) error += "Error: Storage name \"" + item.Name + "\" - exist more than once!" + Environment.NewLine; else StoragesKeys.Add(item.Name, null); } //Look if the Database Field Type is in the Field Types List //Look if Field Name Exists only Once -> This is possible in excel, but not in databases if (error == "") return null; return error; }
private void ReadPlcTagsFromConnection(PLCConnection conn) { var values = from rw in varTabRows where rw.Connection == conn && rw.LibNoDaveValue != null select rw.LibNoDaveValue; if (ReadTagsConfig == 0) conn.ReadValues(values); else { var rq = conn.ReadValuesWithVarTabFunctions(values, (PLCTriggerVarTab) ReadTagsConfig + 1); rq.RequestData(); } }
private void watchToolStripMenuItem_Click(object sender, EventArgs e) { lblStatus.Text = ""; try { if (myConn != null) myConn.Dispose(); myConn = new PLCConnection((string) lstConnections.SelectedItem); myConn.Connect(); fetchPLCData.Enabled = true; } catch (Exception ex) { lblStatus.Text = ex.Message; } //myConn.Disconnect(); }
private void searchPasswordToolStripMenuItem_Click(object sender, EventArgs e) { char[] zeichen = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; myConn = new PLCConnection((string) lstConnections.SelectedItem); myConn.Connect(); Int64 anz = 0; bool pwdCorr = false; string pwd = "12345678"; int[] cnt = new int[8]; while (!pwdCorr) { cnt[0]++; for (int n = 0; n < 7; n++) { if (cnt[n] >= zeichen.Length) { cnt[n + 1]++; cnt[n] = 0; } } if (cnt[7] >= zeichen.Length) { MessageBox.Show("Password not found!"); return; } pwd = ""; for (int n = 0; n < 8; n++) { pwd += zeichen[cnt[n]]; } anz++; pwdCorr = myConn.PLCSendPassword(pwd.Trim()); } MessageBox.Show("Passwort:" + pwd + "\n" + "Anzahl geprüfter Kennwörter:" + anz.ToString()); }
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 lstConnections_SelectedIndexChanged_1(object sender, EventArgs e) { myConn = new PLCConnection((string) lstConnections.SelectedItem); if (lstConnections.SelectedItem != null) lblConnInfo.Text = new PLCConnectionConfiguration((string) lstConnections.SelectedItem).ToString(); }
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 cmdReadStruct_Click(object sender, EventArgs e) { myConn = new PLCConnection("SimpleCSharpDemonstrationConnection"); myConn.Connect(); //PLCTagGeneric PLCTag<TestStruct> tst = new PLCTag<TestStruct>() {DataBlockNumber = 97, ByteAddress = 0}; myConn.ReadValue(tst); TestStruct read = tst.GenericValue; TestStruct wrt = new TestStruct(); wrt.aa = 11; wrt.bb = 12; wrt.cc = 13; wrt.ee = 14; wrt.ff = 15; wrt.test = "Bin da!"; tst.Controlvalue = wrt; myConn.WriteValue(tst); }
private void EstablishConnections() { foreach (ConnectionConfig connectionConfig in akConfig.Connections) { LibNoDaveConfig plcConnConf = connectionConfig as LibNoDaveConfig; TCPIPConfig tcpipConnConf = connectionConfig as TCPIPConfig; DatabaseConfig dbConnConf = connectionConfig as DatabaseConfig; if (plcConnConf != null) { Logging.LogText("Connection: " + connectionConfig.Name + " is starting...", Logging.LogLevel.Information); PLCConnection tmpConn = new PLCConnection(plcConnConf.Configuration); try { tmpConn.Connect(); if (!plcConnConf.StayConnected) tmpConn.Disconnect(); } catch (Exception ex) { Logging.LogText("Connection: " + connectionConfig.Name, ex, Logging.LogLevel.Warning); } ConnectionList.Add(connectionConfig, tmpConn); } else if (dbConnConf != null) { var tmpConn = new DatabaseConnection(dbConnConf); try { tmpConn.Connect(); } catch (Exception ex) { Logging.LogText("Connection: " + connectionConfig.Name, ex, Logging.LogLevel.Warning); } ConnectionList.Add(connectionConfig, tmpConn); } else if (tcpipConnConf != null) { //todo: legth of tcp conn //TCPFunctionsAsync tmpConn = new TCPFunctionsAsync(new SynchronizationContext(), tcpipConnConf.IPasIPAddres, tcpipConnConf.Port, !tcpipConnConf.PassiveConnection, 0); //tmpConn.Connect(); //ConnectionList.Add(connectionConfig, tmpConn); } } myReEstablishConnectionsThreads = new List<Thread>(); foreach (ConnectionConfig connectionConfig in akConfig.Connections) { if (connectionConfig is LibNoDaveConfig) { var thrd = new Thread(new ParameterizedThreadStart(ReEstablishConnectionsThreadProc)) { Name = "EstablishConnectionsThreadProc" }; thrd.Start(connectionConfig as LibNoDaveConfig); this.myReEstablishConnectionsThreads.Add(thrd); } } }