亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gserial.cpp

?? DOS下串口通信程序庫
?? CPP
字號:

  /*------------------------------------------------------------------*
	  GSERIAL.CPP

	  For asynchronous serial port communications

      ATTENTION: Compile this program with Test Stack Overflow OFF.
				(TC++3: Options/Compiler/Entry
  *------------------------------------------------------------------*/

#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include "gserial.h"

#define VERSION 0x0101

#define FALSE				0
#define TRUE				1

#define NO_ERROR			0       /* No error               */
#define BUF_OVFL			1       /* Buffer overflowed      */

#define ESC					0x1B    /* ASCII Escape character */
#define ASCII				0x007F  /* Mask ASCII characters  */
//#define SBUFSIZ			0x4000  /* Serial buffer size     */
#define SBUFSIZ				0x08	/* Serial buffer size     */
#define IBUF_LEN			2048    // Incoming buffer
#define OBUF_LEN			1024    // Outgoing buffer


void           interrupt(*oldvects[2])(...);

/*  get status of the port  */
int read_status_com(int portn)
{
  return(inp(portn+5));
}

/*  send one valid char from the port  */
void send_char_com(int portn,int cc)
{
   while ((read_status_com(portn) & 0x40) == 0);
   outportb(portn,cc);
}

/*  send one string from the port  */
void send_string_com(int portn,int strlen,unsigned char *buf)
{
	int k;	k=0;
   do {
	   send_char_com(portn,*(buf + k));	k++;
	  } while ((k < strlen));
}



void interrupt com_int(...)
{
	int temp;
	disable();
	temp = (inportb(portbase+IIR)) & IIR_MASK;				// why interrupt was called
	switch(temp)
	{
		case 0x00:  // modem status changed
			inportb(portbase+MSR);   // read in useless char
			break;
		case 0x02:  // Request To Send char
			if (outhead != outtail)							// there's a char to send
			{
				outportb(portbase+TXR,outbuf[outhead++]);	// send the character
				if (outhead == OBUF_LEN)
					outhead=0;								// if at end of buffer, reset pointer
			}
			break;
		case 0x04:  // character ready to be read in
			inbuf[inhead++] = inportb(portbase+RXR);// read character into inbuffer
			if (inhead == IBUF_LEN) // if at end of buffer
				inhead=0;           // reset pointer
			break;
		case 0x06:  // line status has changed
			inportb(portbase+LSR);     // read in useless char
			break;
		default:
			break;

	}

	outportb(PIC8259_ICR, PIC8259_EOI);	// Signal end of hardware interrupt
	enable();							// reenable interrupts at the end of the handler

}



// Inserts the character to be outputted into the output buffer, checking
// for an open slot in the output buffer array.  If there is, insert
// the character, or if there isn't, wait until a slot opens up.
serial& serial::operator<<( char ch )
{
	if (ch)								// If this is a valid char
	{
		enable();						// turn on irqs to ensure data output
		//outportb(portbase + MCR,  MCR_INT | MCR_DTR | MCR_RTS);//modem control,
		outportb(portbase + IER,  IER_RX_INT);
		// check buffer, and if full, wait for an available opening

	//	fprintf(stdout,"\n %c is pressed!\n",ch);   //You can use this to verify which key is hit during your test
		while((outhead-1==outtail) ||(outtail==OBUF_LEN-1 && outhead==0));
		disable();						// make sure nothing happens while changing buffer
		outbuf[outtail++] = ch;			// insert character into buffer;
		if (outtail == OBUF_LEN)		// if at end of out buffer
			outtail = 0;				// reset pointer
		if((inportb(portbase+IER)&IER_TX_INT) == 0)
			outportb(portbase+IER,IER_TX_INT | IER_RX_INT);
		enable();                       // re-enable interrupts
	}

	return(*this);
}


serial &serial::operator<<( char *str )
// Outputs a string to the serial port
{
	while (*str)
	{
		(*this) << (*str);
		str++;
	}
	return(*this);
}


serial &serial::operator>>( char &ch )
// Returns either the character to be received from modem if there is one
// waiting in the buffer, or returns a 0 if there is no character waiting.
{
	if (inhead != intail)     // there is a character
	{
		disable();                          // disable irqs while getting char
		ch = inbuf[intail++];               // get character from buffer
		if (intail == IBUF_LEN)				// if at end of in buffer
			intail=0;						// reset pointer
		enable();                           // re-enable interrupt
		return(*this);                      // return the char
	}
	ch = -1;
	return(*this);                          // return nothing
}



