Dear friends,
I'm facing yet another problem. This time, it is about sending and
receiving data from the serial ports. I've modified the program
"example.c" given in the I/O programming mini-HOWTO to write two programs
client.c and iserve.c. The iserve program running on the console sends out
data to one serial port, and the client program running on a virtual
terminal monitors the other serial port, the two serial ports being
connected together by a serial cable.
Now what is happening is that the client program is continuously
displaying the data on the serial port it monitors as 255, no matter what
data I send out to the port from the iserve program.
Do I have to make sure that the baud rate & data comm. settings of
both the ports are the same? ( since normally they correspond to the modem
and the mouse). Also how do I modify these settings?
Also I want to develop some sort of a network based on the RS
485 standard, where a server running Linux controls a few clients based on
the 8051. I've finished designing the client machines, and am in the
process of constructing one, and i've just started working on the server
side software. Which books should I refer to for help on networking?
I'm pasting the two programs client.c and iserve.c below.
------------------------------------------------------------------------------
/* This program was written based on "example.c" given in the I/O
*/
/* programming mini HOWTO. This program just gets input from */
/* serial port 0x2F8 and prints it out on the screen, as long as */
/* the input character is not the pre-determined end of */
/* transmission character, the integer 5 in this instance. */
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>
int main()
{
int thischar;
if (ioperm(0x2F8, 3, 1))
{
perror("ioperm");
exit(1);
}
while((thischar=inb(0x2F8))!=5)
{
printf("status: %d\n", thischar);
}
if (ioperm(0x2F8, 3, 0))
{
perror("ioperm");
exit(1);
}
exit(0);
}
/*---------------------------------------------------------------------------*/
/*---------------------------End of client.c---------------------------*/
/*---------------------------------------------------------------------------*/
/*This program is executed on another virtual terminal, and it just */
/*sends some data out to the serial port 0x3F8 with some delay in */
/*between successive characters. */
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>
int main()
{int n;
usleep(15000000);
/* delay gives me enough time to start `client.c' on the other virutal */
/* terminal.*/
if (ioperm(0x3F8, 2, 1)) {perror("ioperm"); exit(1);}
for(n=1;n<=5000;n++)
{
outb(n, 0x3F8);
usleep(2000000);
}
if (ioperm(0x3F8, 2, 0)) {perror("ioperm"); exit(1);}
exit(0);
}
/*---------------------------------------------------------------------------*/
/*----------------------------End of iserve.c-----------------------------*/
/*--------------------------------------------------------------------------*/
-------------------------------------------------------------------------------
Aalhad Saraf Electronics Engineering Senior at the University of Pune.
More info about me: http://home.talkcity.com/UniversityWay/aal
-------------------------------------------------------------------------------