⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.bak

📁 This is a CNCPro source file. It is include the G-Code interpreter source.
💻 BAK
📖 第 1 页 / 共 5 页
字号:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <dir.h>
#include <stdlib.h>
#include <math.h>
#include "definitions.h"
#include "kernel.h"
#include "setup.h"
#include "utilities.h"
#include "gcode.h"
#include "file.h"
#include "control.h"
#include "help.h"
#include "operator.h"

int version;
int main(int argc, char *argv[])
{
   float cur_speed=0, dist_x=0, dist_y=0, dist_z=0, dist_a=0, tfloat;
   double num, num2, loopmax;
   int msg=COMPLETE, i, ch, ch2, kp=0, tint, gosub=OFF, goloop=OFF, loopnum;
   unsigned long slow_freq, fast_freq;
   long place_holder;
   static char drive[MAXDRIVE], dir[MAXDIR], tstring[20];
   static char fstring[200], user[50], license[10];
   static BYTE buffer[1000], buffer2[1500], buffer3[100], buffer4[400], buffer5[1000];
   static struct hard_setup hardware;
   static struct soft_setup software, temp_software;
   static struct gcode_setup gcode;
   static struct control ctrl;
   static struct filepos sub[100];
   static struct pos pt, world;
   FILE *ifp, *ifp2;
   fpos_t fpos1, fpos2, fpos3, fpostemp, subpos, mainpos;
   BYTE s_port_read;

   //get, store, and set execution path of program
   if(argc>0)
    {fnsplit(argv[0],drive,dir,NULL,NULL);
     if(strlen(dir)>0) dir[strlen(dir)-1]=0;
     system(drive); chdir(dir);
    }

   //check license.dat file
   if((tint=check_key(user, license))==DEMO)
     {sprintf(user,"EVALUATION");
      sprintf(license,"000000000");
      version=DEMO;
     }
   else if(tint==LITE) version=LITE;
   else version=FULL;

   //splash screen
   clrscr();
   _setcursortype(_NOCURSOR);
   box(20,4,60,19, LIGHTGRAY,WHITE,WHITE,BLUE);
   gotoxy(4,4);  cprintf("                                   ");
   gotoxy(4,5);
   if(version==LITE) cprintf("         CNC Pro Lite ");
   else              cprintf("           CNC Pro ");
   cprintf("V3.0");
   gotoxy(4,6);  cprintf("         YA (C) 1999, 2000         ");
   gotoxy(4,7);  cprintf("                                   ");
   gotoxy(4,8);  cprintf("  http://www.yeagerautomation.com  ");
   gotoxy(4,9);  cprintf("                                   ");
   gotoxy(4,10); cprintf("License: %s",license);
   gotoxy(4,11); cprintf("End User: %s",user);
   gotoxy(4,12); cprintf("NOT FOR REDISTRIBUTION             ");
   gotoxy(4,13); cprintf("                                   ");

   //pause 1 second
   sleep(1);

   //init. control screen variables
   world.x_pos=world.y_pos=world.z_pos=world.a_pos=
   pt.x_pos=pt.y_pos=pt.z_pos=pt.a_pos=0;
   ctrl.jog_type=FAST; ctrl.jog_inc=0; ctrl.frate=0;
   sprintf(ctrl.file,"NONE");
   ctrl.cs=0; ctrl.pty=ABS;
   ctrl.M00=ctrl.M03=ctrl.M07=ctrl.M08=ctrl.M10=ctrl.cvv=OFF;
   load_screen_setup(&world,&pt,&ctrl);

   //define hardware and software data structures
   define_data(&hardware, &software);

   //guage computer
   begin_realtime(&software, 10000);
   slow_freq=guage(&software);
   fast_freq=slow_freq*2;
   end_realtime();

   //begin realtime control
   load_setup(&hardware, &software, "<DEFAULT>");
   load_setup(&hardware, &software, "SETUP.INI");
   //if(software.update_after==ON) begin_realtime(&software, fast_freq);
   //else begin_realtime(&software, slow_freq);
   load_setup(&hardware, &software, "<DEFAULT>");
   load_setup(&hardware, &software, "SETUP.INI");
   for(i=0;i<100;i++) sprintf(gcode.tool_dis[i],"NONE");
   load_gcode_setup(&gcode);
   
   //reassign port bits
   clear_data_bits(&hardware);
   if(hardware.io1_on==HIGH) clear_io_bit(&hardware, hardware.io1_bit);
   else set_io_bit(&hardware, hardware.io1_bit);
   if(hardware.io2_on==HIGH) clear_io_bit(&hardware, hardware.io2_bit);
   else set_io_bit(&hardware, hardware.io2_bit);
   if(hardware.io3_on==HIGH) clear_io_bit(&hardware, hardware.io3_bit);
   else set_io_bit(&hardware, hardware.io3_bit);
   if(hardware.io4_on==HIGH) clear_io_bit(&hardware, hardware.io4_bit);
   else set_io_bit(&hardware, hardware.io4_bit);

   //print control screen
   control_screen(&software, &pt, &ctrl, &gcode);
   for(i=0; i<20; i++) if(kbhit()) getch();
   message("Welcome...F1 For Help.");
   message("Alt-(F,S,O,H) or F1 For Help.");
   gettext(43,17,78,17,buffer3);

   while(kp!=27)
     {for(i=0;i<20;i++) if(kbhit()) getch();
      kp=getch();
      if(kp==0) kp=getch()+1000; cur_speed=0;
      switch(kp)
        {case 35+1000:  //alt h
         case 59+1000:  //F1
            help(1);
            break;
         case 'v':
         case 'V':
            if(version==LITE) break;
            if(ctrl.cvv==ON) ctrl.cvv=OFF;
            else ctrl.cvv=ON;
            break;
         case 63+1000:  //F5
            if(software.e_stop!=OFF) s_port_read=(248&inportb(hardware.port+1))^128;
            if(software.e_stop!=OFF && hardware.e_trip*hardware.e_bit-(s_port_read&hardware.e_bit)==0) {msg=E_STOP; break;}
            if(ctrl.M03==OFF)
              {if(hardware.io1_on==HIGH) set_io_bit(&hardware, hardware.io1_bit);
               else clear_io_bit(&hardware, hardware.io1_bit);
               ctrl.M03=ON;}
            else
              {if(hardware.io1_on==HIGH) clear_io_bit(&hardware, hardware.io1_bit);
               else set_io_bit(&hardware, hardware.io1_bit);
               ctrl.M03=OFF;}
            break;
         case 64+1000:  //F6
            if(software.e_stop!=OFF) s_port_read=(248&inportb(hardware.port+1))^128;
            if(software.e_stop!=OFF && hardware.e_trip*hardware.e_bit-(s_port_read&hardware.e_bit)==0) {msg=E_STOP; break;}
            if(ctrl.M07==OFF)
              {if(hardware.io2_on==HIGH) set_io_bit(&hardware, hardware.io2_bit);
               else clear_io_bit(&hardware, hardware.io2_bit);
               ctrl.M07=ON;}
            else
              {if(hardware.io2_on==HIGH) clear_io_bit(&hardware, hardware.io2_bit);
               else set_io_bit(&hardware, hardware.io2_bit);
               ctrl.M07=OFF;}
            break;
         case 65+1000:  //F7
            if(software.e_stop!=OFF) s_port_read=(248&inportb(hardware.port+1))^128;
            if(software.e_stop!=OFF && hardware.e_trip*hardware.e_bit-(s_port_read&hardware.e_bit)==0) {msg=E_STOP; break;}
            if(ctrl.M08==OFF)
              {if(hardware.io3_on==HIGH) set_io_bit(&hardware, hardware.io3_bit);
               else clear_io_bit(&hardware, hardware.io3_bit);
               ctrl.M08=ON;}
            else
              {if(hardware.io3_on==HIGH) clear_io_bit(&hardware, hardware.io3_bit);
               else set_io_bit(&hardware, hardware.io3_bit);
               ctrl.M08=OFF;}
            break;
         case 66+1000:  //F8
            if(software.e_stop!=OFF) s_port_read=(248&inportb(hardware.port+1))^128;
            if(software.e_stop!=OFF && hardware.e_trip*hardware.e_bit-(s_port_read&hardware.e_bit)==0) {msg=E_STOP; break;}
            if(ctrl.M10==OFF)
              {if(hardware.io4_on==HIGH) set_io_bit(&hardware, hardware.io4_bit);
               else clear_io_bit(&hardware, hardware.io4_bit);
               ctrl.M10=ON;}
            else
              {if(hardware.io4_on==HIGH) clear_io_bit(&hardware, hardware.io4_bit);
               else set_io_bit(&hardware, hardware.io4_bit);
               ctrl.M10=OFF;}
            break;
         case 'o':
         case 'O':
            tint=ctrl.cs; ctrl.cs++;
            if(ctrl.cs==7) ctrl.cs=0;
            pt.x_pos=pt.x_pos+(gcode.x_coord[tint]-gcode.x_coord[ctrl.cs])*ctrl.pty;
            pt.y_pos=pt.y_pos+(gcode.y_coord[tint]-gcode.y_coord[ctrl.cs])*ctrl.pty;
            pt.z_pos=pt.z_pos+(gcode.z_coord[tint]-gcode.z_coord[ctrl.cs])*ctrl.pty;
            pt.a_pos=pt.a_pos+(gcode.a_coord[tint]-gcode.a_coord[ctrl.cs])*ctrl.pty;
            break;
         case 'u':
         case 'U':
            if(software.units==MM) {ctrl.frate=change_unit(&software, ctrl.frate, IN);
                                 change_pt_units(&software, &world, IN, IN);
                                 change_gcode_units(&software, &gcode, IN, IN);
                                 change_units(&hardware, &software, IN, IN);}
            else {ctrl.frate=change_unit(&software, ctrl.frate, MM);
                  change_pt_units(&software, &world, MM, MM);
                  change_gcode_units(&software, &gcode, MM, MM);
                  change_units(&hardware, &software, MM, MM);}
            break;
         case 'r':
         case 'R':
            if(ctrl.pty==REL)
              {pt.x_pos=world.x_pos-gcode.x_coord[ctrl.cs]; pt.y_pos=world.y_pos-gcode.y_coord[ctrl.cs];
               pt.z_pos=world.z_pos-gcode.z_coord[ctrl.cs]; pt.a_pos=world.a_pos-gcode.a_coord[ctrl.cs];
               ctrl.pty=ABS;
              }
            else
              {pt.x_pos=pt.y_pos=pt.z_pos=pt.a_pos=0;
               ctrl.pty=REL;
              }
            break;
         case 'w':
         case 'W':
            if(software.a_status==OFF) break;
            if(software.a_follow==INDEPENDANT) software.a_follow=FOLLOW_X;
            else if(software.a_follow==FOLLOW_X) software.a_follow=FOLLOW_Y;
            else if(software.a_follow==FOLLOW_Y) software.a_follow=FOLLOW_Z;
            else if(software.a_follow==FOLLOW_Z) software.a_follow=INDEPENDANT;
            break;
         case 'f':
         case 'F':
            gettext(22,19,59,24,buffer);
            box(22,19,59,24, RED,BLACK,WHITE,WHITE);
            gotoxy(12,1); cprintf("<Esc> To Abort");
            gotoxy(10,3); cprintf("Enter New Feed Rate:");
            _setcursortype(_NORMALCURSOR);
            tfloat=0;
            gotoxy(16,4); get_value(&tfloat);
            if(tfloat>9999) {message("F/R Must Be <=9999."); puttext(22,19,59,24,buffer); break;}
            if(software.time==MIN) ctrl.frate=tfloat/60;
            else ctrl.frate=tfloat;
            _setcursortype(_NOCURSOR);
            puttext(22,19,59,24,buffer);
            break;
         case 't':
         case 'T':
            gettext(22,19,59,24,buffer);
            box(22,19,59,24, RED,BLACK,WHITE,WHITE);
            gotoxy(13,1); cprintf("<Esc> To Exit");
            gotoxy(10,3); gotoxy(3,8); cprintf("Enter New Tool Number:");
            _setcursortype(_NORMALCURSOR);
            gotoxy(18,4); tint=tfloat=0; get_value(&tfloat); tint=tfloat;
            _setcursortype(_NOCURSOR);
            puttext(22,19,59,24,buffer);
            if(tint<=gcode.tnum_max)
              {pt.z_pos=(pt.z_pos-(gcode.tool_len[tint]-gcode.tool_len[gcode.tnum]))*ctrl.pty;
               gcode.tnum=tint;
              }
            else
              {gettext(22,19,59,24,buffer);
               box(22,19,59,24, RED,BLACK,WHITE,WHITE);
               gotoxy(4,3); cprintf("      Tool Number Not Valid");
               gotoxy(4,4); cprintf("            <Any Key>");
               getch();
               puttext(22,19,59,24,buffer);
              }
            break;
         case 'j':
         case 'J':
            if(ctrl.jog_type==FAST) ctrl.jog_type=SLOW;
            else if(ctrl.jog_type==SLOW) ctrl.jog_type=INC;
            else if(ctrl.jog_type==INC) ctrl.jog_type=FAST;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -