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

📄 commu.c

📁 在以前公司DOS环境下
💻 C
字号:
#include<io.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<graph.h>
#include<time.h>
#include<dos.h>
#include<fcntl.h>
#include<malloc.h>
#include<share.h>
#include<math.h>

#include "svgacc.h"      
#include "pcl4c.h"

char RxBuffer[1024+16];
char TxBuffer[512+16];

int ErrorCheck(int);
int bcccheck(char *str);

#define TRUE 1
#define FALSE 0

#define iCOM 1
#define STX 2
#define ETX 3
#define EOT 4
#define ENQ 5
#define ACK 6
#define BS  8
#define NAK 21
#define ENTER 13
#define ESC 27
static char buf2[140];    
static int Port;
int getkey(void);
static char str[40];
void main(void)
{int i;
 char far *Ptr;
 int  Seg;
 int ok;
 char gchar;
 int counter,recievechar;

   
   Port=iCOM;
   Ptr = (char far *)RxBuffer;
   Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
   ErrorCheck(SioRxBuf(Port,Seg,Size1024));

   Ptr = (char far *)TxBuffer;
   Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
   ErrorCheck( SioTxBuf(Port,Seg,Size512) );
   ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
   ErrorCheck( SioReset(Port,Baud9600) );
   i = SioFIFO(Port,LEVEL_4TH);
  ok=TRUE;
  counter=-1;
  for(i=0;i<140;i++)
    buf2[i]=' ';
  recievechar=TRUE;
  while (ok)
  {  
  /*
  if (recievechar==TRUE)
  {buf2[0]='1';
   buf2[1]=ENTER;
   buf2[2]='\0';
   SioRTS(Port,'S');
   SioPuts(Port,buf2,2);
   SioEmpty(Port);
   SioRTS(Port,'C');
   recievechar=FALSE;
   } */               
  gchar=(char)SioGetc(Port,0);
  
  if ((gchar!=STX)&&(counter<0))
      {counter=-1;
       recievechar=TRUE;
       buf2[0]='\0';
      }
   if (gchar==STX) 
     counter=0;
    else if ((gchar==ENTER)||(counter==60))
         { buf2[counter]='\0';
          /* if (bcccheck(buf2)) */
             printf("%s\n",buf2);
             recievechar=TRUE;  
             counter=-1;
            getch();
           
         }
      else    
        {if (gchar>=' ')
            buf2[counter]=gchar;
            counter++;
        }
  if (kbhit())
    {gchar=(char)getkey();
     if (gchar==ESC)
        ok=FALSE;
    }
}
SioDone(Port);
}
int bcccheck(char *str)
{int i,j,bcc;

 i=strlen(str);
 bcc=str[0];
 for(j=1;j<i-1;j++)
   bcc=bcc ^ str[j];
 if(bcc<' ') bcc=bcc+' ';
 if(bcc==str[i-1])
   return TRUE;
 else
   return FALSE;
}
int ErrorCheck(int Code)
{/* trap PCL error codes */
 if(Code<0)
     {printf("ERROR %d:",Code);
      SioError(Code);
      SioDone(Port);
      exit(1);
     }
 return(0);
} /* end ErrorCheck */

int getkey(void)
{ union REGS in,out;
  in.h.ah=0x8;
  int86(0x21,&in,&out);
  if(out.h.al==0)
   return getkey()+128;
  else
   return out.h.al;
}

⌨️ 快捷键说明

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