📄 sent.c
字号:
/*****************************************************************************/
/*功能:进行串口通信。可以通过串口接收和发送文件。 */
/*作者:李士伟 */
/*版权:cfix软件小组 */
/*开发时间:2008.4.20-2008 */
/*****************************************************************************/
/************************** main.h********************************************/
#include<stdio.h>
unsigned char Com2_In();
unsigned char Com2_Out(unsigned char ch);
/************************** end main.h ***************************************/
/************************** comx.c *******************************************/
unsigned char Com2_In()
{
unsigned char ch;
asm mov ax,3fdh
testate:asm in al,dx
asm test al,01h
asm je testate
asm mov dx,3f8h
asm in al,dx
asm mov ch,al
return ch;
}
unsigned char Com2_Out(unsigned char ch)
{
asm mov dx,3fdh
testate1:asm in al,dx
asm test al,20h
asm je testate1
asm mov al,ch
asm mov dx,3f8h
asm out dx,al
return ch;
}
/************************* end comx.c ****************************************/
/************************* transfersfile.c ***********************************/
int SentFile(char *outfile)
{
FILE *ptroutfile;
ptroutfile=fopen(outfile,"rb");
if(ptroutfile==NULL)
{
printf("File sent error!\n");
getch();
exit(1);
}
printf("transfering......");
while(!feof(ptroutfile))
printf("%c",Com2_Out(fgetc(ptroutfile)));
Com2_Out(0);
printf("\nok!");
return 1;
}
int ReceiveFile(char *infile)
{
unsigned char ch;
FILE *ptrinfile;
ptrinfile=fopen(infile,"wb");
if(ptrinfile==NULL)
{
printf("Receive file error!\n");
getch();
exit(1);
}
printf("transfering......");
while((ch=Com2_In())!=0)
{
printf("%c",ch);
fputc(ch,ptrinfile);
}
printf("\nok!");
return 1;
}
/************************ main.c *********************************************/
void main(int argc,char *argv[])
{
char c;
char filename[40];
if(argc!=3)
{
ShowInfo();
c=getch();
putchar(c);
if(c=='1')
{
printf("\nplease enter sent file name:");
gets(filename);
SentFile(filename);
}
else if(c=='2')
{
printf("\nplease enter save file name:");
gets(filename);
ReceiveFile(filename);
}
else
exit(0);
}
}
int ShowInfo()
{
printf("\t\t **********************************\n");
printf("\t\t * file transfer 1.0 edition *\n");
printf("\t\t * author:lishiwei *\n");
printf("\t\t * cfixsoft *\n");
printf("\t\t **********************************\n");
printf("\t\t [1]sent file\n");
printf("\t\t [2]receive file\n");
printf("\t\t [3]exit\n");
printf("\t\t please enter a choose [ ]\b\b");
return 1;
}
/********************** end main.c *******************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -