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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C for Win32 vs C for Mandrake Linux

Status
Not open for further replies.

Bosah

MIS
Feb 9, 2001
39
CA
I have some C source Code to control a device under Windows. The device is a couple of relays that will start a buzzer at various times.

I'm told its very simple Turbo C but I doubt I can run it as is on a Linux Box. (This is true isnt it???)


#include <conio.h> #include <conio.h>
#include <dos.h>
#include <stdio.h>


main()

{
int a,x;

clrscr();
printf(&quot; AR-2 relay test program (com1)\n\n&quot;);
printf(&quot;(1) De-energize relay #1\n&quot;);
printf(&quot;(2) Energize relay #1\n&quot;);
printf(&quot;(3) De-energize relay #2\n&quot;);
printf(&quot;(4) Energize relay #2\n&quot;);
printf(&quot;(5) Exit to Dos\n\n&quot;);
printf(&quot;select function&quot;);

do

{
a=getch();
x=inportb(0x3FC);
if (a==49) x=x&~2;
if (a==50) x=x|2;
if (a==51) x=x&~1;
if (a==52) x=x|1;
outportb(0x3FC,x);
}
while (a!=53);
clrscr();
}


Can anyone suggest a way to write this in Linux to use ttyS1?



Bo

I know its a tall order, great thanks in advance.
 
Yes, you have to make some changes to your code. Take a look at ncurses to duplicate the behavior of getch() and clrscr() in conio.h and look at outb() and inb() for inportb() and outportb() in dos.h. For these latter two functions, make sure that you enable optimization on your compiler (for gcc -O2, -O3 etc.).

Russ
bobbitts@hotmail.com
 
Could I possibly do the same thing in a perl script????

I apologise but I dont think I understand the logic well enough to translate it into a working Linux script.

Any help much appreciated.

Bo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top