Exemplo n.º 1
0
        public void TimerCallback(Object o)
        {
            // Display the date/time when this method got called.
            using (var plc = new Plc(CpuType.S71500, "192.168.1.222", 0, 1))
            {
                plc.Open();
                //Write
                WriteTask(plc);
                ReadTask(plc);
                read_datablock DB1_mem = (read_datablock)plc.ReadStruct(typeof(read_datablock), 1, 0);
                read_datablock DB2_mem = (read_datablock)plc.ReadStruct(typeof(read_datablock), 2, 0);
                read_datablock DB3_mem = (read_datablock)plc.ReadStruct(typeof(read_datablock), 3, 0);
                short          second  = (short)((((Int32)(DB1_mem.PT / 1000)) % 3600) % 60);
                short          ms      = (short)(DB1_mem.PT % 1000);
                Console.WriteLine("Frame Data From Plc with IP address   " + plc.IP + ": Frame" + ixx);
                //Update PLC to Readblock
                updatePLC2ReadBlock(DB1_mem, DB2_mem, DB3_mem);
                //Console.WriteLine
                ushort glo = (ushort)plc.Read("MW103");
                //bool st =(bool)plc.R("M101.4");
                //bool sp=(bool)plc.Read("M101.5");
                Console.WriteLine("DB1 mode :" + DB1_mem.mode);
                Console.WriteLine("DB2 mode :" + DB2_mem.mode);
                Console.WriteLine("DB3 mode: " + DB3_mem.mode);
                Console.WriteLine("level: " + level_bar.level);
                Console.WriteLine("glo: " + glo);
                Console.WriteLine("DATA HAD BEEN UPDATED " + "\n\n");
                Console.WriteLine("-------------------------------------------------------------- ");

                //Update Readblock to Writeblock
                updateReadWrite();
                ixx = ixx + 1;
                plc.Close();
            }
        }
Exemplo n.º 2
0
 public void updatePLC2ReadBlock(read_datablock DB1_mem, read_datablock DB2_mem, read_datablock DB3_mem)
 {
     //Data _ Motor 1
     motor1_status.mode        = DB1_mem.mode;
     motor1_status.start       = DB1_mem.start;
     motor1_status.stop        = DB1_mem.stop;
     motor1_status.CMD         = DB1_mem.CMD;
     motor1_status.FAULT       = DB1_mem.FAULT;
     motor1_status.runfeedback = DB1_mem.runfeedback;
     motor1_status.PT          = DB1_mem.PT;
     motor1_status.ET          = DB1_mem.ET;
     motor1_status.IN          = DB1_mem.IN;
     motor1_status.Q           = DB1_mem.Q;
     //Data _ Motor 2
     motor2_status.mode        = DB2_mem.mode;
     motor2_status.start       = DB2_mem.start;
     motor2_status.stop        = DB2_mem.stop;
     motor2_status.CMD         = DB2_mem.CMD;
     motor2_status.FAULT       = DB2_mem.FAULT;
     motor2_status.runfeedback = DB2_mem.runfeedback;
     motor2_status.PT          = DB2_mem.PT;
     motor2_status.ET          = DB2_mem.ET;
     motor2_status.IN          = DB2_mem.IN;
     motor2_status.Q           = DB2_mem.Q;
     //Data_Valve
     valve_status.mode        = DB3_mem.mode;
     valve_status.start       = DB3_mem.start;
     valve_status.stop        = DB3_mem.stop;
     valve_status.CMD         = DB3_mem.CMD;
     valve_status.FAULT       = DB2_mem.FAULT;
     valve_status.runfeedback = DB3_mem.runfeedback;
     valve_status.PT          = DB3_mem.PT;
     valve_status.ET          = DB3_mem.ET;
     valve_status.IN          = DB3_mem.IN;
     valve_status.Q           = DB3_mem.Q;
 }