garg29
Advanced Member level 1
file transfer inportb baud rate
Hi,
Can anyone please tell me how can i transfer files between 2-computers using parallel port (without LAN card). I found one program in C++ to do this but it didn't worked out, i'm sending that as attachment. Please help me.
Thanks with best regards,
amit
/* File Transfer-Binu LS */
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
int port_address;
void main()
{
void baudset(long );/*user defined fn. for setting baud rate.*/
void comparm(int,int,int); /*user defined fn. for setting parity, stopbits,databits etc.*/
FILE *f;
char chr;
char *fname;
int result,status,choice,port;
unsigned int fstat,mstat,lstat;
clrscr();
textcolor(6);
gotoxy(15,5);
cprintf("PROGRAM TO TRANSFER FILES BETWEEN TWO COMPUTERS ");
textcolor(3);
cprintf("Ver. 1.0\n");
gotoxy(12,6);
textcolor(14);
cprintf("By L.S Binu, Lect./Dept. of EIE/NI College of Engg.,Kumaracoil\n");
gotoxy(25,10);
textcolor(7);
cprintf("1. SEND FILE\n");
gotoxy(25,11);
cprintf("2. RECEIVE FILE\n");
gotoxy(25,12);
cprintf("3. EXIT\n");
gotoxy(25,13);
cprintf("Enter Your Choice(1,2 or 3):");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
printf("\n");
printf("Select Port(Enter '1' for COM1 '2' for COM2):");
scanf("%d",&port);
if(port==1)
port_address=0x3F8;
else
port_address=0x2F8;
baudset((long)2400); /*set baud rate to 2400*/
comparm(0,1,8); /*no parity, 1 stop bit, 8 data bits*/
outportb(port_address+4,1|2);/*turn on hand shaking signals*/
textcolor(4);
printf("Enter file to send:");
scanf("%15s",&fname);
f=fopen(&fname,"r");
if(f==NULL)
{
cprintf("COULD NOT OPEN FILE: \n");
exit(0);
}
textcolor(2);
for(;
{
if(kbhit())
{
if(getch() == 27)/*if 'esc' key pressed then exit*/
exit(0);
}
lstat = inportb(port_address+5);/*if transmitter holding reg. empty*/
if(!(lstat & 32))/*send the next character*/
continue;
else
{
chr = fgetc(f);/*get a character from file*/
}
if (chr==EOF) /* if end of file*/
{
cprintf(" transmission completed");
outportb(port_address,EOF);
exit(0);
}
outportb(port_address, chr); /*send character*/
putchar(chr); /*display the character sent*/
}
fclose(f);
break;
}
case 2:
{
printf("\n");
printf("Select Port(Enter '1' for COM1 '2' for COM2):");
scanf("%d",&port);
if(port==1)
port_address=0x3F8;
else
port_address=0x2F8;
baudset((long)2400);
comparm(0,1,8);
outportb(port_address+4,1|2);
textcolor(4);
printf("Save as (file name):");
scanf("%15s",&fname);
f=fopen(&fname,"w");
if(f==NULL)
{
cprintf("COULD NOT OPEN FILE\n");
exit(0);
}
printf("Waiting for i/p \n");
cprintf("Press ESC to exit\n");
for(;
{
if(kbhit())
{
if(getch()==27)
break;
}
fstat=inportb(port_address+5);
if(fstat & 2)
cprintf("Over_run error\n");
if(fstat & 4)
cprintf("parity error\n");
if(fstat & 8)
cprintf("Framing error\n");
if(fstat & 16)
cprintf("Break received\n");
if(!(fstat & 1)) /*if data not ready*/
continue;
chr=inportb(port_address);/*if data ready read it from receive buffer*/
if(chr==EOF)
{
textcolor(2);
cprintf(" File received");
exit(0);
}
putchar(chr);
fputc(chr,f);
}
outportb(port_address+4,0); /*turn off hand shaking signals*/
fclose(f);
break;
}
case 3:
break;
}
}
void baudset(long baudrate)
{
unsigned int divisor;
unsigned char lsb,msb;
divisor=1152001/baudrate;
msb=divisor>>8;
lsb=(divisor<<8)>>8;
outportb(port_address+3,128); /*enable access to the divisor latches by setting the access bit in line cntrl. reg.*/
outportb(port_address,lsb); /*LSB of divisor*/
outportb(port_address+1,msb); /*MSB of divisor*/
}
void comparm(int parity,int stop,int databits)
{
int parmbyte;
parmbyte=databits-5;
if (stop==2)
parmbyte|=4;
if (parity!=0)
parmbyte|=8;
if (parity==2)
parmbyte|=16;
outportb(port_address+3,parmbyte);/*writing the cntrl. word corresponding*/
/*to the parity,stop bits etc. in the*/
} /*line control reg.*/
Hi,
Can anyone please tell me how can i transfer files between 2-computers using parallel port (without LAN card). I found one program in C++ to do this but it didn't worked out, i'm sending that as attachment. Please help me.
Thanks with best regards,
amit
/* File Transfer-Binu LS */
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
int port_address;
void main()
{
void baudset(long );/*user defined fn. for setting baud rate.*/
void comparm(int,int,int); /*user defined fn. for setting parity, stopbits,databits etc.*/
FILE *f;
char chr;
char *fname;
int result,status,choice,port;
unsigned int fstat,mstat,lstat;
clrscr();
textcolor(6);
gotoxy(15,5);
cprintf("PROGRAM TO TRANSFER FILES BETWEEN TWO COMPUTERS ");
textcolor(3);
cprintf("Ver. 1.0\n");
gotoxy(12,6);
textcolor(14);
cprintf("By L.S Binu, Lect./Dept. of EIE/NI College of Engg.,Kumaracoil\n");
gotoxy(25,10);
textcolor(7);
cprintf("1. SEND FILE\n");
gotoxy(25,11);
cprintf("2. RECEIVE FILE\n");
gotoxy(25,12);
cprintf("3. EXIT\n");
gotoxy(25,13);
cprintf("Enter Your Choice(1,2 or 3):");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
printf("\n");
printf("Select Port(Enter '1' for COM1 '2' for COM2):");
scanf("%d",&port);
if(port==1)
port_address=0x3F8;
else
port_address=0x2F8;
baudset((long)2400); /*set baud rate to 2400*/
comparm(0,1,8); /*no parity, 1 stop bit, 8 data bits*/
outportb(port_address+4,1|2);/*turn on hand shaking signals*/
textcolor(4);
printf("Enter file to send:");
scanf("%15s",&fname);
f=fopen(&fname,"r");
if(f==NULL)
{
cprintf("COULD NOT OPEN FILE: \n");
exit(0);
}
textcolor(2);
for(;
{
if(kbhit())
{
if(getch() == 27)/*if 'esc' key pressed then exit*/
exit(0);
}
lstat = inportb(port_address+5);/*if transmitter holding reg. empty*/
if(!(lstat & 32))/*send the next character*/
continue;
else
{
chr = fgetc(f);/*get a character from file*/
}
if (chr==EOF) /* if end of file*/
{
cprintf(" transmission completed");
outportb(port_address,EOF);
exit(0);
}
outportb(port_address, chr); /*send character*/
putchar(chr); /*display the character sent*/
}
fclose(f);
break;
}
case 2:
{
printf("\n");
printf("Select Port(Enter '1' for COM1 '2' for COM2):");
scanf("%d",&port);
if(port==1)
port_address=0x3F8;
else
port_address=0x2F8;
baudset((long)2400);
comparm(0,1,8);
outportb(port_address+4,1|2);
textcolor(4);
printf("Save as (file name):");
scanf("%15s",&fname);
f=fopen(&fname,"w");
if(f==NULL)
{
cprintf("COULD NOT OPEN FILE\n");
exit(0);
}
printf("Waiting for i/p \n");
cprintf("Press ESC to exit\n");
for(;
{
if(kbhit())
{
if(getch()==27)
break;
}
fstat=inportb(port_address+5);
if(fstat & 2)
cprintf("Over_run error\n");
if(fstat & 4)
cprintf("parity error\n");
if(fstat & 8)
cprintf("Framing error\n");
if(fstat & 16)
cprintf("Break received\n");
if(!(fstat & 1)) /*if data not ready*/
continue;
chr=inportb(port_address);/*if data ready read it from receive buffer*/
if(chr==EOF)
{
textcolor(2);
cprintf(" File received");
exit(0);
}
putchar(chr);
fputc(chr,f);
}
outportb(port_address+4,0); /*turn off hand shaking signals*/
fclose(f);
break;
}
case 3:
break;
}
}
void baudset(long baudrate)
{
unsigned int divisor;
unsigned char lsb,msb;
divisor=1152001/baudrate;
msb=divisor>>8;
lsb=(divisor<<8)>>8;
outportb(port_address+3,128); /*enable access to the divisor latches by setting the access bit in line cntrl. reg.*/
outportb(port_address,lsb); /*LSB of divisor*/
outportb(port_address+1,msb); /*MSB of divisor*/
}
void comparm(int parity,int stop,int databits)
{
int parmbyte;
parmbyte=databits-5;
if (stop==2)
parmbyte|=4;
if (parity!=0)
parmbyte|=8;
if (parity==2)
parmbyte|=16;
outportb(port_address+3,parmbyte);/*writing the cntrl. word corresponding*/
/*to the parity,stop bits etc. in the*/
} /*line control reg.*/