⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iocontrol.cc

📁 CNC 的开放码,EMC2 V2.2.8版
💻 CC
📖 第 1 页 / 共 3 页
字号:
    return 0;}/********************************************************************** Description: saveToolTable(const char *filename, CANON_TOOL_TABLE toolTable[])*		Saves the tool table from toolTable[] array into file filename.*		  Array is CANON_TOOL_MAX + 1 entries, since 0 is included.** Return Value: Zero on success or -1 if file not found.** Side Effects: Default setting used if the parameter not found in*		the ini file.** Called By: main()*********************************************************************/static int saveToolTable(const char *filename,			 CANON_TOOL_TABLE toolTable[]){    int pocket;    FILE *fp;    const char *name;    fprintf(stderr,"I thought saveToolTable wasn't used.  Please report.\n");    return 0;    // check filename    if (filename[0] == 0) {	name = TOOL_TABLE_FILE;    } else {	// point to name provided	name = filename;    }    // open tool table file    if (NULL == (fp = fopen(name, "w"))) {	// can't open file	return -1;    }    // write header    fprintf(fp, "POC\tFMS\tLEN\t\tDIAM\n");    for (pocket = 1; pocket <= CANON_TOOL_MAX; pocket++) {	fprintf(fp, "%d\t%d\t%f\t%f\n",		pocket,		toolTable[pocket].id,		toolTable[pocket].zoffset, toolTable[pocket].diameter);    }    // close the file    fclose(fp);    return 0;}static int done = 0;/********************************************************************** Description: quit(int sig)*		Signal handler for SIGINT - Usually generated by a*		Ctrl C sequence from the keyboard.** Return Value: None.** Side Effects: Sets the termination condition of the main while loop.** Called By: Operating system.*********************************************************************/static void quit(int sig){    done = 1;}/********************************************************************** Description: iocontrol_hal_init(void)** Side Effects: Exports HAL pins.** Called By: main********************************************************************/int iocontrol_hal_init(void){    char name[HAL_NAME_LEN + 2];	//name of the pin to be registered    int n = 0, retval;		//n - number of the hal component (only one for iocotrol)    /* STEP 1: initialise the hal component */    comp_id = hal_init("iocontrol");    if (comp_id < 0) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: hal_init() failed\n");	return -1;    }    /* STEP 2: allocate shared memory for iocontrol data */    iocontrol_data = (iocontrol_str *) hal_malloc(sizeof(iocontrol_str));    if (iocontrol_data == 0) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: hal_malloc() failed\n");	hal_exit(comp_id);	return -1;    }    /* STEP 3a: export the out-pin(s) */    // user-enable-out    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.user-enable-out", n);    retval =	hal_pin_bit_new(name, HAL_OUT, &(iocontrol_data->user_enable_out), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin user-enable-out export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // user-request-enable    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.user-request-enable", n);    retval =	hal_pin_bit_new(name, HAL_OUT, &(iocontrol_data->user_request_enable), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin user-request-enable export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // coolant-flood    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.coolant-flood", n);    retval =	hal_pin_bit_new(name, HAL_OUT, &(iocontrol_data->coolant_flood),	comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin coolant-flood export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // coolant-mist    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.coolant-mist", n);    retval =	hal_pin_bit_new(name, HAL_OUT, &(iocontrol_data->coolant_mist),			comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin coolant-mist export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // lube    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.lube", n);    retval =	hal_pin_bit_new(name, HAL_OUT, &(iocontrol_data->lube), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin lube export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // tool-prepare    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.tool-prepare", n);    retval =	hal_pin_bit_new(name, HAL_OUT, &(iocontrol_data->tool_prepare), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin tool-prepare export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // tool-number    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.tool-number", n);    retval =	hal_pin_s32_new(name, HAL_OUT, &(iocontrol_data->tool_number), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin tool-number export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // tool-prep-number    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.tool-prep-number", n);    retval =	hal_pin_s32_new(name, HAL_OUT, &(iocontrol_data->tool_prep_number), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin tool-prep-number export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // tool-prepared    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.tool-prepared", n);    retval =	hal_pin_bit_new(name, HAL_IN, &(iocontrol_data->tool_prepared), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin tool-prepared export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // tool-change    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.tool-change", n);    retval =	hal_pin_bit_new(name, HAL_OUT, &(iocontrol_data->tool_change), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin tool-change export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // tool-changed    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.tool-changed", n);    retval =	hal_pin_bit_new(name, HAL_IN, &(iocontrol_data->tool_changed), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin tool-changed export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    /* STEP 3b: export the in-pin(s) */    // emc-enable-in    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.emc-enable-in", n);    retval =	hal_pin_bit_new(name, HAL_IN, &(iocontrol_data->emc_enable_in), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin emc-enable-in export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    // lube_level    rtapi_snprintf(name, HAL_NAME_LEN, "iocontrol.%d.lube_level", n);    retval =	hal_pin_bit_new(name, HAL_IN, &(iocontrol_data->lube_level), comp_id);    if (retval != HAL_SUCCESS) {	rtapi_print_msg(RTAPI_MSG_ERR,			"IOCONTROL: ERROR: iocontrol %d pin lube_level export failed with err=%i\n",			n, retval);	hal_exit(comp_id);	return -1;    }    hal_ready(comp_id);    return 0;}/********************************************************************** Description: hal_init_pins(void)** Side Effects: Sets HAL pins default values.** Called By: main********************************************************************/void hal_init_pins(void){    *(iocontrol_data->user_enable_out)=0;	/* output, FALSE when EMC wants stop */    *(iocontrol_data->user_request_enable)=0;	/* output, used to reset HAL latch */    *(iocontrol_data->coolant_mist)=0;		/* coolant mist output pin */    *(iocontrol_data->coolant_flood)=0;		/* coolant flood output pin */    *(iocontrol_data->lube)=0;			/* lube output pin */    *(iocontrol_data->tool_prepare)=0;		/* output, pin that notifies HAL it needs to prepare a tool */    *(iocontrol_data->tool_prep_number)=0;	/* output, pin that holds the tool number to be prepared, only valid when tool-prepare=TRUE */    *(iocontrol_data->tool_change)=0;		/* output, notifies a tool-change should happen (emc should be in the tool-change position) */}/********************************************************************** Description: read_hal_inputs(void)*			Reads the pin values from HAL *			this function gets called once per cycle*			It sets the values for the emcioStatus.aux.*** Returns:	returns > 0 if any of the status has changed*		we then need to update through NML** Side Effects: updates values** Called By: main every CYCLE********************************************************************/int read_hal_inputs(void){    int oldval, retval = 0;    oldval = emcioStatus.aux.estop;    if ( *(iocontrol_data->emc_enable_in)==0) //check for estop from HW	emcioStatus.aux.estop = 1;    else	emcioStatus.aux.estop = 0;        if (oldval != emcioStatus.aux.estop) {	retval = 1;    }            oldval = emcioStatus.lube.level;    emcioStatus.lube.level = *(iocontrol_data->lube_level);	//check for lube_level from HW    if (oldval != emcioStatus.lube.level) {	retval = 1;    }    return retval;}/********************************************************************** Description: read_tool_inputs(void)*			Reads the tool-pin values from HAL *			this function gets called once per cycle*			It sets the values for the emcioStatus.aux.*** Returns:	returns which of the status has changed*		we then need to update through NML (a bit different as read_hal_inputs)** Side Effects: updates values** Called By: main every CYCLE********************************************************************/int read_tool_inputs(void){    if (*iocontrol_data->tool_prepare && *iocontrol_data->tool_prepared) {	emcioStatus.tool.toolPrepped = *(iocontrol_data->tool_prep_number); //check if tool has been prepared	*(iocontrol_data->tool_prepare) = 0;	emcioStatus.status = RCS_DONE;  // we finally finished to do tool-changing, signal task with RCS_DONE	return 10; //prepped finished    }        if (*iocontrol_data->tool_change && *iocontrol_data->tool_changed) {	emcioStatus.tool.toolInSpindle = emcioStatus.tool.toolPrepped; //the tool now in the spindle is the one that was prepared	*(iocontrol_data->tool_number) = emcioStatus.tool.toolInSpindle; //likewise in HAL	emcioStatus.tool.toolPrepped = -1; //reset the tool preped number, -1 to permit tool 0 to be loaded	*(iocontrol_data->tool_prep_number) = 0; //likewise in HAL	*(iocontrol_data->tool_change) = 0; //also reset the tool change signal	emcioStatus.status = RCS_DONE;	// we finally finished to do tool-changing, signal task with RCS_DONE	return 11; //change finished    }    return 0;}static void do_hal_exit(void) {    hal_exit(comp_id);}/********************************************************************** Description: main(int argc, char * argv[])*		Connects to NML buffers and enters an endless loop*		processing NML IO commands. Print statements are*		sent to the console indicating which IO command was

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -