Example #1
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    ////component.Dispose();
                    outputImageBuffer.Dispose();
                    Trace.Flush();
                    Trace.Close();
                    SimPLC  = null;
                    Project = null;
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.
                ////CloseHandle(handle);
                ////handle = IntPtr.Zero;
            }
            disposed = true;
        }
Example #2
0
        public SimulatedPLC(PLCSim plcSimObject)
        {
            SimPLC = plcSimObject;

            dataPointList = new PLCDataPoints();

            outputImageBuffer = new MemoryStream();
            UpdateImages     += UpdateInputImage;
            UpdateImages     += UpdateOutputImage;
            try
            {
                var textListener = new TextWriterTraceListener("c:\\temp\\PLCSimConnector.log", "PLCSimListener");
                textListener.TraceOutputOptions |= TraceOptions.DateTime;
                Trace.Listeners.Add(textListener);
                Trace.AutoFlush = true;
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failure to setup Trace Listener", ex);
            }
            Trace.WriteLine("SimulatedPLC object created trace started.", DateTime.Now.ToString(CultureInfo.CurrentCulture));
        }
Example #3
0
        public SimulatedPLC(PLCSim plcSimObject)
        {
            SimPLC = plcSimObject;

            dataPointList = new PLCDataPoints();

            outputImageBuffer = new MemoryStream();
            UpdateImages += UpdateInputImage;
            UpdateImages += UpdateOutputImage;
            try
            {
                var textListener = new TextWriterTraceListener("c:\\temp\\PLCSimConnector.log", "PLCSimListener");
                textListener.TraceOutputOptions |= TraceOptions.DateTime;
                Trace.Listeners.Add(textListener);
                Trace.AutoFlush = true;
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failure to setup Trace Listener", ex);
            }
            Trace.WriteLine("SimulatedPLC object created trace started.", DateTime.Now.ToString(CultureInfo.CurrentCulture));
        }
Example #4
0
 public void PLCSimConstructorTest()
 {
     var target = new PLCSim();
         Assert.IsInstanceOfType(target,typeof(PLCSim));
         target.Dispose();
 }
Example #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Sandbox app to test PLCSimConnector.dll");
            var c = new PLCSim();
            var plc = new SimulatedPLC(c);
            //Console.WriteLine(c.GetState());
            var p = new PCS7Project("C:\\Program Files (x86)\\SIEMENS\\Step7\\S7Proj\\KING_M_1\\MID_CTRL\\MID_CTRL.s7p");
            Console.WriteLine("Press Any Key to Continue...");
            bool loop = true;
            while (loop)
            {
                ConsoleKeyInfo val = Console.ReadKey();
                switch (val.KeyChar)
                {
                    case 'g':
                        {
                            Console.WriteLine(c.GetState());
                            break;
                        }
                    case 'r':
                        {
                            plc.UpdateImages();
                            object z = c.ReadOutputImage(10, 20);
                            break;
                        }
                    case 'w':
                        {
                            c.Connect();
                            bool b = true;
                            Object z = b;
                            c.WriteInputPoint(0, 0, ref z);
                            break;
                        }
                    case 'p':
                        {
                            Console.WriteLine(p.Project.ProjectName);
                            Console.WriteLine(p.Project.ProjectDescription);
                           foreach (var te in p.PCS7SymbolTable.SymbolTableEntrys)
                           {
                                    Console.WriteLine(te.Symbol + ": " + te.Operand +" "+ te.DataType + " - " + te.OperandIEC);

                            }
                            break;
                        }
                    case 's':
                        {
                            Console.WriteLine(p.Project.ProjectName);
                            Console.WriteLine(p.Project.ProjectDescription);
                            var nope = p.GetOutputImageSymbols();
                            foreach (var s in nope)
                            {
                                Console.WriteLine(s);
                            }
                            break;
                        }
                    case 'z':
                        {
                            ValueType i;
                            float f = 3;
                            i = f;
                            Console.WriteLine("the type of i is {0}", i.GetType());
                            break;
                        }

                    default:
                        loop = false;
                        break;

                }
            }
        }
Example #6
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if(!disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if(disposing)
                {
                    // Dispose managed resources.
                    ////component.Dispose();
                    outputImageBuffer.Dispose();
                    Trace.Flush();
                    Trace.Close();
                    SimPLC = null;
                    Project = null;
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.
                ////CloseHandle(handle);
                ////handle = IntPtr.Zero;

            }
            disposed = true;
        }