int main( int argc, char *argv[] ) { int used=0, NumRung; static int old_level ; bindtextdomain("linuxcnc", EMC2_PO_DIR); setlocale(LC_MESSAGES,""); setlocale(LC_CTYPE,""); textdomain("linuxcnc"); old_level = rtapi_get_msg_level(); compId=hal_init("classicladder"); //emc if (compId<0) return -1; //emc signal(SIGTERM,do_exit); //emc InitModbusMasterBeforeReadConf( ); if (ClassicLadder_AllocAll()) { char ProjectLoadedOk=TRUE; process_options (argc, argv); if (nogui==TRUE) { rtapi_print(_("INFO CLASSICLADDER- No ladder GUI requested-Realtime runs till HAL closes.\n")); ClassicLadder_InitAllDatas( ); ProjectLoadedOk = LoadProjectFiles( InfosGene->CurrentProjectFileName ); if (pathswitch){ strcpy( InfosGene->CurrentProjectFileName, NewPath ); } InfosGene->LadderState = STATE_RUN; ClassicLadder_FreeAll(TRUE); hal_ready(compId); hal_exit(compId); return 0; } else { for(NumRung=0;NumRung<NBR_RUNGS;NumRung++) { if ( RungArray[NumRung].Used ) used++; } if((used==0) || ( (argc - optind) != 0) ) { ClassicLadder_InitAllDatas( ); ProjectLoadedOk = LoadProjectFiles( InfosGene->CurrentProjectFileName ); InitGtkWindows( argc, argv ); UpdateAllGtkWindows(); if (pathswitch){ strcpy( InfosGene->CurrentProjectFileName, NewPath ); } UpdateWindowTitleWithProjectName( ); MessageInStatusBar( ProjectLoadedOk?_("Project loaded and running"):_("Project failed to load...")); if (!ProjectLoadedOk) { ClassicLadder_InitAllDatas( ); if (modmaster) { PrepareModbusMaster( ); } } }else{ InitGtkWindows( argc, argv ); UpdateAllGtkWindows(); if (pathswitch){ strcpy( InfosGene->CurrentProjectFileName, NewPath ); } UpdateWindowTitleWithProjectName( ); MessageInStatusBar(_("GUI reloaded with existing ladder program")); if (modmaster) { PrepareModbusMaster( ); } } if (modslave) { InitSocketServer( 0/*UseUdpMode*/, ModbusServerPort/*PortNbr*/); } InfosGene->LadderState = STATE_RUN; hal_ready(compId); gtk_main(); rtapi_print(_("INFO CLASSICLADDER- Ladder GUI closed. Realtime runs till HAL closes\n")); ClassicLadder_FreeAll(TRUE); hal_exit(compId); return 0; } } rtapi_print(_("ERROR CLASSICLADDER- Ladder memory allocation error\n")); ClassicLadder_FreeAll(TRUE); rtapi_set_msg_level(old_level); hal_exit(compId); return 0; }
int rtapi_app_main(void) { int result, i; CopySizesInfosFromModuleParams(); compId = hal_init("classicladder_rt"); if(compId < 0) return compId; rtapi_print("creating ladder-state\n"); result = hal_export_funct("classicladder.0.refresh",hal_task,0,1, 0, compId); if(result < 0) { error: hal_exit(compId); return result; } hal_state = hal_malloc(sizeof(hal_s32_t)); result = hal_param_s32_new("classicladder.ladder-state", HAL_RO, hal_state, compId); if(result < 0) { hal_exit(compId); return result; } hal_inputs = hal_malloc(sizeof(hal_bit_t*) * numPhysInputs); if(!hal_inputs) { result = -ENOMEM; goto error; } hide_gui = hal_malloc(sizeof(hal_bit_t*)); if(!hide_gui) { result = -ENOMEM; goto error; } hal_s32_inputs = hal_malloc(sizeof(hal_s32_t*) * numS32in); if(!hal_s32_inputs) { result = -ENOMEM; goto error; } hal_float_inputs = hal_malloc(sizeof(hal_float_t*) * numFloatIn); if(!hal_float_inputs) { result = -ENOMEM; goto error; } hal_outputs = hal_malloc(sizeof(hal_bit_t*) * numPhysOutputs); if(!hal_outputs) { result = -ENOMEM; goto error; } hal_s32_outputs = hal_malloc(sizeof(hal_s32_t*) * numS32out); if(!hal_s32_outputs) { result = -ENOMEM; goto error; } hal_float_outputs = hal_malloc(sizeof(hal_float_t*) * numFloatOut); if(!hal_float_outputs) { result = -ENOMEM; goto error; } for(i=0; i<numPhysInputs; i++) { result = hal_pin_bit_newf(HAL_IN, &hal_inputs[i], compId, "classicladder.0.in-%02d", i); if(result < 0) goto error; } result = hal_pin_bit_newf(HAL_IN, &hide_gui[0], compId, "classicladder.0.hide_gui"); if(result < 0) goto error; for(i=0; i<numS32in; i++) { result = hal_pin_s32_newf(HAL_IN, &hal_s32_inputs[i], compId, "classicladder.0.s32in-%02d", i); if(result < 0) goto error; } for(i=0; i<numFloatIn; i++) { result = hal_pin_float_newf(HAL_IN, &hal_float_inputs[i], compId, "classicladder.0.floatin-%02d", i); if(result < 0) goto error; } for(i=0; i<numPhysOutputs; i++) { result = hal_pin_bit_newf(HAL_OUT, &hal_outputs[i], compId, "classicladder.0.out-%02d", i); if(result < 0) goto error; } for(i=0; i<numS32out; i++) { result = hal_pin_s32_newf(HAL_OUT, &hal_s32_outputs[i], compId, "classicladder.0.s32out-%02d", i); if(result < 0) goto error; } for(i=0; i<numFloatOut; i++) { result = hal_pin_float_newf(HAL_OUT, &hal_float_outputs[i], compId, "classicladder.0.floatout-%02d", i); if(result < 0) goto error; } hal_ready(compId); ClassicLadder_AllocAll( ); return 0; }