/* Install our functions to handle communications */
void setvects(void)
{
    oldvects[0] = getvect(0x0B);
	oldvects[1] = getvect(0x0C);
    setvect(0x0B, com_int);
	setvect(0x0C, com_int);
}

/* Uninstall our vectors before exiting the program */
void resvects(void)
{
    setvect(0x0B, oldvects[0]);
    setvect(0x0C, oldvects[1]);
}



/* Tell modem that we're ready to go */
void serial::comm_on(void)
{
    int temp, pnum;


	disable();
	temp = inportb(portbase + MCR) | 0x0f;//MCR_INT;
	outportb(portbase + MCR, temp);
	temp = (inportb(portbase + IER)) | IER_RX_INT;//|IER_TX_INT;
	outportb(portbase + IER, temp);
	pnum = (portbase == COM1BASE ? COM1 : COM2);
	temp = inportb(PIC8259_IMR) & (pnum == COM1 ? IRQ4 : IRQ3);
	outportb(PIC8259_IMR, temp);

 //	temp = inportb(portbase + MCR) | MCR_DTR | MCR_RTS;
 //	outportb(portbase + MCR, temp);
	enable();
}

/* Go off-line */
void serial::comm_off(void)
{
     int  temp;

    disable();
	temp = inportb(PIC8259_IMR) | ~IRQ3 | ~IRQ4;
    outportb(PIC8259_IMR, temp);
    outportb(portbase + IER, 0);
	outportb(portbase + MCR, 0);
	enable();
}

void serial::init_serial(void)
{
    endbuf = startbuf = 0;
	setvects();
	comm_on();
}

serial::~serial()
{
    comm_off();
    resvects();
}

/* Set the port number to use */
int serial::SetPort(int Port)
{
    int  Offset, far *RS232_Addr;

    switch (Port)
	{ /* Sort out the base address */
      case COM1 : 
		  Offset = 0x0000;
          break;
      case COM2 : 
		  Offset = 0x0002;
		  break;
      default   :
		  printf("\ncannot find the serial port.\n");
		  return (-1);
    }

	RS232_Addr = (int far *)MK_FP(0x0040, Offset);  /* Find out where the port is. */
	if (*RS232_Addr == NULL)
	{
		printf("\ncannot find the serial port.\n");
		return (-1);                     /* If NULL then port not used. */
	}
    portbase = *RS232_Addr;              /* Otherwise set portbase      */

	return (0);
}

/* This routine sets the speed; will accept funny baud rates. */
/* Setting the speed requires that the DLAB be set on.        */
int serial::SetSpeed(int Speed)
{
	char	c;
    int		divisor;

    if (Speed == 0)            /* Avoid divide by zero */
        return (-1);
	else
        divisor = (int) (115200L/Speed);

    if (portbase == 0)
        return (-1);

    disable();
	c = inportb(portbase + LCR);
    outportb(portbase + LCR, (c | 0x80)); /* Set DLAB */
    outportb(portbase + DLL, (divisor & 0x00FF));
    outportb(portbase + DLH, ((divisor >> 8) & 0x00FF));
    outportb(portbase + LCR, c);          /* Reset DLAB */
	enable();

	return (0);
}

/* Set other communications parameters */
int serial::SetOthers(int Parity, int Bits, int StopBit)
{
	int  setting;

	if (portbase == 0)
		return (-1);
	if (Bits < 5 || Bits > 8)
		return (-1);
    if (StopBit != 1 && StopBit != 2)			
		return (-1);
    if (Parity != LCR_NO_PARITY && Parity != LCR_ODD_PARITY && Parity != LCR_EVEN_PARITY)
		return (-1);

    setting  = Bits-5;
    setting |= ((StopBit == 1) ? 0x00 : 0x04);
	setting |= Parity;

	disable();
	outportb(portbase + LCR, setting);
    enable();

    return (0);
}

/* Set up the port */
serial::serial(int Port, int Speed, int Parity, int Bits, int StopBit)
{
	flag = 0;
	if (SetPort(Port))
	  flag = -1;
	if (SetSpeed(Speed))
	  flag = -1;
	if (SetOthers(Parity, Bits, StopBit))
	  flag = -1;

	if (!flag)
	   init_serial();
}

