00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022
00023
00024 #include "emc.hh"
00025 #include "emcmot.h"
00026 #include "usrmotintf.h"
00027 #include "initraj.hh"
00028 #include "iniaxis.hh"
00029 #include "emcglb.h"
00030 #include "emcmotglb.h"
00031 #include "emcmotcfg.h"
00032
00033
00034 static EMC_STAT emcStatusStruct;
00035 EMC_STAT * emcStatus = 0;
00036
00037
00038 int emcOperatorError(int id, const char *fmt, ...)
00039 {
00040 char errorString[EMC_OPERATOR_ERROR_LEN];
00041 va_list ap;
00042
00043
00044 sprintf(errorString, "[%d] ", id);
00045
00046
00047 va_start(ap, fmt);
00048 vsprintf(&errorString[strlen(errorString)], fmt, ap);
00049 va_end(ap);
00050
00051
00052 errorString[EMC_OPERATOR_ERROR_LEN-1] = 0;
00053
00054
00055 printf("%s\n", errorString);
00056
00057 return 0;
00058 }
00059
00060 static int numAxes = 0;
00061 #define DEFAULT_NUM_AXES 3 // how many to try if it's not in ini file
00062
00063 static int iniLoad(const char *filename)
00064 {
00065 INIFILE inifile;
00066 const char *inistring;
00067
00068
00069 if (-1 == inifile.open(filename)) {
00070 return -1;
00071 }
00072
00073 if (NULL != (inistring = inifile.find("AXES", "TRAJ"))) {
00074 if (1 != sscanf(inistring, "%d", &numAxes)) {
00075 numAxes = DEFAULT_NUM_AXES;
00076 }
00077 }
00078 else {
00079
00080 numAxes = DEFAULT_NUM_AXES;
00081 }
00082
00083
00084 inifile.close();
00085
00086 return 0;
00087 }
00088
00089 int main(int argc, char *argv[])
00090 {
00091 int retval = 0;
00092 int axis;
00093
00094 emcStatus = &emcStatusStruct;
00095
00096
00097 if (0 != emcGetArgs(argc, argv))
00098 {
00099 printf("error in argument list\n");
00100 exit(1);
00101 }
00102
00103
00104 if (0 != iniLoad(EMC_INIFILE)) {
00105 printf("can't read INI file\n");
00106 exit(1);
00107 }
00108
00109
00110 if (0 != usrmotIniLoad(EMC_INIFILE)) {
00111 printf("can't read motion control INI file\n");
00112 exit(1);
00113 }
00114
00115 if (0 != usrmotInit()) {
00116 printf("can't initialize motion control interface\n");
00117 exit(1);
00118 }
00119
00120 for (axis = 0; axis < numAxes; axis++) {
00121 printf("initing axis %d...", axis);
00122 fflush(stdout);
00123 if (0 == iniAxis(axis, EMC_INIFILE)) {
00124 printf("done\n");
00125 }
00126 else {
00127 printf("error\n");
00128 retval = 1;
00129 }
00130 }
00131
00132
00133 printf("initing traj...");
00134 fflush(stdout);
00135 if (0 == iniTraj(EMC_INIFILE)) {
00136 printf("done\n");
00137 }
00138 else {
00139 printf("error\n");
00140 retval = 1;
00141 }
00142
00143 usrmotExit();
00144
00145 exit(retval);
00146 }