//private Device SuperDevice; protected virtual void Awake() { _portUp = new DevicePort(this); _portDn = new DevicePort(this); _portLt = new DevicePort(this); _portRt = new DevicePort(this); }
/// <summary> /// Input connections to device /// </summary> /// <param name="cycle">Zero-based program cycle number</param> /// <returns></returns> private static List <Connection> Connections(int cycle) { var conns = new List <Connection>(); DevicePort aluPortOut = DevicePort.ALU; DevicePort shifterAluPortIn = DevicePort.Shifter; PortStatus aluPortOut_Stat; PortStatus shifterAluPortIn_Stat; InputsUsed(cycle, out aluPortOut_Stat, out shifterAluPortIn_Stat); var alu_label = ALUModel.OutputCalc(cycle).FormattedValue; conns.Add(new Connection( BusType.Data, aluPortOut, aluPortOut_Stat, alu_label, null, shifterAluPortIn, shifterAluPortIn_Stat)); return(conns); }
protected override void Awake() { gameObject.name = "Kiln " + gameObject.GetInstanceID(); inventory = new Inventory(1); _portUp = new DevicePort(this, Keywords.Names.PORT_TYPE_REQUESTER); print(gameObject.name + " is Awake"); }
/// <summary> /// Input connections to device /// </summary> /// <param name="bankID">BankID of the device</param> /// <param name="cycle">Zero-based program cycle number</param> /// <returns></returns> private static List <Connection> Connections(Bank bankID, int cycle) { var conns = new List <Connection>(); DevicePort mux0PortOut = DevicePort.Mux_0; DevicePort shifterPortOut = DevicePort.Shifter; DevicePort mux1Mux0PortIn = DevicePort.Default; DevicePort mux1ShifterPortIn = DevicePort.Default; PortStatus mux0PortOut_Stat; PortStatus shifterPortOut_Stat; PortStatus mux1Mux0PortIn_Stat; PortStatus mux1ShifterPortIn_Stat; InputsUsed(bankID, cycle, out mux0PortOut_Stat, out shifterPortOut_Stat, out mux1Mux0PortIn_Stat, out mux1ShifterPortIn_Stat); var mux0_label = Mux0Model.OutputCalc(cycle).FormattedValue; var shifter_label = ShifterModel.OutputCalc(cycle).FormattedValue; switch (bankID) { case Bank.Bank_A: mux1Mux0PortIn = DevicePort.Mux_1A; mux1ShifterPortIn = DevicePort.Mux_1A; break; case Bank.Bank_B: mux1Mux0PortIn = DevicePort.Mux_1B; mux1ShifterPortIn = DevicePort.Mux_1B; break; } conns.Add(new Connection( BusType.Data, mux0PortOut, mux0PortOut_Stat, mux0_label, null, mux1Mux0PortIn, mux1Mux0PortIn_Stat)); conns.Add(new Connection( BusType.Data, shifterPortOut, shifterPortOut_Stat, shifter_label, null, mux1ShifterPortIn, mux1ShifterPortIn_Stat)); return(conns); }
private void DijkstraFromProvider(DevicePort source) { List <DevicePort> vertexSet = new List <DevicePort>(); vertexSet.AddRange(providers); vertexSet.AddRange(requesters); vertexSet.AddRange(ribbons); List <DevicePort> unvisitedSet = new List <DevicePort>(); unvisitedSet.AddRange(vertexSet); foreach (DevicePort port in vertexSet) { port.dijkstraDistance = int.MaxValue; port.dijkstraPrevious = null; } source.dijkstraDistance = 0; // Loop while (unvisitedSet.Count > 0) { DevicePort shortestPathVertex = unvisitedSet[0]; foreach (DevicePort port in unvisitedSet) { if (port.dijkstraDistance < shortestPathVertex.dijkstraDistance) { shortestPathVertex = port; } } unvisitedSet.Remove(shortestPathVertex); if (shortestPathVertex.siblings != null) { foreach (DevicePort sibling in shortestPathVertex.siblings) { int newDistance = shortestPathVertex.dijkstraDistance; if (newDistance < sibling.dijkstraDistance) { sibling.dijkstraDistance = newDistance; sibling.dijkstraPrevious = shortestPathVertex; } } } if (shortestPathVertex.companion != null) { int newDistance = shortestPathVertex.dijkstraDistance + 1; if (newDistance < shortestPathVertex.companion.dijkstraDistance) { shortestPathVertex.companion.dijkstraDistance = newDistance; shortestPathVertex.companion.dijkstraPrevious = shortestPathVertex; } } } }
protected override void Awake() { _portUp = new DevicePort(this, Keywords.Names.PORT_TYPE_PROVIDER); _portDn = new DevicePort(this, Keywords.Names.PORT_TYPE_PROVIDER); _portLt = new DevicePort(this, Keywords.Names.PORT_TYPE_PROVIDER); _portRt = new DevicePort(this, Keywords.Names.PORT_TYPE_PROVIDER); gameObject.name = "Chest " + gameObject.GetInstanceID(); chestContents = new Inventory(8); print(gameObject.name + " is Awake"); }
public void GetNamePort(DevicePort product, ref HardwareStructure.MyComputer _data, int which) { try { _data.get_GridFanHub()[which].set_Name(product.Device + "(" + product.PortName + ")"); _data.get_GridFanHub()[which].set_PortName(product.PortName); } catch { } }
/// <summary> /// Input connections to device /// </summary> /// <param name="cycle">Zero-based program cycle number</param> /// <returns></returns> private static List <Connection> Connections(int cycle) { var conns = new List <Connection>(); DevicePort stagePortAOut = DevicePort.Stage_A; DevicePort stagePortBOut = DevicePort.Stage_B; DevicePort muxStagePortAIn = DevicePort.Mux_0; DevicePort muxStagePortBIn = DevicePort.Mux_0; PortStatus stagePortAOut_Stat; PortStatus stagePortBOut_Stat; PortStatus muxStagePortAIn_Stat; PortStatus muxStagePortBIn_Stat; InputsUsed(cycle, out stagePortAOut_Stat, out stagePortBOut_Stat, out muxStagePortAIn_Stat, out muxStagePortBIn_Stat); bool busRead_A; bool busRead_B; BusInModel.BusRead(cycle, out busRead_A, out busRead_B); var bankID = busRead_A ? Bank.Bank_A : Bank.Bank_B; var outputCalc = BusInModel.OutputCalc(bankID, cycle); var activeLabel = outputCalc.FormattedValue; conns.Add(new Connection( BusType.Data, stagePortAOut, stagePortAOut_Stat, activeLabel, null, muxStagePortAIn, muxStagePortAIn_Stat)); conns.Add(new Connection( BusType.Data, stagePortBOut, stagePortBOut_Stat, activeLabel, null, muxStagePortBIn, muxStagePortBIn_Stat)); return(conns); }
public void GetVoltage(DevicePort product, ref HardwareStructure.MyComputer _data, int which) { try { MyProtocolBytesTransfer.SetReadBytes(this._setReadBytes, 132, 0); MySerialPortProcess.ReadWriteCommand(this._setReadBytes, product, this._readReply); _data.get_GridFanHub()[which].set_DCVoltage(MyProtocolBytesTransfer.SetReplyVoltageCurrentBytes(this._readReply)); } catch { } }
protected override void Awake() { gameObject.name = "Ribbon " + gameObject.GetInstanceID(); _portUp = new DevicePort(this, Keywords.Names.PORT_TYPE_RIBBON); _portDn = new DevicePort(this, Keywords.Names.PORT_TYPE_RIBBON); _portLt = new DevicePort(this, Keywords.Names.PORT_TYPE_RIBBON); _portRt = new DevicePort(this, Keywords.Names.PORT_TYPE_RIBBON); _portUp.siblings.AddRange(new DevicePort[] { _portDn, _portLt, _portRt }); _portDn.siblings.AddRange(new DevicePort[] { _portUp, _portLt, _portRt }); _portLt.siblings.AddRange(new DevicePort[] { _portUp, _portDn, _portRt }); _portRt.siblings.AddRange(new DevicePort[] { _portUp, _portDn, _portLt }); }
public FormMain() { InitializeComponent(); // Initialize members devicePort = new DevicePort(); // Initialize COM ports this.buttonCOMPortRefresh_Click(this, null); // Initialize Backgroundworker this.backgroundWorkerCommunicate = new BackgroundWorker(); this.backgroundWorkerCommunicate.WorkerSupportsCancellation = false; this.backgroundWorkerCommunicate.WorkerReportsProgress = false; }
public void GetAllRPM(DevicePort product, ref HardwareStructure.MyComputer _data, int which) { try { for (int i = 1; i < 7; i++) { MyProtocolBytesTransfer.SetReadBytes(this._setReadBytes, 138, (byte)i); MySerialPortProcess.ReadWriteCommand(this._setReadBytes, product, this._readReply); _data.get_GridFanHub()[which].get_RPM()[i] = MyProtocolBytesTransfer.SetReplyRpmBytes(this._readReply); } } catch { } }
public DevicePort(Device parentDevice, string portType = null, DevicePort companion = null, List <DevicePort> siblings = null) { _parentDevice = parentDevice; graph = null; _portType = portType; _companion = companion; if (siblings == null) { this.siblings = new List <DevicePort>(); } else { this.siblings = siblings; } }
public static void ReadWriteCommand(byte[] commandBytes, DevicePort product, byte[] replyBytes) { try { if (!MySerialPortProcess.IfUpdatingFirmware) { lock (MySerialPortProcess._lock) { if (product.PortName != null && MySerialPortProcess.CheckSerialPortExist(product)) { if (!MySerialPortProcess.SerialPortList[product.PortName].IsOpen) { MySerialPortProcess.SerialPortList[product.PortName].Open(); } MySerialPortProcess.SerialPortList[product.PortName].Write(commandBytes, 0, commandBytes.Length); int num = 0; while (true) { num++; System.Threading.Thread.Sleep(10); if (MySerialPortProcess.SerialPortList[product.PortName].BytesToRead > 0) { break; } if (num > 20) { goto Block_9; } } System.Threading.Thread.Sleep(50); Block_9: int bytesToRead = MySerialPortProcess.SerialPortList[product.PortName].BytesToRead; byte[] array = new byte[bytesToRead]; MySerialPortProcess.SerialPortList[product.PortName].Read(array, 0, bytesToRead); MySerialPortProcess.CheckReplyValue(array, replyBytes); } } } } catch (System.IO.IOException) { } catch (System.Exception e) { ErrorXMLProcess.ExceptionProcess(e); } }
public void GetAllCurrent(DevicePort product, ref HardwareStructure.MyComputer _data, int which) { try { _data.get_GridFanHub()[which].get_DCAmpere()[0] = 0.0; for (int i = 1; i < 7; i++) { MyProtocolBytesTransfer.SetReadBytes(this._setReadBytes, 133, (byte)i); MySerialPortProcess.ReadWriteCommand(this._setReadBytes, product, this._readReply); _data.get_GridFanHub()[which].get_DCAmpere()[i] = MyProtocolBytesTransfer.SetReplyVoltageCurrentBytes(this._readReply); _data.get_GridFanHub()[which].get_DCAmpere()[0] += _data.get_GridFanHub()[which].get_DCAmpere()[i]; } } catch { } }
public void AddPort(DevicePort port) { if (port.portType == Keywords.Names.PORT_TYPE_PROVIDER) { AddProvider(port); } else if (port.portType == Keywords.Names.PORT_TYPE_REQUESTER) { AddRequester(port); } else if (port.portType == Keywords.Names.PORT_TYPE_RIBBON) { AddRibbon(port); } else { Debug.Log("ERROR\nCould not add port, unknown type: " + port.portType); } }
public virtual bool ToggleRt() { bool returnValue; if (portRt != null) { _portRt = null; returnValue = false; } else { _portRt = new DevicePort(this); returnValue = true; } if (_neighborRt != null) { _neighborRt.Notify(false, false, true, false); } return(returnValue); }
public virtual bool ToggleDn() { bool returnValue; if (portDn != null) { _portDn = null; returnValue = false; } else { _portDn = new DevicePort(this); returnValue = true; } if (_neighborDn != null) { _neighborDn.Notify(true, false, false, false); } return(returnValue); }
public string DEBUGGraphReport(DevicePort source) { string returnString = "GRAPH REPORT from " + source.parentDevice.gameObject.name + "\nPROVIDERS \n"; foreach (DevicePort port in providers) { returnString += ("\t" + port.parentDevice.gameObject.name + " as " + port.portType + "\n"); } returnString += "REQUESTERS \n"; foreach (DevicePort port in requesters) { returnString += ("\t" + port.parentDevice.gameObject.name + " as " + port.portType + "\n"); } returnString += "RIBBONS \n"; foreach (DevicePort port in ribbons) { returnString += ("\t" + port.parentDevice.gameObject.name + " as " + port.portType + "\n"); } return(returnString); }
//public PortPosition FromPortPosition; //public PortPosition ToPortPosition; //public double? Weight; //public double? Length; //public double? EdgePos_X; //public double? EdgePos_Y; //public List<EdgeColor> EdgeColorList; //public decimal? Penwidth; //public DirType? DirType; public Connection( BusType busType, DevicePort from, PortStatus fromPortActive, string fromPortActiveLabel, string fromPortInactiveLabel, DevicePort to, PortStatus toPortActive) { BusType = busType; From = from; FromPortActive = fromPortActive; FromPortActiveText = fromPortActiveLabel; FromPortInactiveText = fromPortInactiveLabel; To = to; ToPortActive = toPortActive; //EdgeColorList = new List<EdgeColor>(); }
private static bool CheckSerialPortExist(DevicePort product) { bool result; try { foreach (string current in MySerialPortProcess.SerialPortList.Keys) { if (current == product.PortName) { result = true; return(result); } } result = false; } catch (System.Exception e) { ErrorXMLProcess.ExceptionProcess(e); result = false; } return(result); }
public DevicePort[] GetDevicePorts() { var result = new List <DevicePort>(); foreach (var pinConfiguration in _pinConfigurations) { var item = new DevicePort() { PortName = pinConfiguration.PortName, PortType = pinConfiguration.PortType }; switch (pinConfiguration.PortType) { case PortTypes.Switch: case PortTypes.Pulse: var outputPin = _outputPins.First(p => p.PinId == pinConfiguration.PinId); item.PortState = GpioPinValueToPortState(outputPin.GpioPinValue); break; } result.Add(item); } return(result.ToArray()); }
public DevicePort GetPortByAddress(UInt32 address) { DevicePort res = null; foreach (var port in Port) { if (res == null && port.Address <= address) { res = port; } else if (port.Address <= address && res.Address < port.Address) { res = port; } } foreach (var r in Range) { if (r.Name == res.Range) { res.RangeObj = r; } } return(res); }
public virtual void DestroySelf() { _portUp = null; _portDn = null; _portLt = null; _portRt = null; if (_neighborUp != null) { _neighborUp.Notify(false, true, false, false); } if (_neighborDn != null) { _neighborDn.Notify(true, false, false, false); } if (_neighborLt != null) { _neighborLt.Notify(false, false, false, true); } if (_neighborRt != null) { _neighborRt.Notify(false, false, true, false); } Destroy(gameObject); }
public static DevicePort ProductInListFinder(string deviceName, int which) { int num = 0; DevicePort result; foreach (DevicePort current in MySerialPortProcess.DevicePortList) { if (current.Device == deviceName) { num++; if (num == which) { result = current; return(result); } } } result = new DevicePort { Device = null, PortName = null }; return(result); }
public override bool ToggleLt() { bool returnValue; if (portLt != null) { _portUp.siblings.Remove(_portLt); _portDn.siblings.Remove(_portLt); _portRt.siblings.Remove(_portLt); _portLt = null; returnValue = false; } else { _portLt = new DevicePort(this, Keywords.Names.PORT_TYPE_RIBBON, null, new List <DevicePort>(new DevicePort[] { _portUp, _portDn, _portRt })); returnValue = true; } ManagePart(false, false, true, false); if (_neighborLt != null) { _neighborLt.Notify(false, false, false, true); } return(returnValue); }
/// <summary> /// Input connections to device /// </summary> /// <param name="bankID">BankID of the device</param> /// <param name="cycle">Zero-based program cycle number</param> /// <returns></returns> private static List <Connection> Connections(Bank bankID, int cycle) { var conns = new List <Connection>(); DevicePort mux1PortOut = DevicePort.Default; DevicePort dataRamPortOut = DevicePort.Default; DevicePort mux2Mux1PortIn = DevicePort.Default; DevicePort mux2DataRamPortIn = DevicePort.Default; PortStatus mux1PortOut_Stat; PortStatus dataRamPortOut_Stat; PortStatus mux2Mux1PortIn_Stat; PortStatus mux2DataRamPortIn_Stat; var mux1_label = Mux1Model.OutputCalc(bankID, cycle).FormattedValue; var dataRam_label = DataRamModel.OutputCalc(bankID, cycle).FormattedValue; InputsUsed(bankID, cycle, out mux1PortOut_Stat, out dataRamPortOut_Stat, out mux2Mux1PortIn_Stat, out mux2DataRamPortIn_Stat); switch (bankID) { case Bank.Bank_A: mux1PortOut = DevicePort.Mux_1A; dataRamPortOut = DevicePort.DataRam_A; mux2Mux1PortIn = DevicePort.Mux_2A; mux2DataRamPortIn = DevicePort.Mux_2A; break; case Bank.Bank_B: mux1PortOut = DevicePort.Mux_1B; dataRamPortOut = DevicePort.DataRam_B; mux2Mux1PortIn = DevicePort.Mux_2B; mux2DataRamPortIn = DevicePort.Mux_2B; break; default: break; } conns.Add(new Connection( BusType.Data, mux1PortOut, mux1PortOut_Stat, mux1_label, null, mux2Mux1PortIn, mux2Mux1PortIn_Stat)); conns.Add(new Connection( BusType.Data, dataRamPortOut, dataRamPortOut_Stat, dataRam_label, null, mux2DataRamPortIn, mux2DataRamPortIn_Stat)); return(conns); }
private void SetCompanion(DevicePort companionPort) { if (companionPort == null) { // Split the graph at this port. return; } if (graph == null && companionPort.graph == null) { // Create a new graph. graph = new RibbonGraph(); graph.AddPort(this); foreach (DevicePort siblingPort in siblings) { graph.AddPort(siblingPort); siblingPort.graph = graph; } _companion = companionPort; companionPort.companion = this; Debug.Log(graph.DEBUGGraphReport(this)); } else if (graph == companionPort.graph) { // Just recompute paths. _companion = companionPort; // Escape from set cycle if (companionPort.companion != this) { companionPort.companion = this; } Debug.Log(graph.DEBUGGraphReport(this)); } else if (graph == null && companionPort.graph != null) { // Join companionPort's graph. graph = companionPort.graph; graph.AddPort(this); foreach (DevicePort siblingPort in siblings) { graph.AddPort(siblingPort); siblingPort.graph = graph; } _companion = companionPort; companionPort.companion = this; Debug.Log(graph.DEBUGGraphReport(this)); } else if (graph != null && companionPort.graph == null) { // Just set _companion, companionPort will join this graph. _companion = companionPort; companionPort.companion = this; Debug.Log(graph.DEBUGGraphReport(this)); } else { // Merge this port's graph into companionPort's _companion = companionPort; companionPort.graph.mergeGraph(graph); companionPort.companion = this; Debug.Log(graph.DEBUGGraphReport(this)); } }
public static bool IfDevicePortExists(System.Collections.Generic.List <DevicePort> DevicePortList, DevicePort device) { bool result; for (int i = 0; i < DevicePortList.Count; i++) { if (DevicePortList[i].Device == device.Device && DevicePortList[i].PortName == device.PortName) { result = true; return(result); } } result = false; return(result); }
public void AddRibbon(DevicePort port) { ribbons.Add(port); }