/** * Open a CAN port on a Copley CAN card. * * Parameters: * port The port number to open. Ports are numbered starting at zero. * There are two ports for each card, so if the system contains * N CAN cards, then legal port numbers range from 0 to 2*N-1. * * baud The baud rate to set the port to. This should be one of the * values defined in the CopleyCAN.h header file. * * error If an error occurs opening the card, an appropriate error code * will be returned here. This parameter may be passed as NULL * if no error information is desired. * * Returns: * A pointer to a local structure that should be passed to other functions. * NULL will be returned on failure. */ void *CopleyCanOpen( int port, int baud, int *error ) { int err = 0; void *lcl; uint32_t cmd[64]; // Allocate a structure to hold local data lcl = ccAllocLocals(); if( lcl == NULL ) { err = COPLEYCAN_ERR_ALLOC; goto done; } // Open a handle to the device driver err = ccOpenFile( port, lcl ); if( err ) goto freeLocals; // Set the port's baud rate cmd[0] = (CANCARD_CMD_SETBPS<<16) | 1; cmd[1] = baud; err = ccSendCMD( lcl, cmd ); if( err ) goto closeHandle; // Open the CAN port cmd[0] = (CANCARD_CMD_OPENPORT<<16); err = ccSendCMD( lcl, cmd ); if( err ) goto closeHandle; return lcl; closeHandle: ccCloseFile( lcl ); freeLocals: ccFreeLocals( lcl ); done: if( *error ) *error = err; return NULL; }
FILE *SrchPth2(char *name, char *path, char *attrib) { FILE *rv = SrchPth3(name, path, attrib); #ifdef PARSER_ONLY rv = ccOpenFile(name, rv, attrib); #endif #ifdef MSDOS char buf[256], *p; if (rv != - 1) return rv; p = strrchr(name, '.'); if (!p) p = name + strlen(name); if (p - name < 9) return rv; strcpy(buf, name); strcpy(buf + 6, "~1"); strcpy(buf + 8, p); rv = SrchPth3(buf, path, attrib); if (rv != - 1) { strcpy(name, buf); return rv; } strcpy(buf, name); strcpy(buf + 8, p); rv = SrchPth3(name, path, attrib); if (rv != - 1) { strcpy(name, buf); return rv; } return - 1; #else return rv; #endif }