/*  Control-Break interrupt handler */
int c_break(void)
{
	int temp;
	disable();
	temp = inportb(PIC8259_IMR) | ~IRQ3 | ~IRQ4;
	outportb(PIC8259_IMR, temp);
	outportb(portbase + IER, 0);
	outportb(portbase + MCR, 0);
	enable();
	fprintf(stderr, "\nStill online.\n");
	return(0);
}

main()
{
	/* Communications parameters */
	int        port     = COM1;
	int        speed    = 9600;
	int        parity   = LCR_NO_PARITY;
	int        bits     = 8;
	int        stopbits = 1;
	int        done  = FALSE;
	char       c;
	int temp,i=0,j=0;

	serial comport(port, speed, parity, bits, stopbits);

	ctrlbrk(c_break);
	//for(i=0;i<OBUF_LEN;i++)
	//{
	//	outbuf[i] = 'a'+i;
	//}
	//static   char  outbuf[OBUF_LEN];		// out buffer

	fprintf(stdout, "TURBO C TERMINAL\n"
			"...You're now in terminal mode, "
			"press [ESC] to quit...\n\n");

	/*
	   The main loop aMSR_CTS as a dumb terminal. We repeatedly
	   check the keyboard buffer, and communications buffer.
	*/
	do {
		if (kbhit())
		{
			c=getch();
			/* Look for an Escape key */
			switch (c)
			{
				case ESC:
					done = TRUE;  /* Exit program */
					break;

			//You may want to handle other keys here
			}
			if (!done)   comport<<c;
			//send_char_com(portbase,c); //This is another send function,I add this function because some people (esp. older) don't like c++(they use c)
		}
		delay(50);
		comport >> c;
		if (c != -1)     //'-1' is the END signal of a string
		{
			//fputc(c & ASCII, stdout);
			fprintf(stdout,"%c",c);
		}

	} while (!done && !SError);

	/* Check for errors */
	switch (SError)
	{
		case NO_ERROR: fprintf(stderr, "\nbye.\n");
					  return (0);

		case BUF_OVFL: fprintf(stderr, "\nBuffer Overflow.\n");
					  return (99);

		default:      fprintf(stderr, "\nUnknown Error, SError = %d\n",
							  SError);
					  return (99);
	}
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一本高清dvd不卡在线观看| 亚洲国产三级在线| 欧美人xxxx| 92国产精品观看| 国产91在线看| 国产高清在线精品| 国产精品456露脸| 国产成人综合自拍| 成人午夜视频免费看| 成人av动漫网站| 一本久久a久久精品亚洲| 在线观看91视频| 欧美性色欧美a在线播放| 欧美日韩在线综合| 日韩免费电影网站| 久久综合久久综合久久| 久久久亚洲精品一区二区三区| 国产色婷婷亚洲99精品小说| 欧美国产综合一区二区| 日韩一区在线播放| 亚洲3atv精品一区二区三区| 裸体健美xxxx欧美裸体表演| 国产乱码精品一区二区三| 成熟亚洲日本毛茸茸凸凹| 色婷婷综合中文久久一本| 欧美美女视频在线观看| 精品久久久三级丝袜| 国产精品丝袜久久久久久app| 亚洲人成在线观看一区二区| 偷拍一区二区三区| 国产河南妇女毛片精品久久久| 一本到一区二区三区| 日韩一级片在线观看| 中文字幕第一区二区| 亚洲综合图片区| 极品美女销魂一区二区三区免费| 成人黄色综合网站| 欧美一区二区国产| 专区另类欧美日韩| 久久精品72免费观看| 99精品视频在线免费观看| 欧美一区二区福利视频| 国产精品乱子久久久久| 日本欧美在线观看| 99精品国产一区二区三区不卡| 欧美高清你懂得| 亚洲欧洲色图综合| 精品无人码麻豆乱码1区2区 | 国产v综合v亚洲欧| 欧美日韩国产一二三| 国产亚洲欧美激情| 热久久国产精品| 99久久国产综合精品色伊| 久久日韩精品一区二区五区| 亚洲一区二区三区四区五区黄| 国产成人精品一区二| 91精品综合久久久久久| 综合久久综合久久| 国产曰批免费观看久久久| 欧美亚洲综合另类| 欧美韩国日本不卡| 久久精品72免费观看| 欧美伦理视频网站| 亚洲影院久久精品| 91麻豆国产在线观看| 中文乱码免费一区二区| 韩国一区二区三区| 精品国产91亚洲一区二区三区婷婷 | 天天做天天摸天天爽国产一区| 成人黄色国产精品网站大全在线免费观看| 欧美一级二级在线观看| 日韩国产欧美一区二区三区| 欧美三级中文字幕在线观看| 亚洲自拍与偷拍| 色综合一个色综合| 亚洲欧美日韩久久| 91色九色蝌蚪| 亚洲少妇30p| 一本大道久久a久久精品综合| 国产精品毛片大码女人| 不卡区在线中文字幕| 136国产福利精品导航| 99国产欧美久久久精品| 亚洲欧美日韩久久| 欧美日韩一区高清| 日韩va欧美va亚洲va久久| 在线播放视频一区| 狂野欧美性猛交blacked| 精品国产免费久久| 高清国产一区二区| 国产精品久久久久久久午夜片 | 亚洲福利一区二区| 欧美日韩一本到| 免费看欧美女人艹b| 久久一夜天堂av一区二区三区| 精品午夜久久福利影院 | 夜夜亚洲天天久久| 欧美日韩黄色影视| 国产一区二区剧情av在线| 国产精品女同互慰在线看| 色中色一区二区| 日韩av高清在线观看| 久久影院电视剧免费观看| 成人高清在线视频| 午夜精彩视频在线观看不卡| 欧美mv日韩mv| 91视频你懂的| 日本中文字幕一区二区视频| 国产亚洲成aⅴ人片在线观看| av亚洲精华国产精华| 五月天一区二区| 国产欧美日韩精品一区| 色婷婷综合久久久久中文一区二区 | 亚洲乱码中文字幕| 日韩欧美在线观看一区二区三区| 懂色av中文一区二区三区| 亚洲电影一级片| 国产精品色哟哟网站| 欧美一区二区在线视频| 91在线视频网址| 久久精品国产久精国产| 亚洲欧美激情插 | 国产成人av一区二区三区在线| 亚洲线精品一区二区三区八戒| 欧美成人艳星乳罩| 99久免费精品视频在线观看| 蜜臀a∨国产成人精品| 国产精品美女久久久久aⅴ| 日韩你懂的在线观看| 国产精品一卡二卡在线观看| 天天综合网天天综合色| 中文字幕视频一区| 欧美大胆一级视频| 在线观看欧美日本| 国产精品一级二级三级| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲激情自拍偷拍| 久久综合五月天婷婷伊人| 欧美日韩一二区| 97se亚洲国产综合自在线不卡| 国产高清在线精品| 国内精品免费**视频| 亚洲综合丝袜美腿| 中文字幕日韩欧美一区二区三区| 久久久久久**毛片大全| 日韩一级视频免费观看在线| 欧美精品黑人性xxxx| 91成人免费在线| 91福利社在线观看| 91在线视频观看| 99精品久久99久久久久| 成人精品视频一区二区三区 | 欧美丝袜自拍制服另类| 99r精品视频| 粉嫩嫩av羞羞动漫久久久| 国产在线视视频有精品| 久久激情综合网| 精品一区二区三区免费视频| 日韩avvvv在线播放| 日日噜噜夜夜狠狠视频欧美人| 亚洲成人综合在线| 亚洲国产精品久久艾草纯爱| 亚洲精品视频在线看| 亚洲日本成人在线观看| 亚洲精品久久久蜜桃| 尤物在线观看一区| 亚洲午夜精品17c| 亚洲v精品v日韩v欧美v专区| 亚洲va中文字幕| 免播放器亚洲一区| 国产美女娇喘av呻吟久久| 国产91丝袜在线播放0| 成人激情午夜影院| 在线看日本不卡| 欧美日韩一区二区在线观看视频 | 久久av中文字幕片| 久久精品国产免费| 国产91露脸合集magnet| 91麻豆精品在线观看| 欧美久久久久久久久久| 欧美白人最猛性xxxxx69交| 久久午夜电影网| 亚洲日本va在线观看| 午夜精品久久久| 国产一区二区三区香蕉| 94色蜜桃网一区二区三区| 欧美日韩另类一区| wwww国产精品欧美| 亚洲免费在线电影| 免费成人在线播放| 99久久精品国产导航| 欧美精品色一区二区三区| 26uuu久久天堂性欧美| 亚洲色图都市小说| 欧美aⅴ一区二区三区视频| 国产成人免费xxxxxxxx| 欧美熟乱第一页| 久久精品视频一区二区| 亚洲成人资源网| 成人中文字幕电影|