/* ************************************************************** */ /* * Module EV-16P * This module contains I/O functions for the Mitutoyo EV Counter * * Yurii Levashov * 01/07/2005 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "ev16p.h" #include //#include "ev16p_ui.h" /* ************************************************************** */ /* PRIVATE DEVICE TABLE */ /* * This table allows several devices of the same type to be * used in the system. * dev_addr, contains the rs232 addresses of opened devices * dev_descr, contains the device descriptors of opened devices * dev_count, contains the number of devices open of this type */ static int dev_addr[EV16P_MAX_NUM_DEV + 1]; static int dev_descr[EV16P_MAX_NUM_DEV + 1]; static int dev_count; /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ /* * cmd, buffer for RS232 I/O strings * msg, buffer for message strings to Standard I/O */ static int com_port; char cmd[EV16P_MAX_CMD + 1]; char msg[EV16P_MAX_CMD + 1]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ev16p_error_handling * * This function inform operator about error and error codes * Returns 0 - OK; -1 - Error * * Yurii Levashov * 01/07/2005 */ int ev16p_error_handling(int err, char descr[]) { char msg[200]; Fmt(msg, "%s 32) { err = ev16p_error_handling(rs232_com_port, "RS232_COM_PORT"); if(err != 0) return; } if(rs232_dev_addr < 0 || rs232_dev_addr > 99) { err = ev16p_error_handling(rs232_dev_addr, "RS232_DEV_ADDR"); if(err != 0) return; } // Exit here if testing without hardware #ifdef DUMMY_DEVICES *ID = 1; return; #endif /* Save the com port number */ com_port = rs232_com_port; /* Open Device */ dev_ID = ev16p_open_dev(rs232_dev_addr); /* Open RS232 communications */ err = OpenComConfig (com_port, "", 9600, 0, 7, 2, 512, 512); if (err != 0) err = ev16p_error_handling(err, "OpenCom"); if(err != 0) return; err = FlushInQ(com_port); if (err != 0) err = ev16p_error_handling(err, "FlushInQ"); if(err != 0) return; err = FlushOutQ(com_port); if (err != 0) err = ev16p_error_handling(err, "FlushOutQ"); if(err != 0) return; /* Clear Errors */ ev16p_clear_err(dev_ID); /* Check HOLD status of each used gage */ for(i = 1; i <= EV16P_NUM_GAGES; i++) { Fmt(cmd,"%s%s[w4]%i[w1]", cmd, &err); if(err == 1) { err = ConfirmPopup ("Warning", "Counter is not in HOLD state. RS232 commands are not effective. Would you like to set I/O to RS232?"); if(err == 1) MessagePopup ("Change HOLD Mode", "HOLD mode should be changed manually, p.3-7"); } else if(err != 0) { err = ev16p_error_handling(err, "Problem with Hold Mode"); return; } } /* Return the ID number */ *ID = dev_ID; /* Done */ return; } /* ************************************************************** */ /* * ev16p_zero * This function sets the gages readings to zero. * * Input: * dev_ID, device identifier * number of gage to be zeroed. For all gage = 0 * * Yurii Levashov * 01/07/2005 */ void ev16p_zero(int dev_ID, int gage) { /* Declare variables */ int err, i; int dev_open; int num_gages = EV16P_NUM_GAGES; /* Check input parameters */ if (dev_ID < 1 || dev_ID > EV16P_MAX_NUM_DEV) { Fmt(msg, "%s 6) { Fmt(msg, "%s EV16P_MAX_NUM_DEV) { Fmt(msg, "%s 6) { Fmt(msg, "%s%f", &result); // readings + i - 1); if(n == 1) return result; } while(count++ < 1); return(ev16p_error_handling(err, "Reading gages")); // } // output data on GUI /* switch(gage) { case 1: err = SetCtrlAttribute (PANEL, PANEL_GAGE1_OUT, ATTR_CTRL_VAL, dum/1000.); break; case 2: err = SetCtrlAttribute (PANEL, PANEL_GAGE2_OUT, ATTR_CTRL_VAL, readings[1]); break; case 3: err = SetCtrlAttribute (PANEL, PANEL_GAGE3_OUT, ATTR_CTRL_VAL, readings[2]); break; case 4: err = SetCtrlAttribute (PANEL, PANEL_GAGE4_OUT, ATTR_CTRL_VAL, readings[3]); break; default: err = SetCtrlAttribute (PANEL, PANEL_GAGE1_OUT, ATTR_CTRL_VAL, readings[0]); err = SetCtrlAttribute (PANEL, PANEL_GAGE2_OUT, ATTR_CTRL_VAL, readings[1]); err = SetCtrlAttribute (PANEL, PANEL_GAGE3_OUT, ATTR_CTRL_VAL, readings[2]); err = SetCtrlAttribute (PANEL, PANEL_GAGE4_OUT, ATTR_CTRL_VAL, readings[3]); } */ /* Done */ // return e; } /* ************************************************************** */ /* * ev16p_preset * This function presets the gages readings. * * Input: * dev_ID, device identifier * number of gage to be preset. For all gages = 0 * * Yurii Levashov * 01/07/2005 */ void ev16p_preset(int dev_ID, int gage, double readings[]) { /* Declare variables */ int err, i; int dev_open; int num_gages = EV16P_NUM_GAGES; char sign = '+'; double number; /* Check input parameters */ if (dev_ID < 1 || dev_ID > EV16P_MAX_NUM_DEV) { Fmt(msg, "%s 6) { Fmt(msg, "%s EV16P_MAX_NUM_DEV) { Fmt(msg, "%s EV16P_MAX_NUM_DEV) { Fmt(msg, "%s%s[t-]", buf); /* Return the string in buf */ // strcpy(buf, in_buf); /* Done */ return 0; } /* ************************************************************** */ /* * ev16p_check_dev_open * This function checks to see if the specified device is open. * If the device has been opened, a 1 is returned, 0 otherwise. * * Input: * dev_ID, device identifier * * Output: * status, 1 if device is open, 0 otherwise * * Zachary Wolf Modified by Yurii Levashov 01/07/2005 * 7/27/98 */ int ev16p_check_dev_open(int dev_ID) { /* See if the device descriptor has a positive value */ if (dev_descr[dev_ID] > 0) { return 1; /* Open */ } else { return 0; /* Not open */ } }