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

📄 send.c

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

extern char filename[20];
FILE *fpe;
extern char buf[200];
extern char filename[20];
int x_flag,y_flag;
extern long x_count,y_count;
int light_status=0;

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

int de;

send_file()
{
  int ret_code,ch,success,i;

//  getch();
  outportb(0x3f8,0);
  fpe = fopen("setup1.fil","rb");
  if (fpe == NULL){
    printf("Cann't Found File: Setup1.fil!\n");
    return;
  }
  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);
  }
  fclose(fpe);

//  printf("Please Input Your File Name To Send:\n");
//  scanf("%s",filename);
  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();
  test_dog();
  success = 0;
  if (ret_code == -1){
    success = 1;
  }
  while (success == 0){
    send_a_line();
    ret_code = get_a_line1();
    if (ret_code == -1)
      success = 1;
    if (kbhit()){
      ch = getch();
      if (ch == 0)
	ch = getch();
      if (ch == 27)
	success = 1;
      if (ch == ' '){
	printf("Paused, Press Space Bar To Start!\n");
wait:
	ch = getch();
	if (ch == 0)
	  ch = getch();
	if (ch == 27){
	  outportb(0x3f8,0);
	  success = 1;
	}
	else{
	  if (ch != ' ')
	    goto wait;
	}
	printf("Now, Restarting\n");
      }
    }
  }
  fclose(fpe);
  outportb(0x3f8,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){
    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;
  float delay_time;

  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] == 'W'){
      delay_time = atof(&(buf[1]));
      time1 = delay_time*1000;
      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;
  }
  outportb(0x378,outch);
  delay2(10);
//  delay1(4);
  x_count += x_step;
  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 + -