using serial port read and write
Hi every body
this is not for only to debian forum, since the number of debian'user is huge
I hope find an answer.
thanks a lot in advance.
I have written 2 small programs for writing on serial port S0 and another for reading from the port S1.
My machines have 2 physical serial port.
I connect the S0 to S1 via a crossed cable.
On one machine the programs ran perfectly,
when I tried them on another machine, exactly same machine running same system ( linuxMint),
in same conditions, they didn't.
the writing program to port S0 ran but the reading from S1 !!!
the situation is like no physical connection on 2 port exits!!! It is of course;
Very strange, so may be the I have to do something to activate the ports ???
Why it run on one case and not on another!!!
thanks a lot for any idea.
Here are my programs
regards
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#define WAIT 200000
// I have 2 physical serial ports
#define BASEPORT1 0x3f8
#define BASEPORT2 0x2f8
int main(){
char c, i, ch[20], j=0;
printf("\nPort S0 OK \n");
if (ioperm(BASEPORT2, 3, 1)) {
printf("\nErrorr S1 \n"); exit(1);
}
if (ioperm(BASEPORT1, 3, 1)) {
printf("\nError S0 \n"); exit(1);
}
printf("\nPort S1 OK \n");
printf("\n\nThis Program must run first !! \n");
while(1){
c=inb(BASEPORT2);
if ( c > 64 && c < 80) break;
usleep(WAIT);
}
printf("\nStart reading from S1 \n");
while(j++ <3) {
for(i=0; i<26 ; i++){
ch[i]=c; usleep(WAIT);
c=inb(BASEPORT2);
}
ch[i]=0;// ch[i+1]=0;
printf("\nText received %s\n",ch);
}
outb(0, BASEPORT1); // Flush buffer thru port S0
/* We don't need the ports anymore */
if (ioperm(BASEPORT2, 3, 0)) {perror("ioperm"); exit(1);}
exit(0);
}
/****
This second program write on S0 port
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#define WAIT 200000
#define BASEPORT1 0x3f8
#define BASEPORT2 0x2f8
int main(){
char c, i, j=0, ch[20];
/* Get access to the ports */
if (ioperm(BASEPORT1, 3, 1)) {
printf("\nError S0 \n"); exit(1);
}
printf("\nWriting to port S0 \n");
outb(0, BASEPORT1);
while(j++ <3)
for(c='A'; c<='Z'; c++){
outb(c, BASEPORT1);
usleep(WAIT);
}
outb(0, BASEPORT1);
if (ioperm(BASEPORT1, 3, 0)) {perror("ioperm"); exit(1);}
exit(0);
}
Reply to: