/* ** Beeper() * * FILENAME: beep.c * * PARAMETERS: BeepMsg. Holds length of beep, [4:0] and number of * beeps, [7:5] * * DESCRIPTION: When BeepMsg != 0 then it splits the uint8 into the two * parameters needed and starts the beep sequence. * * RETURNS: Nothing. * */ void BeeperDevice() { switch (BeepState) { case BEEP_START : if (BeepMsg != 0) { // Set how long beeper is on and off. BeepTime = (BeepMsg & 0x1F) << 2; // times 4 for 40ms to 1.24 sec. // Set how many times we beep BeepRep = (BeepMsg & 0xE0) >> 5; StartBeep(); StartTimer( BEEP_TIMER, BeepTime ); BeepMsg = 0; BeepState = BEEP_OFF; } break; case BEEP_OFF : if (TimerDone( BEEP_TIMER ) ) { StopBeep(); BeepRep--; StartTimer( BEEP_TIMER, BeepTime ); BeepState = BEEP_ON; }; break; case BEEP_ON: if (TimerDone( BEEP_TIMER ) ) { if ( BeepRep != 0 ) { StartBeep(); StartTimer( BEEP_TIMER, BeepTime ); BeepState = BEEP_OFF; } else { BeepState = BEEP_START; // Beeping is done. } } break; default: BeepState = BEEP_START; break; }
/* ** InitBeeper() * * FILENAME: beep.c * * PARAMETERS: None * * DESCRIPTION: Turns off Beeper and sets up command variables for Beeper state machine. * * RETURNS: * */ void InitBeepDevice(void) { StopBeep(); BeepMsg = 0; BeepState = BEEP_START; }
void __cdecl mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *port, *value; int mrows, ncols, arg; /* Check for proper number of arguments. */ if (nrhs != 2) { mexErrMsgTxt("Two input arguments required."); } else if (nlhs > 0) { mexErrMsgTxt("Too many output arguments."); } /* The input must be noncomplex scalar double.*/ for (arg = 0; arg < 2; arg++) { mrows = mxGetM(prhs[arg]); ncols = mxGetN(prhs[arg]); if (!mxIsDouble(prhs[arg]) || mxIsComplex(prhs[arg]) || !(mrows == 1 && ncols == 1)) { mexErrMsgTxt("Input must be noncomplex scalar double."); } } /* Assign pointers to each input and output. */ port = mxGetData(prhs[0]); value = mxGetData(prhs[1]); OpenPortTalk(); outportb(*port, *value); ClosePortTalk(); /* This is where the new code begins */ //Dynamically load the DLL at runtime (not linked at compile time) HINSTANCE hInpOutDll; hInpOutDll = LoadLibrary("InpOutx64.DLL"); //The 32bit DLL. If we are building x64 C++ //applicaiton then use InpOutx64.dll if (hInpOutDll != NULL) { gfpOut32 = (lpOut32)GetProcAddress(hInpOutDll, "Out32"); gfpInp32 = (lpInp32)GetProcAddress(hInpOutDll, "Inp32"); gfpIsInpOutDriverOpen = (lpIsInpOutDriverOpen)GetProcAddress(hInpOutDll, "IsInpOutDriverOpen"); gfpIsXP64Bit = (lpIsXP64Bit)GetProcAddress(hInpOutDll, "IsXP64Bit"); if (gfpIsInpOutDriverOpen()) { //Make some noise through the PC Speaker - hey it can do more that a single beep using InpOut32 Beep(2000); Sleep(200); Beep(1000); Sleep(300); Beep(2000); Sleep(250); StopBeep(); if (!strcmp(argv[1], "read")) { short iPort = atoi(argv[2]); WORD wData = gfpInp32(iPort); //Read the port printf("Data read from address %s is %d \n\n\n\n", argv[2], wData); } else if (!strcmp(argv[1], "write")) { if (argc < 4) { printf("Error in arguments supplied"); printf("\n***** Usage *****\n\nInpoutTest read <ADDRESS> \nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n"); } else { short iPort = atoi(argv[2]); WORD wData = atoi(argv[3]); gfpOut32(iPort, wData); printf("data written to %s\n\n\n", argv[2]); } } } else { printf("Unable to open InpOut32 Driver!\n"); } //All done FreeLibrary(hInpOutDll); return 0; } else { printf("Unable to load InpOut32 DLL!\n"); return -1; } }