Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Will code to run com 2 in linux work?

Status
Not open for further replies.

Bosah

MIS
Feb 9, 2001
39
0
0
CA
I'm trying to write a very simple program to open and close com 2. A good friend furnished me with this and I can't make it work on Mandrake 8.

If there is any help out there it would be appreciated.

Bo



/*
* relay.c: very simple port I/O
*
* Compile with `gcc -O2 -o relay relay.c',
* and run as root with `./relay'.
* This program reads from standard in until it gets a EOF (^D)
* to use in unattended mode just run as relay < inputfile
*/

#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>

#define BASEPORT 0x3FC /*com 1 */
define BASEPORT 0x2FC /*com 2 */

int main()
{
int a;
int x;
/* Get access to the ports */
if (ioperm(BASEPORT, 1, 1)) {
fprintf(stderr,&quot;error performing ioperm\n&quot;);
exit(1);
}

do {
a=fgetc(stdin);
if (a == EOF) continue; // Jump to end of loop on end condition
x = inb(BASEPORT);
if (a == 49) x &= ~2; // If you get a 0 in clear relay #1
if (a == 50) x |= 2; // If you get a 1 in set relay #1
if (a == 51) x &= ~1; // If you get a 2 in clear relay #2
if (a == 52) x |= 1; // If you get a 3 in set relay #3
outb(x, BASEPORT);
usleep(100); // Wait 100 microseconds.
} while (a != EOF);
/* We don't need the ports anymore */
if (ioperm(BASEPORT, 1, 0)) {
fprintf(stderr,&quot;error closing ioperm\n&quot;);
exit(1);
}

exit(0);
}

 
As I knoow, COM ports are tipically for DOS and Windows. John Fill
1c.bmp


ivfmd@mail.md
 
I'm sorry, I didn't see the post when I logged back in and thought it might have been lost.

Please forgive the double posting.

I hope the more recent post is more clear.

Bo
 
Hi,

I don't think that will work. You could have a look into open command - it should be able to open the tty's(/dev/ttyS1 - com2) from where you can read or write.

You should look at the man pages(man open).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top