internal void GetAllTagsAsync() { if (CurrentBlock.Value.Name.Equals("Symbols")) { AllTags = Symbols; return; } else if (!(CurrentBlock.Value.Name.ToLower().StartsWith("db"))) { return; } S7DataBlock blk = (S7DataBlock)CurrentBlock.Value.BlockContents; ExportTable.KepwareExportTableDataTable exportTable = new ExportTable.KepwareExportTableDataTable(); AddChildrenToKepwareExportTable(exportTable, blk.Structure.Children, CurrentBlock.Value.SymbolicName, CurrentBlock.Value); Dictionary<String, Tag> myTags = new Dictionary<string,Tag>(); foreach (ExportTable.KepwareExportTableRow Row in exportTable) { Regex LastNumberInString = new Regex("(\\d+)(?!.*\\d)"); Tag NewTag = new Tag() { Name = Row.Tag_Name, AreaTypeParameter = Trending.AREA_TYPE.DB}; String[] SplitAddress = Row.Address.Split('.'); if (SplitAddress.Length == 2) NewTag.BitOffset = 0; else NewTag.BitOffset = int.Parse(LastNumberInString.Match(Row.Address).Value); NewTag.ByteOffset = int.Parse(LastNumberInString.Match(Row.Address.Split('.')[1]).Value); NewTag.DbNumber = int.Parse(LastNumberInString.Match(Row.Address.Split('.')[0]).Value); NewTag.Address = Row.Address; myTags.Add(Row.Tag_Name, NewTag); } AllTags = myTags; }
public String ReadBytes(Tag Tag) { int res; byte[] buffer = new byte[4]; res = PLCConnection.readBytes((int)Tag.AreaTypeParameter, Tag.DbNumber, Tag.ByteOffset, 4, buffer); if (res == 0) { switch (Tag.DataType) { case DATA_TYPES.TYPE_BOOL: return (new BitArray(buffer[0])).Get(Tag.BitOffset).ToString(); break; case DATA_TYPES.TYPE_FLOAT: return PLCConnection.getS32().ToString(); break; case DATA_TYPES.TYPE_INT: return PLCConnection.getS16().ToString(); break; } } throw new Exception("Unable to read data block DB " + Tag.DbNumber + "."); }
private Dictionary<String, Tag> GetSymbolTableFromProject(List<ProjectFolder> folders) { //create new list List<SymbolTableEntry> s = GetSymbolEntries(folders); Dictionary<String,Tag> SymbolTable = new Dictionary<string,Tag>(); foreach (SymbolTableEntry sym in s) { Tag NewTag = new Tag(); NewTag.Name = sym.Symbol; NewTag.Address = sym.Operand; switch (sym.Operand.First()) { case 'I': NewTag.AreaTypeParameter = Trending.AREA_TYPE.IN; break; case 'M': NewTag.AreaTypeParameter = Trending.AREA_TYPE.MEMORY; break; case 'Q': NewTag.AreaTypeParameter = Trending.AREA_TYPE.OUT; break; default: NewTag.AreaTypeParameter = Trending.AREA_TYPE.DB; break; } Regex LastNumberInString = new Regex("(\\d+)(?!.*\\d)"); String[] SplitAddress = sym.Operand.Split('.'); if (SplitAddress.Length == 1) { NewTag.BitOffset = 0; NewTag.ByteOffset = int.Parse(LastNumberInString.Match(sym.Operand).Value); } else { NewTag.BitOffset = int.Parse(LastNumberInString.Match(sym.Operand).Value); NewTag.ByteOffset = int.Parse(LastNumberInString.Match(sym.Operand.Split('.')[0]).Value); } if (!SymbolTable.ContainsKey(sym.Symbol)) SymbolTable.Add(sym.Symbol, NewTag); } return SymbolTable; }
public void LogTagData(Tag tag, string value, DateTime time) { try { if (!Directory.Exists(S7_DMCToolbox.Properties.Settings.Default.TrendLogDirectory)) Directory.CreateDirectory(S7_DMCToolbox.Properties.Settings.Default.TrendLogDirectory); var info = time.ToString("yyyy-MM-dd hh:mm:ss.ff") + "," + //DateTime.Now.ToString("hh:mm:ss") + "," + tag.Name + "," + value + "\r\n"; File.AppendAllText(S7_DMCToolbox.Properties.Settings.Default.TrendLogDirectory+ "Tag_" + tag.Name + ".csv", info); } catch (Exception ex) { MessageBox.Show("Error Logging to File!\r\n\r\n" + ex.Message); //logger.ErrorException("Error Logging to File", ex); } }