Ok, just checked again.
its NOT a serial cable...
it is a 15 pin connector/ribben cable.(same look as a serial just a bit bigger) Should work the same as a serial though. just more pins, right?
this will be so sweet if we can figure this out.
here is the code to the program I currently have. it works via user inputs from the keyboard.
Code:
#include <stdio.h>
#include <time.h>
//This is a seperate function that is called whenever the data is to be save to a file. It takes in as arguments the
//time that the current recording started (time since last save or the time since the start command was issued), the
//time that the current recording ended and time that was spent (in seconds) in the error state.
void print (time_t st, time_t end, double errortime);
char *dfname (time_t stime);
int main () {
//VARIABLE DECLARATIONS
time_t time1=0, time2=0,startdate,enddate;
double count=0;
int in=0;
char state='i';
printf("A $ will appear when program is waiting for next action.\nCommands\n========\n1)Start\t2)Error\t3)Error Fixed\t4)Write to File\t5)Quit");
while (in!=5){
printf("\n==================================================");
printf("\n$");
scanf("%d",&in);
if (in==1&& state=='i'){
printf("\nStart signal has been given. Start date has been recorded. \nNow in state:Run\n");
startdate=time(NULL);
state='r';
}
else if (in==1&&state!='i'){
printf("\nCan't \"Start\" unless current state is \"Idle\"\n");
printf("\nCurrent state is:");
if(state=='r')
printf("Run\n");
else if (state=='e')
printf("Error\n");
else printf("unknown\n");
}
if (in==2&& state=='r'){
time1=time(NULL);
state='e';
printf("\nError had been detected. Now in state:Error\n");
}
else if(in==2 && state!='r'){
printf("\nCan't have \"Error\" unless current state is \"Run\"\n");
printf("\nCurrent state is:");
if(state=='i')
printf("Idle\n");
else if (state=='e')
printf("Error\n");
else printf("unknown\n");
}
if (in==3&& state=='e'){
time2=time(NULL);
count=count+difftime(time2,time1);
state='r';
printf("\nError has been fixed. Back to state:Run\n");
}
else if (in==3&& state!='e'){
printf("\nCan't have \"Fixed Error\" unless current state is \"Error\"\n");
printf("\nCurrent state is:");
if(state=='r')
printf("Run\n");
else if (state=='i')
printf("Idle\n");
else printf("unknown\n");
}
if (in==4&&state=='r') {
printf("\n\nFile save command has been detected. End date has been stored.\nStart date will be reset.");
enddate=time(NULL);
print(startdate,enddate,count);
count=0;
startdate=time(NULL);
}
else if (in==4&&state!='r'){
printf("\n\nCan't save data unless state is run. Fix errors or start program running.");
}
printf("\n==================================================");
}
printf("\n==================================================");
if (state=='e'){
time2=time(NULL);
count=count+difftime(time2,time1);
}
printf("\nQuit signal has been received. End date has been recorded.\nTotal error time will be calculated.");
enddate=time(NULL);
print(startdate,enddate,count);
printf("\n==================================================");
return 0;
}
void print (time_t st, time_t end, double errortime){
double elapsed;
char filename[30],*temp;
int i=0,j=0;
FILE *userfile;
char *sdate,*edate;
struct tm savetime;
elapsed=difftime(end,st);
edate=ctime(&end);
while (*(edate+i)!='\n'){
if(*(edate+i)!=' '&&*(edate+i)!=':'){
filename[j]=*(edate+i);
j++;
}
i++;
}
filename[j]='.';
filename[j+1]='t';
filename[j+2]='x';
filename[j+3]='t';
filename[j+4]='\0';
userfile=fopen(filename,"w");
if(userfile){
printf("\nFile is being written to the default filename:%s",filename);
fprintf(userfile, "\n\nTime Saved\n==========\n%s",edate);
sdate=ctime(&st);
fprintf(userfile, "Time Started\n============\n%s",sdate);
fprintf(userfile, "\n\nTime Elapsed\n============\n%.0lf",elapsed);
fprintf(userfile, "\n\nError Time\n==========\n%.0lf",errortime);
}
else{
printf("\n\nFile has not been successfully created.");
}
fclose(userfile);
}