Exemple #1
0
        static void Shutdown(MemoryBit start)
        {
            start.Value = false;

            MemoryMap.Instance.Update();
            MemoryMap.Instance.Dispose();
        }
    public Interface()
    {
        Conveyor = MemoryMap.Instance.GetBit("Conveyor", MemoryType.Output);
        Sensor   = MemoryMap.Instance.GetBit("Sensor", MemoryType.Input);

        init_variables();
    }
Exemple #3
0
        //In this sample we are powering a roller conveyor on and off 10 times.
        //Use the Saved Scene "SDK Write Sample" provided in the Saved Scene folder.
        static void Main(string[] args)
        {
            //We are using a MemoryBit which we get from the MemoryMap.
            //You can find the memory addresses of a specific Factory I/O Tag by toggling the visibility of the Tags Address in the View Menu, or by docking the Tag.
            MemoryBit rollerConveyor = MemoryMap.Instance.GetBit(0, MemoryType.Output);

            for (int i = 0; i < 10; i++)
            {
                rollerConveyor.Value = !rollerConveyor.Value;

                //When using a memory value before calling the Update method we are using a cached value.
                Console.WriteLine("Is the roller conveyor on? " + rollerConveyor.Value);

                //Calling the Update method will write the rollerConveyor.Value to the memory map.
                MemoryMap.Instance.Update();

                Thread.Sleep(1000);
            }

            //When we no longer need the MemoryMap we should call the Dispose method to release all the allocated resources.
            MemoryMap.Instance.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
 public void SendUpdate(MemoryBit mem)
 {
     if (filter.Apply(mem))
     {
         client.Publish("in/" + transformer.NameToOpenHAB(mem.Name) + "/state", Encoding.ASCII.GetBytes(transformer.BitToState(mem)));
     }
 }
        public void SetValue_Valid_ChangesBitValue(int bitStateCount, int value)
        {
            var bit = new MemoryBit(bitStateCount);

            bit.SetValue(value);
            Assert.Equal(value, bit.GetValue());
        }
Exemple #6
0
    static void Main(string[] args)
    {
        //MemoryBit used to switch FACTORY I/O between edit and run mode
        MemoryBit start = MemoryMap.Instance.GetBit(MemoryMap.BitCount - 16, MemoryType.Output);

        //MemoryBit used to detect if FACTORY I/O is edit or run mode
        MemoryBit running = MemoryMap.Instance.GetBit(MemoryMap.BitCount - 16, MemoryType.Input);

        //Forcing a rising edge on the start MemoryBit so FACTORY I/O can detect it
        SwitchToRun(start);

        Interface inter = new Interface();

        Console.WriteLine("Running. Press Escape to shutdown...");

        while (!(Console.KeyAvailable && (Console.ReadKey(false).Key == ConsoleKey.Escape)))
        {
            //Update the memory map before executing the controller
            MemoryMap.Instance.Update();

            if (running.Value)
            {
                inter.PLCCycle();
            }

            Thread.Sleep(CycleTime);
        }

        Shutdown(start);
    }
Exemple #7
0
        public void load()
        {
            //We are using a MemoryBit which we get from the MemoryMap.
            //You can find all the memory addresses at the Memory Addresses page.
            MemoryBit livingRoomLight = MemoryMap.Instance.GetBit(0, MemoryType.Output);

            for (int i = 0; i < 10; i++)
            {
                livingRoomLight.Value = !livingRoomLight.Value;

                //When using a memory value before calling the Update method we are using a cached value.
                Console.WriteLine("Light is on? " + livingRoomLight.Value);

                //Calling the Update method will write the livingRoomLight.Value to the memory map.
                MemoryMap.Instance.Update();

                Thread.Sleep(5000);
            }

            //When we no longer need the MemoryMap we should call the Dispose method to release all the allocated resources.
            MemoryMap.Instance.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Exemple #8
0
 public Road(MemoryBit ins, MemoryBit es, params MemoryBit[] conveyors)
 {
     Conveyors = conveyors;
     InSensor  = ins;
     EndSensor = es;
     RoadManager.Instance().Add(this);
 }
Exemple #9
0
        public static void BitOutput(int input, bool value)
        {
            MemoryBit HomeInput = MemoryMap.Instance.GetBit(input, MemoryType.Output);

            HomeInput.Value = value;
            MemoryMap.Instance.Update();
        }
        public ForkLoader(MemoryInt pos, MemoryBit fl, MemoryBit fr, MemoryBit l, MemoryBit x, MemoryBit z, MemoryBit al, MemoryBit ar, MemoryBit am, Road inputLine, Road outputLine, Side mySide)
        {
            pos.Value = 55;

            Pos       = pos;
            ForkLeft  = fl;
            ForkRight = fr;
            Lift      = l;
            MovingX   = x;
            MovingZ   = z;
            AtLeft    = al;
            AtMiddle  = am;
            AtRight   = ar;

            AtSide = new MemoryBit[2] {
                AtRight, AtLeft
            };
            ForkSide = new MemoryBit[2] {
                ForkRight, ForkLeft
            };

            InputLine  = inputLine;
            OutputLine = outputLine;

            WhoAmI = mySide;
        }
 public string BitToState(MemoryBit mem)
 {
     if (mem.Name.Contains("Door Detector"))
     {
         return(mem.Value == false ? "OPEN" : "CLOSED");
     }
     return(mem.Value == true ? "OPEN" : "CLOSED");
 }
 public DoubleJunction(MemoryBit topSensor, MemoryBit bottomSensor, MemoryBit t1, MemoryBit t2, MemoryBit b1, MemoryBit b2)
 {
     AtUpSensor   = topSensor;
     AtDownSensor = bottomSensor;
     Top1         = t1;
     Top2         = t2;
     Bot1         = b1;
     Bot2         = b2;
 }
Exemple #13
0
        static void SwitchToRun(MemoryBit start)
        {
            start.Value = false;
            MemoryMap.Instance.Update();
            Thread.Sleep(500);

            start.Value = true;
            MemoryMap.Instance.Update();
            Thread.Sleep(500);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //conditions initiales
            this.X1     = true;
            this.X2     = false;
            this.bpPrec = false;
            this.lampe  = MemoryMap.Instance.GetBit(0, MemoryType.Output);

            timer1.Start();
        }
        public DadosTermostato Termostato_A()
        {
            //update dos registros
            MemoryMap.Instance.Update();

            MemoryFloat temperatura = MemoryMap.Instance.GetFloat(1, MemoryType.Input);
            MemoryFloat setPoint    = MemoryMap.Instance.GetFloat(2, MemoryType.Input);
            MemoryBit   estado      = MemoryMap.Instance.GetBit(9, MemoryType.Output);

            return(new DadosTermostato(temperatura.Value, setPoint.Value, estado.Value));
        }
Exemple #16
0
        private void AtualizarBit(int endereco, bool estado)
        {
            MemoryMap.Instance.Update();//update dos registros
            MemoryBit elemento = MemoryMap.Instance.GetBit(endereco, MemoryType.Output);

            if (elemento.Value != estado)
            {
                elemento.Value = estado;
                MemoryMap.Instance.Update();//update dos registros novamento para update nos dados alterados
            }
        }
Exemple #17
0
 private void button1_Click(object sender, EventArgs e)
 {
     //conditions initiales
     this.X1                = true;
     this.X2                = false;
     this.X3                = false;
     this.bpPrec            = false;
     this.rollerShadesOpen  = MemoryMap.Instance.GetBit(3, MemoryType.Output);
     this.rollerShadesClose = MemoryMap.Instance.GetBit(4, MemoryType.Output);
     timer1.Start();
 }
Exemple #18
0
        public FT_Con1()
        {
            // Inputs
            C1_startIR = MemoryMap.Instance.GetBit("C1_startIR", MemoryType.Input);
            C1_endIR   = MemoryMap.Instance.GetBit("C1_endIR", MemoryType.Input);

            // Outputs
            C1_motor     = MemoryMap.Instance.GetBit("C1_motor", MemoryType.Output);
            R1_fwd_motor = MemoryMap.Instance.GetBit("R1_fwd_motor", MemoryType.Output);

            init_variables();
        }
Exemple #19
0
        public FT_Con2()
        {
            // Inputs
            C1_endIR = MemoryMap.Instance.GetBit("C1_endIR", MemoryType.Input);
            M1_IR    = MemoryMap.Instance.GetBit("M1_IR", MemoryType.Input);

            // Outputs
            C2_motor = MemoryMap.Instance.GetBit("C2_motor", MemoryType.Output);
            M1_motor = MemoryMap.Instance.GetBit("M1_motor", MemoryType.Output);

            init_variables();
        }
Exemple #20
0
        public FT_Con3()
        {
            // Inputs
            M1_IR = MemoryMap.Instance.GetBit("M1_IR", MemoryType.Input);
            M2_IR = MemoryMap.Instance.GetBit("M2_IR", MemoryType.Input);

            // Outputs
            C3_motor = MemoryMap.Instance.GetBit("C3_motor", MemoryType.Output);
            M2_motor = MemoryMap.Instance.GetBit("M2_motor", MemoryType.Output);

            init_variables();
        }
Exemple #21
0
        public FT_Con4()
        {
            // Inputs
            M2_IR    = MemoryMap.Instance.GetBit("M2_IR", MemoryType.Input);
            C4_endIR = MemoryMap.Instance.GetBit("C4_endIR", MemoryType.Input);

            // Outputs
            C4_motor     = MemoryMap.Instance.GetBit("C4_motor", MemoryType.Output);
            R2_fwd_motor = MemoryMap.Instance.GetBit("R2_fwd_motor", MemoryType.Output);

            init_variables();
        }
Exemple #22
0
 private void button1_Click(object sender, EventArgs e)
 {
     button1.Enabled           = false;
     this.porteGarageOuverture = MemoryMap.Instance.GetBit(72, MemoryType.Output);
     this.porteGarageFermeture = MemoryMap.Instance.GetBit(73, MemoryType.Output);
     this.X0 = true;
     this.X1 = false;
     this.X2 = false;
     this.X3 = false;
     this.X4 = false;
     this.X5 = false;
     timer1.Start();
 }
Exemple #23
0
        //In this sample we are reading the Diffuse Sensor 1 value. The value is only sampled once.
        //Use the Saved Scene "SDK Read Sample" provided in the Saved Scene folder.
        static void Main(string[] args)
        {
            //We are using a MemoryBit which we get from the MemoryMap.
            //You can find the memory addresses of a specific Factory I/O Tag by toggling the visibility of the Tags Address in the View Menu, or by docking the Tag.
            MemoryBit diffuseSensor = MemoryMap.Instance.GetBit(0, MemoryType.Input);

            //We must call the Update method each time we want to access the latest value.
            MemoryMap.Instance.Update();

            Console.WriteLine("Diffuse Sensor 1 value: " + diffuseSensor.Value.ToString());

            //When we no longer need the MemoryMap we should call the Dispose method to release all the allocated resources.
            MemoryMap.Instance.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
        public void PutTo(Side s)
        {
            MemoryBit fork = ForkSide[(int)s];
            MemoryBit at   = AtSide[(int)s];

            fork.Value = true;
            while (!at.Value)
            {
                Thread.Sleep(32);
            }
            Lift.Value = false;
            Thread.Sleep(300);
            while (MovingZ.Value)
            {
                Thread.Sleep(32);
            }
            fork.Value = false;
            while (!AtMiddle.Value)
            {
                Thread.Sleep(32);
            }
        }
 public bool Apply(MemoryBit mem)
 {
     return(true);
 }
 public Junction(MemoryBit atSensor)
 {
     AtSensor = atSensor;
 }
 public JunctionInput(Road road, MemoryBit inBit)
 {
     Line  = road;
     InBit = inBit;
     // ReadySensor = rs;
 }
 public JunctionOutput(Road road, MemoryBit outBit)
 {
     Sensor = road.InSensor;
     Line   = road;
     OutBit = outBit;
 }
        public void Init()
        {
            //MemoryMap.Instance.Update();
            memoryInputBits = MemoryMap.Instance.GetBitMemories(MemoryType.Input);
            for (int i = 0; i < memoryInputBits.Length - 1; i++)
            {
                MemoryBit memoryBit = memoryInputBits[i];
                simuHash = memoryBit.Name;
                if (simuHash.Equals("") ||
                    simuHash.Length != 32)
                {
                    continue;
                }
                //Search for the hash in the list of plc symbols
                //Console.WriteLine("simuHash: {0} index: {1} ", simuHash, i );
                for (int k = 0; k < plcInterface.IBoolInPathCtr - 1; k++)
                {
                    plcHash = plcInterface.GetMd5Hash(md5Hash, plcInterface.ArrBoolInPaths[k]);
                    //Console.WriteLine("PLCHash: {0} SimuHash: {1}", plcHash, simuHash );
                    if (plcHash.Equals(simuHash))
                    {
                        //Console.Write("plcHash: {0} index: {1} ", plcHash, k );
                        //Console.WriteLine("Memory input found: index plc: {0} index simulation: {1}", k, i );
                        //Store the simuHash index
                        inputDecoder[k] = i;
                        //Console.WriteLine("Input PLCHash: {0} Input SimuHash: {1} k: {2} inputDecoder[k]: {3}", plcHash, memoryInputBits[inputDecoder[k]].Name,k ,inputDecoder[k] );

                        //Exit the loop
                        break;
                    }
                }
            }

            //MemoryMap.Instance.Update();
            memoryOutputBits = MemoryMap.Instance.GetBitMemories(MemoryType.Output);
            for (int i = 0; i < memoryOutputBits.Length - 1; i++)
            {
                //Get outputs from the plc and transfer them to the simulation.
                if (memoryOutputBits[i].Name.Equals("") ||
                    memoryOutputBits[i].Name.Length != 32)
                {
                    continue;
                }

                for (int k = 0; k < plcInterface.IBoolOutPathCtr - 1; k++)
                {
                    plcHash = plcInterface.GetMd5Hash(md5Hash, plcInterface.ArrBoolOutPaths[k]);
                    if (plcHash.Equals(memoryOutputBits[i].Name))
                    {
                        outputDecoder[k] = i;
                        //Console.WriteLine("Output PLCHash: {0} Output SimuHash: {1} k: {2} ouputDecoder[k]: {3}", plcHash, memoryOutputBits[outputDecoder[k]].Name,k ,outputDecoder[k] );
                        //Exit the loop
                        break;
                    }
                }
            }

            inputThread  = new Thread(InputsExchange);
            outputThread = new Thread(OutputsExchange);
            inputThread.Start();
            outputThread.Start();
        }
Exemple #30
0
        /// <summary>
        /// The idea of this sample is to demonstrate that Microsoft Visual Studio can be used as a soft PLC to
        /// control FACTORY I/O (requires Ultimate Edition).
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Stopwatch used to measure elapsed time between cycles
            Stopwatch stopwatch = new Stopwatch();

            //MemoryBit used to switch FACTORY I/O between edit and run mode
            MemoryBit start = MemoryMap.Instance.GetBit(MemoryMap.BitCount - 16, MemoryType.Output);

            //MemoryBit used to detect if FACTORY I/O is edit or run mode
            MemoryBit running = MemoryMap.Instance.GetBit(MemoryMap.BitCount - 16, MemoryType.Input);

            //Forcing a rising edge on the start MemoryBit so FACTORY I/O can detect it
            SwitchToRun(start);

            //Uncomment ONLY one of the following lines to control the corresponding scene in FACTORY I/O
            Controller controller = new FromAToB();

            //Controller controller = new FromAToBSetReset();
            //Controller controller = new FillingTank();
            //Controller controller = new QueueOfItems();
            //Controller controller = new Assembler();
            //Controller controller = new AssemblerAnalog();
            //Controller controller = new AutomatedWarehouse();
            //Controller controller = new BufferStation();
            //Controller controller = new ConvergeStation();
            //Controller controller = new ElevatorAdvanced();
            //Controller controller = new ElevatorBasic();
            //Controller controller = new LevelControl();
            //Controller controller = new Palletizer();
            //Controller controller = new PickPlaceBasic();
            //Controller controller = new PickPlaceXYZ();
            //Controller controller = new ProductionLine();
            //Controller controller =  new SeparatingStation();
            //Controller controller = new SortingHeightAdvanced();
            //Controller controller = new SortingHeightBasic();
            //Controller controller = new SortingWeight();
            //Controller controller = new SortingStation();

            Console.WriteLine(string.Format("Running controller: {0}", controller.GetType().Name));
            Console.WriteLine("Press Escape to shutdown...");

            stopwatch.Start();

            Thread.Sleep(CycleTime);

            while (!(Console.KeyAvailable && (Console.ReadKey(false).Key == ConsoleKey.Escape)))
            {
                //Update the memory map before executing the controller
                MemoryMap.Instance.Update();

                if (running.Value)
                {
                    stopwatch.Stop();

                    controller.Execute((int)stopwatch.ElapsedMilliseconds);

                    stopwatch.Restart();
                }

                Thread.Sleep(CycleTime);
            }

            Shutdown(start);
        }