User Tools

Site Tools


plc:software_plc_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plc:software_plc_examples [2018/09/24 21:11] skirillovplc:software_plc_examples [2022/03/29 15:55] (current) ivan
Line 1: Line 1:
 ==== Software PLC examples ==== ==== Software PLC examples ====
 +
 +//**NOTE**: The myCNC team recommends utilizing the examples provided in this manual (as well as other manuals in this documentation) as a starting point for your machine setup. When possible (and applicable), it is recommended to keep changes to a mininum. In general, using these examples as the basis for your PLCs/macro commands allows for an easier setup process.//
 +
 +===General examples===
  
   * [[How to add mandatory Homing after Emergency Button and-or Servo ready alarm]]   * [[How to add mandatory Homing after Emergency Button and-or Servo ready alarm]]
Line 100: Line 104:
     if (ymax>MAX_Y){ left_right=0;};     if (ymax>MAX_Y){ left_right=0;};
  
-    gvarset(502,left_right); //502 - показывает обе стороны или одна+    gvarset(502,left_right); //502 - shows both sides or single side
     LR=gvarget(500);     LR=gvarget(500);
  
-    if (LR==0) //левая+    if (LR==0) //left
      {      {
-//       gvarset(9100,1); //показать сообщение №+//       gvarset(9100,1); //show message #
-       //do{ a=portget(11); }while(a==0); //ждем педаль, 11 вход +       //do{ a=portget(11); }while(a==0); //press pedalport 11 
-       //do{ a=gvarget(6065); }while(a!=0); //ждем педаль, 11 вход +       //do{ a=gvarget(6065); }while(a!=0); //press pedalport 11 
-//       gvarset(9100,0);  //убрать сообщение+//       gvarset(9100,0);  //clear the message
  
        portclr(10);//Vacuum Left OFF        portclr(10);//Vacuum Left OFF
Line 116: Line 120:
        portset(22);//        portset(22);//
  
-//       gvarset(9101,1); //показать сообщение №+//       gvarset(9101,1); //show message #
-       //do{ a=portget(13); }while(a==0); //ждем педаль, 13 вход+       //do{ a=portget(13); }while(a==0); //press pedalport 13
 //       gvarset(9101,0); //убрать //       gvarset(9101,0); //убрать
  
        portset(10);//Vacuum Left        portset(10);//Vacuum Left
        portclr(9); //        portclr(9); //
-       timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек пока присоски сработают+       timer=5; do{ timer--; }while(timer>0); //wait 0.5 seconds while the vacuum is working
  
        portclr(11);//выключить упоры        portclr(11);//выключить упоры
Line 129: Line 133:
 //// ////
 //ждать пока УП завершится //ждать пока УП завершится
-       do{ a=gvarget(6065); }while(a!=0); //ждем+       do{ a=gvarget(6065); }while(a!=0); //wait
 //// ////
  
  
 do { do {
-      do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы+      do{ a=gvarget(6065); }while(a!=0); //wait for the system to be ready
       gvarset(100010,54); //Дать код G54       gvarset(100010,54); //Дать код G54
-      timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек пока сменится система +      timer=5; do{ timer--; }while(timer>0); //wait 0.5s for the system to switch 
- n=gvarget(5220);//получить текущий номер системы координат + n=gvarget(5220);//gets the current coordinate system number 
- } while(n!=1); //пока текущая система не G54+ } while(n!=1); //while the current system is not G54
  
-       do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы +       do{ a=gvarget(6065); }while(a!=0); //wait for the system to be ready 
-       gvarset(100001,1); //сбросить программу в начало +       gvarset(100001,1); //go to the beginning of the program 
-       timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек +       timer=5; do{ timer--; }while(timer>0); //wait 0.5s 
-       do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы +       do{ a=gvarget(6065); }while(a!=0); //wait for the system to be ready 
-       gvarset(100002,1); //запустить программу +       gvarset(100002,1); //start the program 
- +    }else //right 
-    }else //правая+
     {     {
-//       gvarset(9110,1); //показать сообщение №+//       gvarset(9110,1); //show message #
-//       do{ a=portget(12); }while(a==0); //ждем педаль, 11 вход +//       do{ a=portget(12); }while(a==0); //press pedalport 11 
-//       gvarset(9110,0);  //убрать сообщение+//       gvarset(9110,0);  //clear the message
  
        portclr(15); //Vacuum Left OFF        portclr(15); //Vacuum Left OFF
Line 158: Line 161:
        portset(23); //        portset(23); //
  
-//       gvarset(9111,1); //показать сообщение №+//       gvarset(9111,1); //show message #
-//       do{ a=portget(14); }while(a==0); //ждем педаль, 13 вход +//       do{ a=portget(14); }while(a==0); //press pedalport 13 
-//       gvarset(9111,0); //убрать+//       gvarset(9111,0); //clear
  
        portset(15); //Vacuum Left        portset(15); //Vacuum Left
        portclr(16); //        portclr(16); //
-       timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек пока присоски сработают+       timer=5; do{ timer--; }while(timer>0); //wait 0.5 seconds while the vacuum is working
  
-       portclr(14);//выключить упоры+       portclr(14);//
        portclr(23);//        portclr(23);//
  
 //// ////
-       do{ a=gvarget(6065); }while(a!=0); //ждем +       do{ a=gvarget(6065); }while(a!=0); //wait 
-//ждать пока УП завершится+//wait until the control program is finished
 //// ////
  
 do{ do{
-      do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы +      do{ a=gvarget(6065); }while(a!=0); //wait until the program is ready 
- gvarset(100010,55); //Дать код G54 + gvarset(100010,55); //assigns G54 coordinate system 
-      timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек пока сработает смена координат +      timer=5; do{ timer--; }while(timer>0); //wait 0.5 seconds while the coordinate system switch is happening 
- n=gvarget(5220);//получить текущий номер системы координат + n=gvarget(5220);//obtain the current coordinate system number 
-} while(n!=2);//пока текущая система не G55+} while(n!=2);//while the system is not G55
  
-       do{ a=gvarget(6065); }while(a!=0); //ждем пока процессор занят +       do{ a=gvarget(6065); }while(a!=0); //wait while the processor is busy 
-       gvarset(100001,1); //сбросить программу в начало +       gvarset(100001,1); //return to the beginning of the program 
-       timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек  +       timer=5; do{ timer--; }while(timer>0); //wait 0.5 seconds 
-       do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы +       do{ a=gvarget(6065); }while(a!=0); //wait for the system to be ready 
-       gvarset(100002,1); //запустить программу+       gvarset(100002,1); //start the program
  
     };     };
  
-       timer=20; do{ timer--; }while(timer>0); //пауза на сек, что программа стартовала +       timer=20; do{ timer--; }while(timer>0); //second pause 
-       do{ a=gvarget(6065); }while(a!=0); //ждем пока завершится программа+       do{ a=gvarget(6065); }while(a!=0); //wait until the program is complete
  
- LR=LR^1; //переключить на другую сторону+ LR=LR^1; //switch to the other side
     gvarset(500,LR);     gvarset(500,LR);
  
Line 205: Line 208:
  
  
-==== Jog Step (0.001, 0.01, 0.1 1.0) Indication with external LED display ====+===Jog Step (0.001, 0.01, 0.1 1.0) Indication with external LED display===
  
  
Line 262: Line 265:
 }; };
  
 +</code>
 +
 +
 +===Switching an output ON for a certain period of time===
 +
 +<code>
 +#define OUTPUT_TIMER 15
 +main()
 +{
 +count=0;
 +do{
 +a=gvarget(7373);
 +
 +if (a!=0)
 +{
 +  count++;
 +  if (count<30) { portset(OUTPUT_TIMER); }
 +  else { 
 +            portclr(OUTPUT_TIMER); 
 +            if (count>6000) { count=0; };
 +          };
 +}else
 +{
 +  portclr(OUTPUT_TIMER);
 +  count=0;
 +};
 +}while(1);
 +exit(99);
 +};
 </code> </code>
  
plc/software_plc_examples.txt · Last modified: 2022/03/29 15:55 by ivan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki