Hello Kyle,
Thank you for your answer. I looked through the Continuous Change Detection Example and it seems that it does what I want to do, but my device does not support the DIG_Block_PG_Config function. My device is a Lab-PC 1200 DAQ, programming using Visual C++ 6 on Windows 95, and Ni-daq version 5.1. Hardware settings are all correct and working.
I have attached the project code as a zip file and the main code here.
Thank you very much,
Rion
/*==============CODE START================
This program runs and monitors the digital line (PortA, bit 4 (bit 1 = LSB)).
When the digital line is logical high, the program increments the variable count2
by 1 and displays the value of count2 in an edit box.
count1 is used to count the number of times the DIG_Block_In function has been
called and completed.
This program is used to test the event messaging function of Ni-DAQ. This program
must not use any "while" loop and relies on the callback functions to work. The
idea of the callback event messaging of this program will be used in a software
that controls a machine and monitors a status signal from the machine.
*/
#include
#include "nidaqcns.h"
#include "nidaq.h"
#include "nidaqex.h"
#include "resource.h"
HINSTANCE hInst;
// Device number for the LabPC DAQ Card
#define DEVICE_NUM 1
// Number of scans for digital block in
#define NUM_DI_SCAN 20
int count1 = 0;
int count2 = 0;
// Callback function for updating the count2 variable
void Update2CB(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam)
{
count2++;
// Display the value of count2 in an edit box
SetDlgItemInt(handle, IDC_ALG_1, count2, TRUE);
}
// Check digital input callback function
void CheckDigCB(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam)
{
i16 grp0data[NUM_DI_SCAN];
int status;
count1++;
// Display count1 in an edit box
SetDlgItemInt(handle, IDC_ALG_0, count1, TRUE);
// Clear the block transfer
status = DIG_Block_Clear(DEVICE_NUM, 1);
// Start asynchronous block transfer operation
status = DIG_Block_In(DEVICE_NUM, 1, grp0data, NUM_DI_SCAN);
}
// Setup the event messages
void SetupDigCallback(HWND hwnd)
{
i16 grp0data[NUM_DI_SCAN];
int status;
i16 devNum;
i16 portList[] = {0};
Init_DA_Brds(DEVICE_NUM, &devNum);
Config_DAQ_Event_Message(DEVICE_NUM, 0, "", 0, 0, 0, 0, 0, 0, 0, 0, NULL);
// Set DAQ to interrupt driven
Set_DAQ_Device_Info(DEVICE_NUM, ND_DATA_XFER_MODE_DIO_GR1, ND_INTERRUPTS);
// Setup digital group
status = DIG_SCAN_Setup(DEVICE_NUM, 1, 1, portList, 0);
status = Config_DAQ_Event_Message(DEVICE_NUM, 1, "DI0", 1, NUM_DI_SCAN, 0, 0, 0, 0, hwnd, 0, (ULONG)&CheckDigCB);
// Setup event to detect change of digital port 0, bit 4
status = Config_DAQ_Event_Message(DEVICE_NUM, 1, "DI0", 8, 0, 0, 0, 0, 0, hwnd, 0, (ULONG)&Update2CB);
// Start asynchronous operation
status = DIG_Block_In(DEVICE_NUM, 1, grp0data, NUM_DI_SCAN);
}
// Clear the event message
void ReleaseDigCallback(HWND hwnd)
{
// Clear block
DIG_Block_Clear(DEVICE_NUM, 1);
// Release group
DIG_SCAN_Setup(DEVICE_NUM, 0, 0, 0, 0);
// Clear all messages
Config_DAQ_Event_Message(DEVICE_NUM, 0, "", 0, 0, 0, 0, 0, 0, 0, 0, NULL);
}
// Main message handler for the main application dialog box
BOOL CALLBACK MainDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
// Monitor the digital line until the user pressed the close button
SetupDigCallback(hdlg);
return TRUE;
case WM_CLOSE:
ReleaseDigCallback(hdlg);
EndDialog(hdlg, 0);
return TRUE;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
hInst = hInstance;
DialogBox(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)MainDlgProc);
return 0;
}