public virtual string GetDefaultDatabaseFieldTypeForLibNoDaveTag(PLCTag tag) { switch (tag.LibNoDaveDataType.ToString().ToLower().Trim()) { case "float": return "float"; break; case "int": return "int"; break; case "word": return "word"; break; case "date": return "date"; break; case "datetime": return "datetime"; break; case "time": return "time"; break; case "dint": return "bigint"; break; } return ""; }
public static PLCTag ShowPLCTagEditor(PLCTag tag) { PLCTagEditor tagedt=new PLCTagEditor(); tagedt._libnodavevalue = new PLCTag(tag); tagedt.ShowDialog(); return tagedt._libnodavevalue; }
private void ThreadProc() { PLCTag tag = new PLCTag(triggerBit); while (threadShouldRun) { myConn.ReadValue(tag); if ((bool)tag.Value == true) { PLCTag writeData = new PLCTag(); writeData.TagDataType = TagDataType.CharArray; writeData.DataBlockNumber = writeDB; writeData.ArraySize = writeCharArraySize; string writeDataString = ""; using (StreamReader sr = new StreamReader(csvFile)) { writeDataString = sr.ReadToEnd(); } writeData.Controlvalue = writeDataString; //Reset the Bit tag.Controlvalue = false; myConn.WriteValues(new[] { writeData, tag }); } Thread.Sleep(20); } }
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 cmdOK_Click(object sender, EventArgs e) { if (_libnodavevalue==null) _libnodavevalue = new PLCTag(); if ((MemoryArea)((EnumListItem)cmbSource.SelectedItem).Value == MemoryArea.Datablock || (MemoryArea)((EnumListItem)cmbSource.SelectedItem).Value == MemoryArea.InstanceDatablock) _libnodavevalue.DataBlockNumber = int.Parse(txtDB.Text); else _libnodavevalue.DataBlockNumber = 0; _libnodavevalue.ByteAddress = int.Parse(txtByte.Text); if ((TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.Bool) _libnodavevalue.BitAddress = int.Parse(txtBit.Text); else _libnodavevalue.BitAddress = 0; if ((TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.String || (TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.ByteArray || (TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.CharArray) _libnodavevalue.ArraySize = int.Parse(txtLen.Text); else _libnodavevalue.ArraySize = 0; _libnodavevalue.TagDataSource = (MemoryArea) ((EnumListItem) cmbSource.SelectedItem).Value; _libnodavevalue.TagDataType = (TagDataType)((EnumListItem)cmbType.SelectedItem).Value; this.Close(); }
private void cmdReadWithReadValues_Click(object sender, EventArgs e) { try { txtWert.Text = ""; txtZeit.Text = ""; lblStatus.Text = ""; if (myConn == null) cmdConnect_Click(sender, e); PLCTag myTag = new PLCTag(txtTag.Text); List<PLCTag> tagList = new List<PLCTag>() {myTag}; Stopwatch sw = new Stopwatch(); sw.Start(); myConn.ReadValues(tagList); sw.Stop(); txtZeit.Text = sw.ElapsedMilliseconds.ToString() + " ms"; txtWert.Text = myTag.ValueAsString; } catch (Exception ex) { lblStatus.Text = ex.Message; } }
private void cmdReadValuesWithvarTab_Click(object sender, EventArgs e) { MessageBox.Show("Achtung: Es können hier nur rund 200 Bytes gelesen werden, aber die länge wird noch nicht geprüft! Und es wird nur die Zeit zum lesen, nicht die zum starten der Anfrage gemessen!"); try { txtWert.Text = ""; txtZeit.Text = ""; lblStatus.Text = ""; if (myConn == null) cmdConnect_Click(sender, e); PLCTag myTag = new PLCTag(txtTag.Text); List<PLCTag> tagList = new List<PLCTag>() { myTag }; var read = myConn.ReadValuesWithVarTabFunctions(tagList, PLCTriggerVarTab.BeginOfCycle); Stopwatch sw = new Stopwatch(); sw.Start(); read.RequestData(); sw.Stop(); txtZeit.Text = sw.ElapsedMilliseconds.ToString() + " ms"; txtWert.Text = myTag.ValueAsString; } catch (Exception ex) { lblStatus.Text = ex.Message; } }
private void button1_Click(object sender, EventArgs e) { //if (startWasNull) _libnodavevalue = null; //else // _libnodavevalue = backupPLCTag; this.Close(); }
public static PLCTag ShowPLCTagEditor(PLCTag tag) { PLCTagEditor tagedt = new PLCTagEditor(); tagedt._libnodavevalue = new PLCTag(tag); tagedt.ShowDialog(); return(tagedt._libnodavevalue); }
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; }
//private PLCTag backupPLCTag = null; private void LibNoDaveValueEditor_Load(object sender, EventArgs e) { EnumListBoxExtensions.AddEnumToList(cmbSource, typeof(MemoryArea)); EnumListBoxExtensions.AddEnumToList(cmbType, typeof(TagDataType)); if (_libnodavevalue == null) { startWasNull = true; _libnodavevalue = new PLCTag(); } //else // backupPLCTag = new PLCTag(_libnodavevalue); _libnodavevalue.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_libnodavevalue_PropertyChanged); _libnodavevalue_PropertyChanged(null, null); }
private void cmdOK_Click(object sender, EventArgs e) { if (_libnodavevalue == null) { _libnodavevalue = new PLCTag(); } if ((MemoryArea)((EnumListItem)cmbSource.SelectedItem).Value == MemoryArea.Datablock || (MemoryArea)((EnumListItem)cmbSource.SelectedItem).Value == MemoryArea.InstanceDatablock) { _libnodavevalue.DataBlockNumber = int.Parse(txtDB.Text); } else { _libnodavevalue.DataBlockNumber = 0; } _libnodavevalue.ByteAddress = int.Parse(txtByte.Text); if ((TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.Bool) { _libnodavevalue.BitAddress = int.Parse(txtBit.Text); } else { _libnodavevalue.BitAddress = 0; } if ((TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.String || (TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.ByteArray || (TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.CharArray) { _libnodavevalue.ArraySize = int.Parse(txtLen.Text); } else { _libnodavevalue.ArraySize = 0; } _libnodavevalue.TagDataSource = (MemoryArea)((EnumListItem)cmbSource.SelectedItem).Value; _libnodavevalue.TagDataType = (TagDataType)((EnumListItem)cmbType.SelectedItem).Value; if (textValueName.Text != null && textValueName.Text.Length >= 1) { _libnodavevalue.ValueName = textValueName.Text; } this.Close(); }
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 cmdOK_Click(object sender, EventArgs e) { if (_libnodavevalue == null) { _libnodavevalue = new PLCTag(); } if ((TagDataSource)((EnumListItem)cmbSource.SelectedItem).Value == TagDataSource.Datablock || (TagDataSource)((EnumListItem)cmbSource.SelectedItem).Value == TagDataSource.InstanceDatablock) { _libnodavevalue.DatablockNumber = int.Parse(txtDB.Text); } else { _libnodavevalue.DatablockNumber = 0; } _libnodavevalue.ByteAddress = int.Parse(txtByte.Text); if ((TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.Bool) { _libnodavevalue.BitAddress = int.Parse(txtBit.Text); } else { _libnodavevalue.BitAddress = 0; } if ((TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.String || (TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.ByteArray || (TagDataType)((EnumListItem)cmbType.SelectedItem).Value == TagDataType.CharArray) { _libnodavevalue.ArraySize = int.Parse(txtLen.Text); } else { _libnodavevalue.ArraySize = 0; } _libnodavevalue.LibNoDaveDataSource = (TagDataSource)((EnumListItem)cmbSource.SelectedItem).Value; _libnodavevalue.LibNoDaveDataType = (TagDataType)((EnumListItem)cmbType.SelectedItem).Value; this.Close(); }
private void button2_Click(object sender, EventArgs e) { FolderBrowserDialog saveDataDir=new FolderBrowserDialog(); if (saveDataDir.ShowDialog() == System.Windows.Forms.DialogResult.OK) { foreach (string db in listBox1.SelectedItems) { var size = myConn.PLCGetDataBlockSize(db); var Tag = new PLCTag(db + ".DBX0.0"); Tag.TagDataType = TagDataType.ByteArray; Tag.ArraySize = size; myConn.ReadValue(Tag); BinaryWriter wrt = new BinaryWriter(File.Open(Path.Combine(saveDataDir.SelectedPath, db + ".data"), FileMode.Create)); wrt.Write((byte[])Tag.Value); wrt.Close(); } } }
private void button3_Click(object sender, EventArgs e) { OpenFileDialog dlg=new OpenFileDialog(); dlg.Filter = "*.data|*.data"; dlg.Multiselect = true; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { foreach (var fileName in dlg.FileNames) { var rd = new BinaryReader(File.Open(fileName, FileMode.Open)); var bytes = rd.ReadBytes(Convert.ToInt32(rd.BaseStream.Length)); var fn = Path.GetFileName(fileName); fn = fn.Substring(0, fn.Length - 5); var Tag = new PLCTag(fn + ".DBX0.0"); Tag.TagDataType = TagDataType.ByteArray; Tag.ArraySize = bytes.Length; Tag.Controlvalue = bytes; myConn.WriteValue(Tag); } } }
public S7VATBlock(byte[] hexCode, byte[] comments, int blocknumber, Encoding projEncoding) { BlockType = PLCBlockType.VAT; //BlockLanguage= BlockNumber = blocknumber; //Every Vats starts with: //0001 31 20 32 20 30 20 32 20 31 20 31 30 20 30 20 32 1 2 0 2 1 10 0 2 //0010 30 20 31 20 33 30 20 31 20 34 30 20 31 20 35 30 0 1 30 1 40 1 50 //0020 20 36 30 00 32 20 33 20 38 38 20 30 20 30 20 30 60. Rows = new List<PLCTag>(); VATRows = new List<S7VATRow>(); int akAddr = 36; while (akAddr < hexCode.Length) { if (hexCode[akAddr] != 0x00) { PLCTag tmp = new PLCTag(); string var = ""; string type = ""; string addr = ""; string controlval = ""; string db = ""; string showtype = ""; bool bit = false; switch (hexCode[akAddr]) { case 0x32: var = "E"; tmp.LibNoDaveDataSource = TagDataSource.Inputs; break; case 0x33: var = "A"; tmp.LibNoDaveDataSource = TagDataSource.Outputs; break; case 0x34: tmp.LibNoDaveDataSource = TagDataSource.Flags; var = "M"; break; case 0x35: tmp.LibNoDaveDataSource = TagDataSource.Datablock; var = "DB"; db = "DB"; break; case 0x38: tmp.LibNoDaveDataSource = TagDataSource.Timer; var = "T"; break; case 0x39: tmp.LibNoDaveDataSource = TagDataSource.Counter; var = "Z"; break; default: var = " 0x" + hexCode[akAddr].ToString("X") + " "; break; } akAddr++; akAddr++; switch (hexCode[akAddr]) { case 0x31: if (db != "") var += "X"; tmp.LibNoDaveDataType = TagDataType.Bool; bit = true; break; case 0x32: var += "B"; tmp.LibNoDaveDataType = TagDataType.Byte; break; case 0x33: tmp.LibNoDaveDataType = TagDataType.Word; var += "W"; break; case 0x34: tmp.LibNoDaveDataType = TagDataType.Dword; var += "D"; break; default: var = " 0x" + hexCode[akAddr].ToString("X") + " "; break; } akAddr++; akAddr++; while (hexCode[akAddr] != 0x20) { addr += hexCode[akAddr] - 0x30; akAddr++; } tmp.ByteAddress = Convert.ToInt32(addr); akAddr++; if (bit == true) { tmp.BitAddress = Convert.ToInt32(hexCode[akAddr] - 0x30); } akAddr++; akAddr++; if (db != "") { addr = ""; while (hexCode[akAddr] != 0x20) { addr += hexCode[akAddr] - 0x30; akAddr++; } tmp.DatablockNumber = Convert.ToInt32(addr); } akAddr++; akAddr++; //0x30 akAddr++; akAddr++; //again akAddr++; akAddr++; //again size akAddr++; akAddr++; //0x30 akAddr++; akAddr++; //0x31 akAddr++; akAddr++; akAddr++; akAddr++; akAddr++; //View Sign switch (hexCode[akAddr]) { case 0x30: if (hexCode[akAddr - 1] == 0x31) { //showtype = "ZAEHLER"; tmp.LibNoDaveDataType = TagDataType.BCDWord; tmp.DataTypeStringFormat = TagDisplayDataType.Decimal; } else { //showtype = "BIN"; tmp.DataTypeStringFormat = TagDisplayDataType.Binary; } break; case 0x31: if (hexCode[akAddr - 1] == 0x31) { //showtype = "ZEIGER"; tmp.DataTypeStringFormat = TagDisplayDataType.Pointer; } else { //showtype = "HEX"; tmp.DataTypeStringFormat = TagDisplayDataType.Hexadecimal; } break; case 0x32: //showtype = "DEZ"; tmp.DataTypeStringFormat = TagDisplayDataType.Decimal; break; case 0x33: //showtype = "GLEITPUNKT"; tmp.LibNoDaveDataType = TagDataType.Float; tmp.DataTypeStringFormat = TagDisplayDataType.Float; break; case 0x34: //showtype = "ZEICHEN"; tmp.LibNoDaveDataType = TagDataType.Byte; tmp.DataTypeStringFormat = TagDisplayDataType.String; break; case 0x35: //showtype = "BOOL"; tmp.DataTypeStringFormat = TagDisplayDataType.Bool; break; case 0x36: //showtype = "ZEIT"; tmp.LibNoDaveDataType = TagDataType.Time; tmp.DataTypeStringFormat = TagDisplayDataType.Time; break; case 0x37: //showtype = "DATUM"; tmp.LibNoDaveDataType = TagDataType.Date; tmp.DataTypeStringFormat = TagDisplayDataType.S7Date; break; case 0x38: tmp.LibNoDaveDataType = TagDataType.S5Time; tmp.DataTypeStringFormat = TagDisplayDataType.S5Time; //showtype = "SIMATIC_ZEIT"; break; case 0x39: tmp.LibNoDaveDataType = TagDataType.TimeOfDay; tmp.DataTypeStringFormat = TagDisplayDataType.S7TimeOfDay; //showtype = "TAGESZEIT"; break; default: var = " 0x" + hexCode[akAddr].ToString("X") + " "; break; } akAddr++; while (hexCode[akAddr] != 0x00) { controlval += System.Text.Encoding.ASCII.GetString(new byte[] { hexCode[akAddr] }); akAddr++; } tmp.ParseControlValueFromString(controlval); akAddr++; Rows.Add(tmp); VATRows.Add(new S7VATRow() { LibNoDaveValue = tmp }); } else { akAddr++; VATRows.Add(new S7VATRow() {}); } } //string aa = System.Text.Encoding.ASCII.GetString(comments); int commentsRow = 12; int akLine = -1; while (commentsRow<comments.Length) { int akLen = comments[commentsRow] + comments[commentsRow + 1]*0x100; int akLinePlus = comments[commentsRow + 2] + comments[commentsRow + 3]*0x100; akLine += akLinePlus; VATRows[akLine].Comment = projEncoding.GetString(comments, commentsRow + 6, akLen); commentsRow += 6 + akLen; akLine++; } }
public static PLCTag GetPLCTagFromString(String plcAddress) { PLCTag retValue = new PLCTag(); retValue.ChangeAddressFromString(plcAddress); return retValue; }
public PLCTag(PLCTag oldTag) { if (oldTag != null) { this.TagDataSource = oldTag.TagDataSource; this.TagDataType = oldTag.TagDataType; this.ByteAddress = oldTag.ByteAddress; this.BitAddress = oldTag.BitAddress; this.ArraySize = oldTag.ArraySize; this.DataTypeStringFormat = oldTag.DataTypeStringFormat; this.DataBlockNumber = oldTag.DataBlockNumber; this.Controlvalue = oldTag.Controlvalue; this.DontSplitValue = oldTag.DontSplitValue; } }
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 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 cmdReadWithLibnodave_Click(object sender, EventArgs e) { try { txtWert.Text = ""; txtZeit.Text = ""; lblStatus.Text = ""; if (myConn == null) cmdConnect_Click(sender, e); PLCTag myTag = new PLCTag(txtTag.Text); byte[] tmp = new byte[myTag.ArraySize]; Stopwatch sw = new Stopwatch(); sw.Start(); int res = myConn._dc.readManyBytes(DotNetSiemensPLCToolBoxLibrary.Communication.LibNoDave.libnodave.daveDB, myTag.DataBlockNumber, myTag.ByteAddress, myTag.ArraySize, ref tmp); sw.Stop(); if (res != 0) { MessageBox.Show("Error using libnodave, readmaybytes! Code:" + res.ToString()); return; } txtZeit.Text = sw.ElapsedMilliseconds.ToString() + " ms"; string tmp2 = "{"; foreach (byte b in tmp) { tmp2 += b.ToString() + ","; } txtWert.Text = tmp2 + "}"; } catch (Exception ex) { lblStatus.Text = ex.Message; } }