Stream(ArrayList data, VoltageType voltType) { data.Add(new Snoop.Data.ClassSeparator(typeof(VoltageType))); data.Add(new Snoop.Data.Double("Actual value", voltType.ActualValue)); data.Add(new Snoop.Data.Bool("Is in use", voltType.IsInUse)); data.Add(new Snoop.Data.Double("Max value", voltType.MaxValue)); data.Add(new Snoop.Data.Double("Min value", voltType.MinValue)); }
/// <summary> /// 设置电压类型 /// </summary> /// <param name="type"></param> /// <param name="value"></param> private void SetVoltageType(VoltageType type, bool value) { VoltageType setType = VoltageType.Effective; switch (type) { case VoltageType.Effective: setType = value ? VoltageType.Effective : VoltageType.Peak; break; case VoltageType.Peak: setType = value ? VoltageType.Peak : VoltageType.Effective; break; } Cache.Instance.Cards.ForEach(c => { c.VoltageType = setType; c.Channels.ForEach(h => h.VoltageType = setType); }); }
private void Stream(ArrayList data, VoltageType voltType) { data.Add(new Snoop.Data.ClassSeparator(typeof(VoltageType))); data.Add(new Snoop.Data.Double("Actual value", voltType.ActualValue)); data.Add(new Snoop.Data.Bool("Is in use", voltType.IsInUse)); data.Add(new Snoop.Data.Double("Max value", voltType.MaxValue)); data.Add(new Snoop.Data.Double("Min value", voltType.MinValue)); }
Stream(ArrayList data, ElementType sym) { data.Add(new Snoop.Data.ClassSeparator(typeof(ElementType))); // no data at this level yet AnnotationSymbolType annoType = sym as AnnotationSymbolType; if (annoType != null) { Stream(data, annoType); return; } AreaReinforcementType areaReinforcementType = sym as AreaReinforcementType; if (areaReinforcementType != null) { Stream(data, areaReinforcementType); return; } AreaTagType areaTagType = sym as AreaTagType; if (areaTagType != null) { Stream(data, areaTagType); return; } BeamSystemType beamSystemType = sym as BeamSystemType; if (beamSystemType != null) { Stream(data, beamSystemType); return; } DimensionType dimType = sym as DimensionType; if (dimType != null) { Stream(data, dimType); return; } //TF FabricSheetType fabricST = sym as FabricSheetType; if (fabricST != null) { Stream(data, fabricST); return; } FabricWireType fabricWT = sym as FabricWireType; if (fabricWT != null) { Stream(data, fabricWT); return; } //TFEND GroupType groupType = sym as GroupType; if (groupType != null) { Stream(data, groupType); return; } HostObjAttributes hostAtt = sym as HostObjAttributes; if (hostAtt != null) { Stream(data, hostAtt); return; } InsertableObject insObj = sym as InsertableObject; if (insObj != null) { Stream(data, insObj); return; } LevelType levelType = sym as LevelType; if (levelType != null) { Stream(data, levelType); return; } LineAndTextAttrSymbol lineAndTextAttr = sym as LineAndTextAttrSymbol; if (lineAndTextAttr != null) { Stream(data, lineAndTextAttr); return; } LoadTypeBase loadTypeBase = sym as LoadTypeBase; if (loadTypeBase != null) { Stream(data, loadTypeBase); return; } MEPBuildingConstruction mepBldConst = sym as MEPBuildingConstruction; if (mepBldConst != null) { Stream(data, mepBldConst); return; } PathReinforcementType pathReinforcementType = sym as PathReinforcementType; if (pathReinforcementType != null) { Stream(data, pathReinforcementType); return; } RebarBarType rebarBarType = sym as RebarBarType; if (rebarBarType != null) { Stream(data, rebarBarType); return; } RebarCoverType rebarCoverType = sym as RebarCoverType; if (rebarCoverType != null) { Stream(data, rebarCoverType); return; } RebarHookType rebarHookType = sym as RebarHookType; if (rebarHookType != null) { Stream(data, rebarHookType); return; } RebarShape rebarShape = sym as RebarShape; if (rebarShape != null) { Stream(data, rebarShape); return; } RoomTagType roomTagType = sym as RoomTagType; if (roomTagType != null) { Stream(data, roomTagType); return; } SpaceTagType spaceTagType = sym as SpaceTagType; if (spaceTagType != null) { Stream(data, spaceTagType); return; } TrussType trussType = sym as TrussType; if (trussType != null) { Stream(data, trussType); return; } DistributionSysType distSysType = sym as DistributionSysType; if (distSysType != null) { Stream(data, distSysType); return; } MEPCurveType mepCurType = sym as MEPCurveType; if (mepCurType != null) { Stream(data, mepCurType); return; } FluidType fluidType = sym as FluidType; if (fluidType != null) { Stream(data, fluidType); return; } PipeScheduleType pipeSchedType = sym as PipeScheduleType; if (pipeSchedType != null) { Stream(data, pipeSchedType); return; } VoltageType voltType = sym as VoltageType; if (voltType != null) { Stream(data, voltType); return; } WireType wireType = sym as WireType; if (wireType != null) { Stream(data, wireType); return; } ModelTextType modelTxtType = sym as ModelTextType; if (modelTxtType != null) { Stream(data, modelTxtType); return; } }
private double GetVoltage(VoltageType type) { short busy; // Select and access the ID of the device we want to talk to Adapter.Select(Id); // Data buffer to send over the network var data = new byte[30]; // How many bytes of data to send short dataCount = 0; // Set the command to recall the status/configuration page to the scratchpad data[dataCount++] = 0xB8; // Set the page number to recall data[dataCount++] = 0x00; // Send the data block Adapter.SendBlock(data, dataCount); // Clear the data count dataCount = 0; // Access the device we want to talk to Adapter.Access(); // Set the command to read the scratchpad data[dataCount++] = 0xBE; // Set the page number to read data[dataCount++] = 0x00; // Add 9 bytes to be read - 8 for the data and 1 for the CRC for (var index = 0; index < 9; index++) data[dataCount++] = 0xFF; // Send the data block Adapter.SendBlock(data, dataCount); // Calculate the CRC of the scratchpad data var crc = Crc8.Calculate(data, 2, 9); // If the CRC doesn't match then throw an exception if (crc != data[10]) { // Throw a CRC exception throw new OneWireException(OneWireException.ExceptionFunction.Crc, Id); } // TODO - Check if we really need to change the input selector if (true) { // Access the device we want to talk to Adapter.Access(); // Reset the data count dataCount = 0; // Set the command to write the scratchpad data[dataCount++] = 0x4E; // Set the page number to write data[dataCount++] = 0x00; // Set or clear the AD bit based on the type requested if (type == VoltageType.Supply) data[dataCount++] = (byte) (data[2] | 0x08); else data[dataCount++] = (byte) (data[2] & 0xF7); // Move the existing data down in the array for (var index = 0; index < 7; index++) data[dataCount++] = data[index + 4]; // Send the data block Adapter.SendBlock(data, dataCount); // Reset the data count dataCount = 0; // Access the device we want to talk to Adapter.Access(); // Set the command to copy the scratchpad data[dataCount++] = 0x48; // Set the page number to copy to data[dataCount++] = 0x00; // Send the data block Adapter.SendBlock(data, dataCount); // Loop until the data copy is complete do { busy = Adapter.ReadByte(); } while (busy == 0); } // Access the device we want to talk to Adapter.Access(); // Send the voltage conversion command Adapter.SendByte(0xB4); // Loop until conversion is complete do { busy = Adapter.ReadByte(); } while (busy == 0); // Clear the data count dataCount = 0; // Set the command to recall the status/configuration page to the scratchpad data[dataCount++] = 0xB8; // Set the page number to recall data[dataCount++] = 0x00; // Access the device we want to talk to Adapter.Access(); // Send the data block Adapter.SendBlock(data, dataCount); // Clear the data count dataCount = 0; // Access the device we want to talk to Adapter.Access(); // Set the command to read the scratchpad data[dataCount++] = 0xBE; // Set the page number to read data[dataCount++] = 0x00; // Add 9 bytes to be read - 8 for the data and 1 for the CRC for (var index = 0; index < 9; index++) data[dataCount++] = 0xFF; // Send the data block Adapter.SendBlock(data, dataCount); // Calculate the CRC of the scratchpad data crc = Crc8.Calculate(data, 2, 9); // If the CRC doesn't match then throw an exception if (crc != data[10]) { // Throw a CRC exception throw new OneWireException(OneWireException.ExceptionFunction.Crc, Id); } // Assemble the voltage data var dVoltage = (double) ((data[6] << 8) | data[5]); return dVoltage / 100; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; #region Clear the existing system. TaskDialogResult r = TaskDialog.Show("Note", "This will clear the existing " + "electrical system.Continue?", TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No); if (r == TaskDialogResult.No) { return(Result.Failed); } using (Transaction tx = new Transaction(doc)) { tx.Start("Clear existing system."); FilteredElementCollector col = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .OfCategory(BuiltInCategory.OST_ElectricalCircuit); Stack <ElementId> sysId = new Stack <ElementId>(); foreach (Element e in col) { sysId.Push(e.Id); } while (sysId.Count > 0) { doc.Delete(sysId.Pop()); } tx.Commit(); } #endregion #region Check the default settings. const string elecSettingName = "DefaultElectricalSettingExcuted"; GlobalParameter SettingP = doc.GetElement( GlobalParametersManager.FindByName (doc, elecSettingName)) as GlobalParameter; if (SettingP == null) { //Set the voltage and distribution to default using (Transaction tx = new Transaction(doc)) { tx.Start("Autoset electrical setting"); ElectricalSetting ElecSet = ElectricalSetting .GetElectricalSettings(doc); VoltageType VtypeHome = ElecSet .AddVoltageType("Home", 220, 200, 250); ElecSet.AddDistributionSysType ("Lighting", ElectricalPhase.SinglePhase, ElectricalPhaseConfiguration.Undefined, 2, null, VtypeHome); ElecSet.AddDistributionSysType ("Outlet", ElectricalPhase.SinglePhase, ElectricalPhaseConfiguration.Undefined, 2, null, VtypeHome); GlobalParameter.Create (doc, elecSettingName, ParameterType.Number); tx.Commit(); } } #endregion #region Retrieve elements from database List <ElementId> LightIds = new List <ElementId>(); List <ElementId> OutletIds = new List <ElementId>(); List <ElementId> HVACIds = new List <ElementId>(); FilteredElementCollector colLight = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_LightingFixtures) .WhereElementIsNotElementType(); FilteredElementCollector colOutlet = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_ElectricalFixtures) .WhereElementIsNotElementType(); FilteredElementCollector colHVAC = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_MechanicalEquipment) .WhereElementIsNotElementType(); foreach (Element e in colLight) { LightIds.Add(e.Id); } foreach (Element e in colOutlet) { OutletIds.Add(e.Id); } foreach (Element e in colHVAC) { if (HasElectricalConnector(e)) { HVACIds.Add(e.Id); } } #endregion Retrieve elements from databa //Locate the electrical main box. FamilyInstance ElecBox = null; do { try { Selection sel = uidoc.Selection; TaskDialog.Show("Choose", "Please " + "select one electrical box after " + "closing the dialog.\n" + "请在关闭窗口后选择一个配电箱。"); ElementId ElecBoxId = sel.PickObject (ObjectType.Element, new SelFilterElecEquip() , "Select the main box").ElementId; ElecBox = doc.GetElement(ElecBoxId) as FamilyInstance; } catch (Exception ex) { TaskDialog.Show("Error", "Something went wrong.\n" + ex.Message); return(Result.Failed); } } while ((ElecBox.MEPModel as ElectricalEquipment) .DistributionSystem == null); // Create the electrical system using (Transaction tx = new Transaction(doc)) { tx.Start("Create ElectricalSystem"); ElectricalSystem LightingCircuit = ElectricalSystem.Create(doc, LightIds, ElectricalSystemType.PowerCircuit); LightingCircuit.Name = "LightingCircuit"; LightingCircuit.SelectPanel(ElecBox); ElectricalSystem OutlietCircuit = ElectricalSystem.Create(doc, OutletIds, ElectricalSystemType.PowerCircuit); OutlietCircuit.Name = "OutletCircuit"; OutlietCircuit.SelectPanel(ElecBox); ElectricalSystem HVACCircuit = ElectricalSystem.Create(doc, HVACIds, ElectricalSystemType.PowerCircuit); HVACCircuit.Name = "HVACCircuit"; HVACCircuit.SelectPanel(ElecBox); tx.Commit(); } TaskDialog.Show("Result", "Default systems have been created.\n" + "Please do not change system name.\n" + "已创建默认系统,请勿修改系统名,将影响后续计算\n" + "可手动调整系统内末端."); return(Result.Succeeded); }