private void cn_ButtonAdd_Click(object sender, EventArgs e) { try { if (m_ParBlock.RowState == System.Data.DataRowState.Detached) { MessageBox.Show(Resources.tx_TagsCollection_pleasecreatedatablockfirst); return; } m_DB.EnforceConstraints = false; ComunicationNet.TagsRow cNTG = m_DB.Tags.NewTagsRow(m_ParBlock.DatBlockID, m_ParBlock.Name); TagsRowWrapper cRW = new TagsRowWrapper(cNTG, dataBlockRowWrapper, true); using (AddObject <TagsRowWrapper> cDial = new AddObject <TagsRowWrapper>(cRW)) { cDial.ShowDialog(this); if (cDial.DialogResult != DialogResult.OK) { cNTG.Delete(); cRW.AddUnfinishedCleanup(); return; } } cRW.AddObjectToTable(); FillLlist(cn_listBox.Items.Count - 1); } catch (Exception) { } finally { m_DB.EnforceConstraints = true; } }
protected override DataBlock.Tag newTag(ComunicationNet.TagsRow currRow, IStationState myStationState, int myAddress, short myDataType, IDataWrite myWriteInt) { #if COMMSERVER Opc.Da.ItemPropertyCollection prop_coll = ItemDescriber2OpcDA.GetItemPropertiesCollection(currRow.Name, Initialization.m_ds_dsc); #else Opc.Da.ItemPropertyCollection prop_coll=null; #endif return new TagDataDescription(currRow, myStationState, myAddress, myDataType, myWriteInt, prop_coll); }
private void CreateAllTags(ComunicationNet.TagsRow[] tagsDsc, out int length, IDataWrite myWriteInt, int myAddress, short myDataType, IStationState myStationState, ref int cVConstrain) { SortedList sortedTgs = new SortedList(); foreach (ComunicationNet.TagsRow curr in tagsDsc) { if (cVConstrain > 0) { sortedTgs.Add(curr.TagID, curr); cVConstrain--; } } length = sortedTgs.Count; tagHendlers = new Tag[length]; for (ushort idx = 0; (idx < length); idx++) { ComunicationNet.TagsRow currRow = (ComunicationNet.TagsRow)sortedTgs.GetByIndex(idx); tagHendlers[idx] = newTag(currRow, myStationState, myAddress + idx, myDataType, myWriteInt); } }//CreateAllTags
/// <summary> /// Gets the data type from configuration row. /// </summary> /// <param name="myDSC">Tag description as row from configuration.</param> /// <returns></returns> internal static System.Type GetDataTypeFromConfig(ComunicationNet.TagsRow myDSC) { System.Type typetobereturned = null; if (!myDSC.IsDataTypeConversionNull()) { try { typetobereturned = System.Type.GetType(myDSC.DataTypeConversion); } catch (Exception ex) { EventLogMonitor.WriteToEventLogInfo("Unknown type:" + myDSC.DataTypeConversion + "; conversion exception info:" + ex.Message, 128); } if (typetobereturned == null) EventLogMonitor.WriteToEventLogInfo("Unknown type:" + myDSC.DataTypeConversion, 166); } if (typetobereturned != null) return typetobereturned; else return typeof(object); }
protected abstract Tag newTag(ComunicationNet.TagsRow currRow, IStationState myStationState, int myAddress, short myDataType, IDataWrite myWriteInt);
/// <summary> /// Tag constructor /// </summary> /// <param name="myDSC">parameters from Tags table</param> /// <param name="myStation">pointer to interface that allow to change priority of the station</param> internal Tag(ComunicationNet.TagsRow myDSC, IStationState myStation) : base(myDSC.Name, null, qualityBits.badNotConnected, (ItemAccessRights)myDSC.AccessRights, GetDataTypeFromConfig(myDSC)) { switch ((StateTrigger)myDSC.StateTrigger) { case StateTrigger.StateHigh: stateHihgTriger = true; break; case StateTrigger.StateLow: stateLowTriger = true; break; default: break; } stateMask = (int)myDSC.StateMask; this.myStation = myStation; this.EuType = Opc.Da.euType.noEnum; ItemPropertyCollection itemPropertyCollection = new ItemPropertyCollection(); foreach (ComunicationNet.ItemPropertiesTableRow row_property in myDSC.GetItemPropertiesTableRows()) { try { PropertyDescription prop_dsc = PropertyDescription.Find( new PropertyID( new XmlQualifiedName(row_property.ID_Name_Name, row_property.ID_Name_Namespace) )); ItemProperty _itemProperty = new ItemProperty { ID = prop_dsc.ID, Value = row_property.Value }; if (prop_dsc.ID != Opc.Da.Property.DATATYPE) //this property is managed differently // as GetDataTypeFromConfig( myDSC ) // at the constructor { if (prop_dsc.ID == Opc.Da.Property.HI_LIMIT || prop_dsc.ID == Opc.Da.Property.LO_LIMIT || prop_dsc.ID == Opc.Da.Property.HIHI_LIMIT || prop_dsc.ID == Opc.Da.Property.LOLO_LIMIT || prop_dsc.ID == Opc.Da.Property.LOWEU || prop_dsc.ID == Opc.Da.Property.HIGHEU || prop_dsc.ID == Opc.Da.Property.SCANRATE ) { // this property contains double value if (double.TryParse(row_property.Value, out double prop_value)) _itemProperty.Value = prop_value; } if (prop_dsc.ID == Opc.Da.Property.EUTYPE) { _itemProperty.Value = Opc.Da.euType.noEnum; // this property contains vale from enum: Opc.Da.euType foreach (Opc.Da.euType NEWeuType in Enum.GetValues(typeof(Opc.Da.euType))) { if (NEWeuType.ToString() == row_property.Value) _itemProperty.Value = NEWeuType; } } if (prop_dsc.ID == Opc.Da.Property.EUINFO) { //I assume that this is table of strings spited by ; _itemProperty.Value = row_property.Value.Split(';'); } itemPropertyCollection.Add(_itemProperty); } } catch (Exception ex) { CommServerComponent.Tracer.TraceInformation(290, "DataBlock.Tag", "Problem with property for item : " + myDSC.Name + ": " + TraceEvent.GetMessageWithExceptionNameFromExceptionIncludingInnerException(ex)); } } try { this.AddProperties(itemPropertyCollection); } catch (Exception ex) { CommServerComponent.Tracer.TraceInformation(290, "DataBlock.Tag", "Problem with many properties for item : " + myDSC.Name + ": " + TraceEvent.GetMessageWithExceptionNameFromExceptionIncludingInnerException(ex)); } }
private void MainImportJob(object sender, DoWorkEventArgs e) { BackgroundWorker _BackgroundWorker = sender as BackgroundWorker; ProgressBarWindow _ProgressBarWindow = e.Argument as ProgressBarWindow; long _stationID = 0; ulong _timeScan = 0, _timeout = 0, _timeScanFast = 0, _timOutFast = 0; ulong _address = 0; byte _dataType = 0; int _length = 0; int _originalLen = m_CSVContainer.ToString().Length; _ProgressBarWindow.SetInformation("ImportingCSV"); while (m_CSVContainer.ToString().Length > 0 && !_BackgroundWorker.CancellationPending) { _ProgressBarWindow.SetProgressValue(_originalLen - m_CSVContainer.ToString().Length); try { _stationID = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement()); _timeScan = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement()); _timeout = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement()); _timeScanFast = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement()); _timOutFast = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement()); _address = Convert.ToUInt32(m_CSVContainer.GetAndMove2NextElement()); _dataType = Convert.ToByte(m_CSVContainer.GetAndMove2NextElement()); _length = Convert.ToInt32(m_CSVContainer.GetAndMove2NextElement()); //odczytalismy wszystkie elememty definiuj¹ce dany blok danych //znajdujemy odpowiednia stacje ComunicationNet.StationRow _stationRow = null; try { _stationRow = m_Database.Station.FindByStationID(_stationID); } catch { throw new Exception("station " + _stationID.ToString() + "not found"); } ComunicationNet.GroupsRow _GroupsRow = m_Database.Groups.NewGroupsRow(); _GroupsRow.Name = "GR_" + _GroupsRow.GroupID.ToString() + "_st_" + _stationRow.Name; _GroupsRow.StationID = _stationID; _GroupsRow.TimeOut = _timeout; _GroupsRow.TimeOutFast = _timOutFast; _GroupsRow.TimeScan = _timeScan; _GroupsRow.TimeScanFast = _timeScanFast; m_Database.Groups.AddGroupsRow(_GroupsRow); ComunicationNet.DataBlocksRow _dataBlocksRow = m_Database.DataBlocks.NewDataBlocksRow(); _dataBlocksRow.Name = "db" + _GroupsRow.GroupID.ToString() + "_st_" + _stationRow.Name; _dataBlocksRow.GroupID = _GroupsRow.GroupID; _dataBlocksRow.Address = _address; _dataBlocksRow.DataType = _dataType; m_Database.DataBlocks.AddDataBlocksRow(_dataBlocksRow); for (int idx = 0; idx < _length; idx++) { ComunicationNet.TagsRow _tagRow = m_Database.Tags.NewTagsRow(); _tagRow.Name = _stationRow.Name + "/" + _dataType.ToString() + "/" + "add" + (_address + (ulong)idx).ToString(); _tagRow.AccessRights = (sbyte)ItemAccessRights.ReadWrite; _tagRow.StateTrigger = (sbyte)StateTrigger.None; _tagRow.Alarm = false; _tagRow.AlarmMask = 0; _tagRow.StateMask = 0; _tagRow.DatBlockID = _dataBlocksRow.DatBlockID; m_Database.Tags.AddTagsRow(_tagRow); m_TagsAddedNumber++; } } catch (Exception ex) { AppendToLog("Error: " + ex.Message + " at \r\n" + _stationID.ToString() + "," + _timeScan.ToString() + "," + _timeout.ToString() + "," + _timeScanFast.ToString() + "," + _timOutFast.ToString() + "," + _address.ToString() + "," + _dataType.ToString() + "," + _length.ToString()); } } }