Hello to all,
I am new to C and am learning on a daily basis. The code below will return a weight from a scales and output the result to a file. The program will only exit from a keyboard execution (Esc key). Is it possible to time out the program after a specified time (eg 5 seconds). Any pointers would be greatly appreciated.
Code:
#include <bios.h>
#include <stdio.h>
#include <conio.h>
#define COM1 0
#define DATA_READY 0x100
#define TRUE 1
#define FALSE 0
#define SETTINGS ( 0xE0 | 0x18 | 0x04 | 0x02)
/* MODE COM 9600 EVEN 2 7 */
int main(void)
{
int status, DONE = FALSE,flag=0,j=0,n;
char rname[10000],in,out;
FILE *fp=NULL;
bioscom(0, SETTINGS, COM1);
cprintf("... BIOSCOM [ESC] to exit .../n");
fp=fopen("c:\\myfile.txt","w");
while (flag!=1 || out=='$')
{
status = bioscom(3, 0, COM1);
status = status & DATA_READY;
if (status & DATA_READY)
/*if (status!=0)*/
{
out = bioscom(2, 0, COM1);
out = (out & 0x007f);
if(out!='$')
{
printf("%c",out);
rname[j]=out;
j++;
}
}
if (kbhit())
{
if ((in = getch()) == 27)
flag = 1;
}
}
n=j;
for(j=0;j<n;j++)
{
fputc(rname[j],fp);
}
fclose(fp);
return 0;
}