C语言串口通信-源代码
void Int()
{
unsigned char key,key2;
port=ComNum-1;
if(peek(0x40,port*2)==0)
{
printf("have no special com .\n");
exit(1);
}
else
{
printf("The used port is :COM%d\n",ComNum);
};
Getportaddr(port); // 得到串口地址
SerInit(SER_BAUD_9600,SER_PARITY_EVEN| SER_BITS_8 | SER_STOP_1); //初始化串口,设置波特率等
SerOpen();
do
{
if(kbhit())
{
key2=getch();
if(key2==27){ break;}
};
key=getb();
if(key!=0xff)
{
printf("%x\t",key);
FILE *fp;
fp=fopen("C:\\Receivedata.dat","ab"); //可选择接收数据的存放文件路径和文件名 if(fp==NULL) printf("File open error!");
// fputc(key,fp);
fwrite(&key,sizeof(unsigned char),1,fp);
fclose(fp);
}
}while (key2!=27);
SerClose();
// printf("%d char has been received\n",incount);
// printf("%d char has been sended\n",outcount);
// printf("\nsum=%d \n",sum);
}
void main()//com1 receive
{
printf("Please input the receive COMnum:(1~4)\n");
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库C语言串口通信-源代码(7)在线全文阅读。
相关推荐: