static void Main(string[] args) { // construct the quantum simulator using (var sim = new QuantumSimulator()) { // Try initial values Result[] initials = new Result[] { Result.Zero, Result.One }; foreach (Result initial in initials) { // we pass the simulator, initial count of 1000, and an initial qubit value // Note that the run method is asynchronous. // Each Q# operation has a corresponding C# class, for which a Run method belongs to the class // the Run method performs asynchronous executions of the given operations // note that our results for BellTest are strored in a tuple var results1 = XGate.Run(sim, 1000, initial).Result; // here we perform a Hadamard gate operation, for which our qubit is placed from the ground or exited state into // a superposition state of either |0> or |1> var results2 = HGate.Run(sim, 1000, initial).Result; // Places two bits a Bell State, which is in essence a superposition of two qubits that are entangled var res = BellTest.Run(sim, 1000, initial).Result; // caste results into a tuple, for easy access var(numZeros, numOnes, agree) = res; var play = Playground.Run(sim, 1000, initial).Result; var(nOnes, nZeros, agreement) = play; // System.Console.WriteLine($"Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4} agree={agree, -4}"); System.Console.WriteLine($"Init:{initial,-4} 0s={nZeros,-4} 1s={nOnes,-4} agree={agreement,-4}"); } } System.Console.WriteLine("Press any key to continue..."); System.Console.ReadKey(); }
//启动控制器 public void StartController(string ip) { this.Do(() => { this.xgate = new XGate(ip, 2); this.xgate.DeviceErrorCallback += xgate_DeviceErrorCallback; this.xgate.PickedInforCallback += xgate_PickedInforCallback; //关闭 for (int i = 1; i < 11; i++) { this.xgate.Clear900U(i); this.xgate.Close(); //this.xgate.ClearAll(); } //int address = this.TryParseAddress(); //打开 for (int i = 1; i < 11; i++) { this.xgate.Add900U(i, i / 100); this.xgate.Start(); //this.xgate.ClearAll(); } Xopen = true; }); }
void xgate_DeviceErrorCallback(XGate xgate, Device PTLDevice, Exception error) { this.BeginInvoke(new MethodInvoker(() => { IniHelper.WriteLog(error); })); }
/// <summary> /// 启动通讯。 /// </summary> public void Start() { IPAddress ipAddress = IPAddress.Parse(this.xGateIP); IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, XGate.DefaultIPEndPointPort); this.XGate = new XGate(ipEndPoint, 1, 5000, 5000, 5000, 0, DefaultRS485AddressMapper.Original); // 8 个库位标签 for (byte i = 1; i <= 8; i++) { Ptl900U ptl900U = new Ptl900U(); ptl900U.Address = i; ptl900U.MinorType = Ptl900UType.P24; this.XGate.Buses[RS485BusName.Bus1].Devices.AddOrUpdate(ptl900U); this.lastDeviceErrorTime.Add(ptl900U.Address, DateTime.MinValue); } // 1 个中文信息屏 Ptl900U ptl900UPublisher = new Ptl900U(); ptl900UPublisher.Address = 9; ptl900UPublisher.MinorType = Ptl900UType.S1; this.XGate.Buses[RS485BusName.Bus1].Devices.AddOrUpdate(ptl900UPublisher); this.lastDeviceErrorTime.Add(ptl900UPublisher.Address, DateTime.MinValue); // 1 个指示球灯 Ptl900U ptl900ULight = new Ptl900U(); ptl900ULight.Address = 10; ptl900ULight.MinorType = Ptl900UType.P0; this.XGate.Buses[RS485BusName.Bus1].Devices.AddOrUpdate(ptl900ULight); this.lastDeviceErrorTime.Add(ptl900ULight.Address, DateTime.MinValue); this.XGate.StartUnicastCommandQueue(); foreach (RS485Bus rs485Bus in this.XGate.Buses) { rs485Bus.CommunicationClient.ConnectedChanged += this.rs485Bus_CommunicationClient_ConnectedChanged; foreach (PtlDevice ptlDevice in rs485Bus.Devices) { ptlDevice.InErrorChanged += this.ptlDevice_InErrorChanged; ptlDevice.Initialize(); } } //寻车指示灯始终锁定 ptl900ULight.Lock(); }
/// <summary> /// 停止通讯。 /// </summary> public void Stop() { this.lastDeviceErrorTime.Clear(); this.lastConnectionErrorTime = DateTime.MinValue; foreach (RS485Bus rs485Bus in this.XGate.Buses) { rs485Bus.CommunicationClient.ConnectedChanged -= this.rs485Bus_CommunicationClient_ConnectedChanged; foreach (PtlDevice ptlDevice in rs485Bus.Devices) { ptlDevice.InErrorChanged -= this.ptlDevice_InErrorChanged; } } this.XGate.StopUnicastCommandQueue(); this.XGate.Dispose(); this.XGate = null; }
/// <summary> /// 停止所有转台的 PTL 通讯。 /// </summary> public void Stop() { foreach (RS485Bus rs485Bus in this.xGate.Buses) { foreach (PtlDevice ptlDevice in rs485Bus.Devices) { ptlDevice.InErrorChanged -= this.ptlDevice_InErrorChanged; } } this.xGate.StopUnicastCommandQueue(); this.xGate.Dispose(); this.xGate = null; this.installProject = null; this.channelPtlByChannelId.Clear(); this.IsRunning = false; }
void xgate_PickedInforCallback(XGate xgate, Device PTLDevice, string[] contents, int[] pickedQuantities, bool FnPressed) { try { this.BeginInvoke(new MethodInvoker(() => { websocket.LightSortReturn(int.Parse(contents[0]), pickedQuantities[0]); xgate.Clear900U(PTLDevice.Address); //xgate.Close(); string info = "设备类型:" + PTLDevice + "\r\n" + "货位号:" + contents[0] + "\r\n" + "拣货数量:" + pickedQuantities[0]; IniHelper.WriteInfo(info); if (que_light.Count != 0) { disPlay900(); } })); } catch (Exception ex) { IniHelper.WriteLog(ex); } }
public void Start() { this.Stop(); try { List <MarketZone> items = new List <MarketZone>(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { items = dbContext.MarketZones.ToList(); } foreach (var item in items) { XGate xgate = this.xGates .FirstOrDefault(xg => xg.IPEndPoint.Address.ToString() == item.XGateIP); if (xgate == null) { xgate = new XGate(item.XGateIP); this.xGates.Add(xgate); } RS485Bus bus = xgate.Buses[(byte)item.Bus]; PtlMXP1O5 m3 = bus.Devices.FirstOrDefault(d => d.Address == (byte)item.Address) as PtlMXP1O5; if (m3 == null) { m3 = new PtlMXP1O5(); m3.Address = (byte)item.Address; bus.Devices.AddOrUpdate(m3); } Lighthouse redLighthouse = m3.Lighthouses[2]; Lighthouse blueLighthouse = m3.Lighthouses[0]; Lighthouse greenLighthouse = m3.Lighthouses[4]; MarketZoneDevice logicDevice = new MarketZoneDevice { XGate = xgate, Bus = bus, M3 = m3, RedLighthouse = redLighthouse, GreenLighthouse = greenLighthouse, BlueLighthouse = blueLighthouse, Id = item.Id, GroundId = item.GroundId, AreaId = item.AreaId }; this.devices.Add(logicDevice); } dict = this.devices.ToDictionary(x => x.Id); //启动 PTL 通讯 foreach (XGate xGate in this.xGates) { xGate.StartUnicastCommandQueue(); foreach (RS485Bus bus in xGate.Buses) { foreach (PtlDevice target in bus.Devices) { target.Initialize(); } } } thread = new Thread(new ParameterizedThreadStart(Dowork)); thread.IsBackground = true; thread.Start(); areaThread = new Thread(new ParameterizedThreadStart(DoStatus)); areaThread.IsBackground = true; areaThread.Start(); } catch { this.Stop(); } }
public void Start() { this.Stop(); try { List <Assembling> items = new List <Assembling>(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { items = dbContext.Assemblings.ToList(); } foreach (var item in items) { XGate xgate = this.xGates .FirstOrDefault(xg => xg.IPEndPoint.Address.ToString() == item.XGateIP); if (xgate == null) { xgate = new XGate(item.XGateIP); this.xGates.Add(xgate); } RS485Bus bus = xgate.Buses[(byte)item.Bus]; Ptl900U callButton = (Ptl900U)bus.Devices.FirstOrDefault(d => d.Address == (byte)item.Address); if (callButton == null) { callButton = new Ptl900U(); callButton.Address = (byte)item.Address; bus.Devices.AddOrUpdate(callButton); } AssemblingDevice logicDevice = new AssemblingDevice { XGate = xgate, Bus = bus, CallButton = callButton, Id = item.Id, AreaId = item.AreaId, Type = item.Type }; this.devices.Add(logicDevice); } //启动 PTL 通讯 foreach (XGate xGate in this.xGates) { xGate.StartUnicastCommandQueue(); foreach (RS485Bus bus in xGate.Buses) { foreach (PtlDevice target in bus.Devices) { target.Initialize(); if (target is Ptl900U) { (target as Ptl900U).Pressed += CallButton_Pressed; } } } } dict = this.devices.ToDictionary(x => x.Id); thread = new Thread(new ParameterizedThreadStart(Dowork)); thread.IsBackground = true; thread.Start(); //threadStatus = new Thread(new ParameterizedThreadStart(DoStatus)); //threadStatus.IsBackground = true; //threadStatus.Start(); var groups = this.devices.GroupBy(x => x.AreaId); foreach (var group in groups) { //dictBool.AddOrUpdate(group.Key, false, (a, b) => b); Thread threadStatus = new Thread(new ParameterizedThreadStart(DoStatus)); threadStatus.IsBackground = true; threadStatus.Start(group.Key); dictThread.AddOrUpdate(group.Key, threadStatus, (a, b) => b); } } catch { this.Stop(); } }
/// <summary> /// 加载并启动所有转台的 PTL 通讯。 /// </summary> public void Start() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <CFG_Channel> cfgChannels = dbContext.CFG_Channels .ToList(); CFG_ChannelPtlDevice firstCFG_ChannelPtlDevice = dbContext.CFG_ChannelPtlDevices .First(); //单个 XGate this.xGate = new XGate(firstCFG_ChannelPtlDevice.XGateIP); this.installProject = new InstallProject(); this.installProject.XGates.AddOrUpdate(this.xGate); foreach (CFG_Channel cfgChannel in cfgChannels) { ChannelPtl channelPtl = new ChannelPtl(cfgChannel.Id); this.channelPtlByChannelId.Add(cfgChannel.Id, channelPtl); List <CFG_ChannelPtlDevice> cfgChannelPtlDevices = dbContext.CFG_ChannelPtlDevices .Where(cpd => cpd.CFG_ChannelId == cfgChannel.Id) .ToList(); //各个分拣口的指示灯 foreach (CFG_ChannelPtlDevice cfgChannelPtlDevice in cfgChannelPtlDevices) { Ptl900U ptl900U = (Ptl900U)this.xGate.Buses[cfgChannelPtlDevice.RS485BusIndex].Devices .FirstOrDefault(d => d.Address == cfgChannelPtlDevice.Ptl900UAddress); if (ptl900U == null) { ptl900U = new Ptl900U(); ptl900U.Address = cfgChannelPtlDevice.Ptl900UAddress; ptl900U.MinorType = Ptl900UType.P0; this.xGate.Buses[cfgChannelPtlDevice.RS485BusIndex].Devices.AddOrUpdate(ptl900U); } channelPtl.SetPtl900UByPosition(cfgChannelPtlDevice.Position, ptl900U); } } this.xGate.StartUnicastCommandQueue(); foreach (RS485Bus rs485Bus in this.xGate.Buses) { foreach (PtlDevice ptlDevice in rs485Bus.Devices) { ptlDevice.InErrorChanged += this.ptlDevice_InErrorChanged; ptlDevice.Initialize(); //转台上的标签始终锁定 ptlDevice.Lock(); } } this.installProject.HeartbeatGenerator.Period = TimeSpan.FromSeconds(10); this.installProject.HeartbeatGenerator.Enable = true; } this.IsRunning = true; }
public void Start() { this.Stop(); try { List <FeedZone> items = new List <FeedZone>(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { items = dbContext.FeedZones.ToList(); } foreach (var item in items) { XGate xgate = this.xGates .FirstOrDefault(xg => xg.IPEndPoint.Address.ToString() == item.XGateIP); if (xgate == null) { xgate = new XGate(item.XGateIP); this.xGates.Add(xgate); } RS485Bus bus = xgate.Buses[(byte)item.Bus]; if (item.IsInteractive == true) //交互灯是PTL900U { Ptl900U callButton = (Ptl900U)bus.Devices.FirstOrDefault(d => d.Address == (byte)item.Address); if (callButton == null) { callButton = new Ptl900U(); callButton.Address = (byte)item.Address; bus.Devices.AddOrUpdate(callButton); } FeedZoneDevice logicDevice = new FeedZoneDevice { XGate = xgate, Bus = bus, CallButton = callButton, IsM3 = false, IsInteractive = item.IsInteractive, Id = item.Id, RFID = item.RFID, GroundId = item.GroundId, AreaId = item.AreaId }; this.devices.Add(logicDevice); } else { PtlMXP1O5 m3 = bus.Devices.FirstOrDefault(d => d.Address == (byte)item.Address) as PtlMXP1O5; if (m3 == null) { m3 = new PtlMXP1O5(); m3.Address = (byte)item.Address; bus.Devices.AddOrUpdate(m3); } Lighthouse redLighthouse = m3.Lighthouses[(byte)2]; Lighthouse orangeLighthouse = m3.Lighthouses[(byte)1]; Lighthouse greenLighthouse = m3.Lighthouses[(byte)4]; FeedZoneDevice logicDevice = new FeedZoneDevice { XGate = xgate, Bus = bus, M3 = m3, RedLighthouse = redLighthouse, GreenLighthouse = greenLighthouse, OrangeLighthouse = orangeLighthouse, IsM3 = item.IsM3, IsInteractive = false, Id = item.Id, RFID = item.RFID, GroundId = item.GroundId, AreaId = item.AreaId }; this.devices.Add(logicDevice); } } //启动 PTL 通讯 foreach (XGate xGate in this.xGates) { xGate.StartUnicastCommandQueue(); foreach (RS485Bus bus in xGate.Buses) { foreach (PtlDevice target in bus.Devices) { target.Initialize(); var targetDevice = devices.FirstOrDefault(x => x.CallButton == target && x.IsInteractive == true); if (targetDevice != null) { targetDevice.CallButton.Pressed += CallButton_Pressed; } } } } dict = this.devices.ToDictionary(x => x.Id); thread = new Thread(new ParameterizedThreadStart(Dowork)); thread.IsBackground = true; thread.Start(); //threadStatus = new Thread(new ParameterizedThreadStart(DoStatus)); //threadStatus.IsBackground = true; //threadStatus.Start(); var groups = this.devices.GroupBy(x => x.AreaId); foreach (var group in groups) { dictBool.AddOrUpdate(group.Key, false, (a, b) => b); Thread threadStatus = new Thread(new ParameterizedThreadStart(DoStatus)); threadStatus.IsBackground = true; threadStatus.Start(group.Key); dictThread.AddOrUpdate(group.Key, threadStatus, (a, b) => b); } } catch { this.Stop(); } }