public void StockerPlcIntegrationTest()
        {
            StockerSimulatorPlcCommunication simulator = StockerSimulatorPlcCommunication.Create();

            IStockerPlc target = new StockerPlc(simulator);
            target.Open();

            bool barcodeError = false;
            CarrierPlateRouting routing = CarrierPlateRouting.Cleared;
            bool isMagazineChanged = false;
            bool isMagazineBarcodeReadedOk = false;
            StockerInventory inventory = StockerInventory.Cleared;
            MagazineSelection selection = MagazineSelection.Cleared;

            IStockerStatus status = target.GetStatus();
            CompareObjects(simulator, status);

            for (int i = 0; i < 100000; i++)
            {
                // "PLC" randomly clear memory
                if (_random.NextDouble() > 0.40)
                {
                    switch (_random.Next(2, 7))
                    {
                        case 2:
                            routing = CarrierPlateRouting.Cleared;
                            simulator.CarrierPlateRouting = routing;
                            break;
                        case 3:
                            isMagazineChanged = false;
                            simulator.IsMagazineChange = isMagazineChanged;
                            break;
                        case 4:
                            isMagazineBarcodeReadedOk = false;
                            simulator.IsInputMagazineBarcodeOK = isMagazineBarcodeReadedOk;
                            break;
                        case 5:
                            inventory = StockerInventory.Cleared;
                            simulator.StockerInventory = inventory;
                            break;
                        case 6:
                            selection = MagazineSelection.Cleared;
                            simulator.Selection = selection;
                            break;
                    }
                }

                // "Information system" randomly write to memory
                if (_random.NextDouble() > 0.50)
                {
                    switch (_random.Next(1, 7))
                    {
                        case 1:
                            barcodeError = (_random.NextDouble() > 0.5) ? true : false;
                            target.WriteBarcodeError(barcodeError);
                            CompareObjects(simulator, barcodeError, routing, isMagazineChanged, isMagazineBarcodeReadedOk, inventory, selection);
                            break;
                        case 2:
                            routing = (_random.NextDouble() > 0.5) ? CarrierPlateRouting.InsertIntoMagazine : CarrierPlateRouting.Reject;
                            target.AcceptCarrierPlate(routing);
                            CompareObjects(simulator, barcodeError, routing, isMagazineChanged, isMagazineBarcodeReadedOk, inventory, selection);
                            break;
                        case 3:
                            target.MagazineChange();
                            isMagazineChanged = true;
                            CompareObjects(simulator, barcodeError, routing, isMagazineChanged, isMagazineBarcodeReadedOk, inventory, selection);
                            break;
                        case 4:
                            target.MagazineBarcodeSuccesfullyReaded();
                            isMagazineBarcodeReadedOk = true;
                            CompareObjects(simulator, barcodeError, routing, isMagazineChanged, isMagazineBarcodeReadedOk, inventory, selection);
                            break;
                        case 5:
                            inventory = (_random.NextDouble() > 0.5) ? StockerInventory.SizeAvailable : StockerInventory.SizeNotInStocker;
                            target.SetWaferSizeAvailable(inventory);
                            CompareObjects(simulator, barcodeError, routing, isMagazineChanged, isMagazineBarcodeReadedOk, inventory, selection);
                            break;
                        case 6:
                            selection = (_random.NextDouble() > 0.5) ? MagazineSelection.HasRequestedSize : MagazineSelection.DoesNotHaveRequestedSize;
                            target.AcceptMagazine(selection);
                            CompareObjects(simulator, barcodeError, routing, isMagazineChanged, isMagazineBarcodeReadedOk, inventory, selection);
                            break;
                    }
                }

                ChangeStatusData(simulator);
                status = target.GetStatus();
                CompareObjects(simulator, status);
            }
        }
Exemplo n.º 2
0
        public void GetStatus1Test()
        {
            Mock<ICommunication> plcComm = PlcHelper.GetPlcCommunicationMock();
            string read = string.Empty;
            plcComm.Setup(x => x.Read()).Returns(() => { return read; });
            plcComm.Setup(x => x.Write(It.IsAny<string>())).Callback<string>((s) =>
            {
                if (s.StartsWith("\u000500FFCR00012016"))
                    read = "\u0002" + PlcHelper.GetStockerStatusStream(0) + PlcStream.CalculateCheckSum(PlcHelper.GetStockerStatusStream(0));
            });

            StockerPlc target = new StockerPlc(plcComm.Object);
            target.Open();

            IStockerStatus target1 = target.GetStatus();

            Assert.AreEqual<bool>(true, target1.IsCarrierPlateArrived);
            Assert.AreEqual<bool>(false, target1.MagazineChangeRequest.IsMagazineFull);
            Assert.AreEqual<bool>(false, target1.MagazineChangeRequest.IsOperatorChangeRequest);
            Assert.AreEqual<bool>(true, target1.IsMagazineChangeStarted);
            Assert.AreEqual<WaferSize>(WaferSize.Size6Inches, target1.MagazineRequest.WaferSize);
            Assert.AreEqual<bool>(true, target1.MagazineRequest.IsRequested);
            Assert.AreEqual<int>(1, target1.MagazineRequest.PolishLineNumber);
            Assert.AreEqual<bool>(true, target1.IsMagazineArrived);
            Assert.AreEqual<MagazineSelection>(MagazineSelection.Cleared, target1.MagazineSelection);
        }