how can udp data can passed through RS232 in ansi c?

Posted by moon on Stack Overflow See other posts from Stack Overflow or by moon
Published on 2010-05-20T05:57:59Z Indexed on 2010/05/20 6:00 UTC
Read the original article Hit count: 276

Filed under:

i want to transmit and receive data on RS232 using udp and i want to know about techniques which allow me to transmit and receive data on a faster rate and also no lose of data is there?

thanx in advance. i have tried but need improvements if possible

 #include <stdio.h>
 #include <dos.h>
 #include<string.h>
 #include<conio.h>
 #include<iostream.h>
 #include<stdlib.h>

 #define PORT1 0x3f8

 void main()
 {
int c,ch,choice,i,a=0;
char filename[30],filename2[30],buf;
FILE *in,*out;
clrscr();
while(1){
outportb(PORT1+0,0x03);
outportb(PORT1+1,0);
outportb(PORT1+3,0x03);
outportb(PORT1+2,0xc7);
outportb(PORT1+4,0x0b);
cout<<"\n===============================================================";
cout<<"\n\t*****Serial Communication By BADR-U-ZAMAN******\nCommunication between two computers By serial port";
cout<<"\nPlease select\n[1]\tFor sending file \n[2]\tFor receiving file \n[3]\tTo exit\n";
cout<<"=================================================================\n";

cin>>choice;
if(choice==1)
{
    strcpy(filename,"C:\\TC\\BIN\\badr.cpp");
    cout<<filename;
    for(i=0;i<=strlen(filename);i++)
        outportb(PORT1,filename[i]);
    in=fopen(filename,"r");
    if (in==NULL)
    {       cout<<"cannot open a file";
         a=1;
    }
    if(a!=1)
    cout<<"\n\nFile sending.....\n\n";
    while(!feof(in))
    {
        buf=fgetc(in);
        cout<<buf;
        outportb(PORT1,buf);
        delay(5);
    }
}
else
{
    if(choice==3)
    exit(0);
    i=0;
    buf='a';
    while(buf!=NULL)
    {
        c=inportb(PORT1+5);
        if(c&1)
        {
            buf=inportb(PORT1);
            filename2[i]=buf;
            i++;
        }
    }
    out=fopen(filename2,"t");
    cout<<"\n Filename received:"<<filename[2];
    cout<<"\nReading from the port...";
    cout<<"writing to file"<<filename2;
    do
    {
        c=inportb(PORT1+5);
        if(c&1)
        {
        buf=inportb(PORT1);
        cout<<buf;
        fputc(buf,out);
        delay(5);
        }
        if(kbhit())
        {
        ch=getch();
        }
    }while(ch!=27);
}
 getch();
 }
 }

© Stack Overflow or respective owner

Related posts about c