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

📄 s2.c

📁 激光加工控制系统 可以读入plt文件
💻 C
字号:
#include <stdlib.h>
#include <bios.h>
#include <dos.h>
#include <stdio.h>
#include <conio.h>

#include "exam.h"

/************************************************************************
  The globle variable DogAddr indicates the first memory  address ( range
0 to 199) of user area in the MicroDog when you make reading and/or writing
operations.The sum of DogAddr and DogBytes should not exceed 200.
************************************************************************/
short DogAddr;

/************************************************************************
  The globle variable DogBytes indicates the number ( 1-200 ) of bytes in
the  operation of reading/writing or  convertion. The  sum of DogAddr and
DogBytes should not exceed 200.
************************************************************************/
short DogBytes;

/************************************************************************
  The globle variable DosPassword indicates the password in the MicroDog
(factory value is zero), used in the reading/writing/converting operation.
***********************************************************************/
unsigned long DogPassword;

/************************************************************************
  The globle variable DogResult indicates the result of converting opera-
tion.
************************************************************************/
unsigned long DogResult;

/************************************************************************
  The globle variable DogData indicates  the pointer variable which poi-
  nts to the data for operations .
************************************************************************/
void far *    DogData;

/************************************************************************
  The globle variable Cascade indicates the cascade serial .
************************************************************************/
unsigned char Cascade;

char filename[20];
FILE *fpe;
char buf[200];
char filename[20];
int x_flag,y_flag;
long x_count,y_count;
long x_c,y_c;
int x_ss,y_ss;
int old_de;
int light_status=0;
unsigned char mask=0;

send_a_line();
get_a_line1();
delay1(long len);
delay2(long len);
send_a_step(int x,int y);

int de;

main()
{
  int ret_code,ch,success,i,ret1;
  long l;
  int ee;
  int wint;

//  getch();
  wint = 12345;
  DogData = &wint;
  DogAddr = 100;
  DogBytes = 2;
  WriteDog();
  delay(100);
  wint = 0;
  DogAddr = 100;
  DogBytes = 2;
  DogData = &wint;
  ReadDog();
  delay(100);
  outportb(0x378,0);
//  outportb(0x37a,0xff);
  delay(2000);
  fpe = fopen("c:\\jgs\\setup1.fil","rb");
  if (fpe == NULL){
    printf("Cann't Found File: Setup1.fil!\n");
    return;
  }
  printf("Now,Is Running.\n");
  ch = fgetc(fpe);
  while ((ch != '$')&&(ch != EOF))
    ch = fgetc(fpe);
  if (ch == EOF)
    de = 160;
  else{
    i = 0;
    while ((ch != 10)&&(ch != 13)&&(ch != EOF)){
      ch = fgetc(fpe);
      buf[i++] = ch;
    }
    buf[i-1] = 0;
    de = atoi(buf);
  }
  old_de = de;
  fclose(fpe);

//  printf("Please Input Your File Name To Send:\n");
//  scanf("%s",filename);
  strcpy(filename,"c:\\jgs\\test.23");
  i = 0;
  while (filename[i++] != '.');
  filename[i-1] = 0;
  if (filename[strlen(filename)-3] != '.')
    strcat(filename,".23");
//  strcpy(filename,"line.23");
again:
  fpe = fopen(filename,"rb");
  if (fpe == NULL){
    printf("Cann't Find File: %s\n",filename);
    return -1;
  }
  ret_code = get_a_line1();
  success = 0;
  if (ret_code == -1){
    success = 1;
  }
  ee = 0;
  while (success == 0){
    send_a_line();
    ret_code = get_a_line1();
    if (ret_code == -1)
      success = 1;
    if (wint != 12345){
      ee ++;
      if (ee == 10)
	return -1;
    }
    if (kbhit()){
      ch = getch();
      if (ch == 0)
	ch = getch();
      if (ch == 27)
	success = 1;
      if (ch == ' '){
	ch = inportb(0x378);
	ch &= 0xef;
	outportb(0x378,ch);
	printf("Paused, Press Space Bar To Start!\n");
wait:
	ch = getch();
	if (ch == 0)
	  ch = getch();
	if (ch == 27){
	  success = 1;
	}
	else{
	  if (ch != ' '){
	    if ((ch == 'h')||(ch == 'H')){
	      x_c = -x_count;
	      y_c = -y_count;
	      if (x_c > 0)
		x_flag = 1;
	      else
		x_flag = 0;
	      light_status = 0;
	      for (l=0;l<labs(x_c);l++)
		send_a_step(1,0);
	      if (y_c > 0)
		y_flag = 1;
	      else
		y_flag = 0;
	      for (l=0;l<labs(y_c);l++)
		send_a_step(0,1);
	      fclose(fpe);
	      printf("Now, Waiting for Restart\n");
	      ch = getch();
	      if (ch != 27)
		goto again;
	      else
		exit(-1);
	    }
	    goto wait;
	  }
	  else{
	    if (light_status == 1){
	      ch = inportb(0x378);
	      ch |= 0x10;
	      outportb(0x378,ch);
	      light_status = 1;
	    }
	    printf("Now, Restarting\n");
	  }
	}
      }
      else{
	if (ch == '+'){
	  de = de*0.95;
	  if (de < old_de/3)
	    de = old_de/3;
	}
	if (ch == '-')
	  de = de*1.05;
      }
    }

  }
  fclose(fpe);
  outportb(0x378,0xff);
//  outportb(0x37a,0);
//  printf("If You Want To Continue, Press Enter!\n");
//  ch = getch();
//  if (ch == 13)
//    goto again;
}

get_a_line1()
{
  int ch,i;

  ch = fgetc(fpe);
  i = 0;
  while ((ch != EOF)&&(ch != 10)&&(ch != 13)){
    buf[i++] = ch;
    ch = fgetc(fpe);
  }
  buf[i] = 0;
  if (ch != EOF){
    ch = fgetc(fpe);
    return 1;
  }
  else
    return -1;
}

send_a_line()
{
  int i,j,x_step,y_step,oldx,oldy,x,y,time1;
  unsigned char ch,outch;
  float delay_time;
  int ret1;

  if (buf[0] != 'P'){
    if (buf[0] == 'O'){
      if (buf[2] == '0'){
	ch = inportb(0x378);
	ch &= 0xef;
	outportb(0x378,ch);
	light_status = 0;
      }
      else{
	ch = inportb(0x378);
	ch |= 0x10;
	outportb(0x378,ch);
	light_status = 1;
      }
    }
    else if (buf[0] == 'M'){
      if ((buf[1] == '1')&&((buf[2] == 0)||(buf[2] == ' '))){
	printf("Pause, Press Space Bar To Start!\n");
	getch();
      }
      if ((buf[1] == '1')&&(buf[2] == '0'))
	mask = 0xe0;   // 111
      if (buf[1] == '7')
	mask = 0x60;   // 011
      if (buf[1] == '6')
	mask = 0x90;   // 101
      if (buf[1] == '5')
	mask = 0x20;   // 001
      if (buf[1] == '4')
	mask = 0xd0;   // 110
      if (buf[1] == '3')
	mask = 0x40;  // 010
      if ((buf[1] == '1')&&(buf[2] == '2'))
	mask = 0x80; // 100
      if ((buf[1] == '1')&&(buf[2] == '1'))
	mask = 0;   // 000
      outch = mask;
      if (light_status == 1){
	outch |= 0x10;
       }
       else{
	 outch &= 0xef;
       }
       outportb(0x378,outch);
    }
    else if (buf[0] == 'W'){
      delay_time = atof(&(buf[1]));
      time1 = delay_time;
      delay(time1);
    }
    return -1;
  }
  x_step = atoi(&(buf[1]));
  if (x_step > 0)
    x_flag = 1;
  else{
    x_flag = 0;
    x_step = -x_step;
  }
  i = 0;
  while (buf[i] != ' ')
    i ++;
  y_step = atoi(&(buf[i]));
  if (y_step > 0)
    y_flag = 1;
  else{
    y_flag = 0;
    y_step = -y_step;
  }
  oldx = 0;
  oldy = 0;
  for (j=0;j<51;j++){
    x = (float)j*x_step/50.0+0.5;
    y = (float)j*y_step/50.0+0.5;
    if (x > oldx){
      if (y > oldy){
	send_a_step(1,1);
      }
      else{
	send_a_step(1,0);
      }
    }
    else{
      if (y > oldy){
	send_a_step(0,1);
      }
      else{
	send_a_step(0,0);
      }
    }
    oldx = x;
    oldy = y;
  }
  return 1;
}

send_a_step(int x_step,int y_step)
{
  unsigned char outch;

  outch = 0;
  if (x_flag == 1){
    outch |= 2;
  }
  if (y_flag == 1){
    outch |= 8;
  }
  if (x_step == 1){
    if (y_step == 1){
      outch |= 5;
    }
    else{
      outch |= 1;
    }
  }
  else{
    if (y_step == 1){
      outch |= 4;
    }
  }
  if (light_status == 1){
    outch |= 0x10;
  }
  else{
    outch &= 0xef;
  }
  outportb(0x378,outch);
//  outportb(0x378,5);
  delay2(1);
  outch = 0;
  if (x_flag == 1){
    outch |= 2;
  }
  if (y_flag == 1){
    outch |= 8;
  }
  if (light_status == 1){
    outch |= 0x10;
  }
  else{
    outch &= 0xef;
  }
  outch |= mask;
  outportb(0x378,outch);
  delay2(10);
//  delay1(4);
  if (x_flag == 1)
    x_count += x_step;
  else
    x_count -= x_step;
  if (y_flag == 1)
    y_count += y_step;
  else
    y_count -= y_step;
}

delay1(long len)
{
  long i,j;

//  for (i=0;i<len;i++)
//    for (j=0;j<22;j++); //375
    for (j=0;j<10;j++);
}

delay2(long len)
{
  long i,j;

  for (j=0;j<de;j++);
}

⌨️ 快捷键说明

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