The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-15-2002
killerserv's Avatar
killerserv killerserv is offline Forum Advisor  
Unix Predator
  
 

Join Date: Dec 2000
Location: Phoenix, AZ
Posts: 670
You can try to declare main with arguments;

int main(int argc, char *argv[])

This program was used in an application, where a PC was controlling critical tasks. Lets call it PC_critical. Unfortunately, PC_critical occasionally stalled and had to be manually reset.

Thus, a second PC (PC_monitor) was used. PC_critical was to send a message to PC_monitor every five minutes to assure that it was "alive". If no message was received, PC_monitor forced a hard reset of PC_critical by applying a momentary relay closure across the manual reset switch on PC_critical. The operation of the relay was caused by outputting the pattern 0x0a on the Data Port.

You can try this as an example.

Code:

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

int main(int argc, char *argv[])
{
   unsigned int t_delay, Data;
   int tenths_sec;

   clrscr();

   if(argc != 3)
   {
      printf("Incorrect number of args\n");
      exit(-1);
   }
   if(sscanf(argv[1],"%d", &tenths_sec)!=1)
   {
      printf("Time scanf failed.\n");
      exit(-2);
   }
   if (sscanf(argv[2],"%x", &Data) != 1)
   {
      printf("Parallel port scanf failed.\n");
      exit(-3);
   }
   t_delay = tenths_sec * 100;
   outportb(Data, 0x0a); /* operate the relay */
   delay(t_delay);
   outportb(Data, 0x00); /* release it */
   exit(0);
}