madsoft.c

来自「16 relay output channels and 16 isolated」· C语言 代码 · 共 1,682 行 · 第 1/5 页

C
1,682
字号
        dwPhyChan = usStartChan;
        for(i = 0; i < usNumChan; i++, dwPhyChan++)
        {
			if (DevCfg.ulChanConfig == 1)
			{
				if (dwPhyChan >= DevFeatures.usMaxAIDiffChl)
					break;
			}
			else
			{
				if (dwPhyChan >= DevFeatures.usMaxAISiglChl)
					break;
			}
			
            lvItem.iItem = i;
            lvItem.iSubItem = 0;
            wsprintf(szBuff, "Chan %d", dwPhyChan);
            ListView_InsertItem(hGainListWnd, &lvItem);
            lvItem.iSubItem = 1;
            wsprintf(szBuff, "%s", DevFeatures.glGainList[usGainIndex[PhyChanToLogChan(&DevCfg,dwPhyChan)]].szGainStr);

            ListView_SetItem(hGainListWnd, &lvItem);
            lvItem.iSubItem = 2;

			// If differential and single-ended can not combine,
			// If all channels are differential, DevCfg.ulChanConfig = 0x0001
			// If all channels are single-ended, DevCfg.ulChanConfig = 0x0000

			if (DevCfg.ulChanConfig == 1) // Can not combine and differential
			{
				wsprintf(szBuff, "%s", "Differential");
				wsprintf(szTmpBuff, "Chan %d",dwPhyChan);
				ListView_SetItemText(hGainListWnd,  i, 0, szTmpBuff);
			}
			else
			{
				if (dwPhyChan < 32)
				{  // The physical channel number between 0 and 31
					
					if (DevCfg.ulChanConfig & (1 << dwPhyChan))
					{
						wsprintf(szBuff, "%s", "Differential");
						if (dwPhyChan % 2 == 0)
						{
							dwPhyChan++;
						}
						wsprintf(szTmpBuff, "Chan %d,%d", dwPhyChan-1, dwPhyChan);
						ListView_SetItemText(hGainListWnd,  i, 0, szTmpBuff);
					}
					else
					{
						wsprintf(szBuff, "%s", "Single-Ended");
					}
				}
				else
				{  // The physical channel number between 32 and 63
					
					if (DevCfg.ulChanConfigEx[0] & (1 << (dwPhyChan-32)))
					{
						wsprintf(szBuff, "%s", "Differential");
						if (dwPhyChan % 2 == 0)
						{
							dwPhyChan++;
						}
						wsprintf(szTmpBuff, "Chan %d,%d", dwPhyChan-1, dwPhyChan);
						ListView_SetItemText(hGainListWnd,  i, 0, szTmpBuff);
					}
					else
					{
						wsprintf(szBuff, "%s", "Single-Ended");
					}
				}
			}


            ListView_SetItem(hGainListWnd, &lvItem);
        }

        // Step 6: Close device
        DRV_DeviceClose((LONG far *)&DriverHandle);

        return TRUE;

    case WM_COMMAND :
        switch (LOWORD(wParam))
        {
        case IDOK:
        case IDCANCEL:
            SetGain(GetParent(hDlg), TRUE);
            EndDialog(hDlg, 0);
            return TRUE;

        case IDC_CMB_GAIN :
            if (HIWORD(wParam) == CBN_CLOSEUP)
            {
                i = (int)SendDlgItemMessage(hDlg, LOWORD(wParam),
                    CB_GETCURSEL, 0, 0);
                if (i != CB_ERR)
                {
                    if (iPos>=0 && iPos<usNumChan)
                    {
                        usGainIndex[iPos+PhyChanToLogChan(&DevCfg,usStartChan)] = i;
                        lvItem.mask = LVIF_TEXT;
                        lvItem.pszText = szBuff;
                        lvItem.iItem = iPos;
                        lvItem.iSubItem = 1;
                        wsprintf(szBuff, "%s", DevFeatures.glGainList[i].szGainStr);
                        ListView_SetItem(GetDlgItem(hDlg, IDC_LST_GAIN), &lvItem);
                    }
                }
            }
            return TRUE;
        }

        break;

    case WM_NOTIFY:
        switch (LOWORD(wParam))
        {
        case IDC_LST_GAIN :
            lpnmhdr = (LPNMHDR) lParam;
            if (lpnmhdr->code == NM_CLICK)
            {
                lpnmitem = (LPNMITEMACTIVATE) lParam;
                iPos = lpnmitem->iItem;
                if (iPos>=0 && iPos<usNumChan)
                {
                    SendDlgItemMessage(hDlg, IDC_CMB_GAIN,
                        CB_SETCURSEL, usGainIndex[iPos + PhyChanToLogChan(&DevCfg,usStartChan)], 0);
                }
            }
            return TRUE;
        }
    }

    return FALSE;
}

/***************************************************************************
    FUNCTION: ConfigDlgProc(HWND, unsigned, WPARAM, LPARAM)

    PURPOSE:  Processes dialog box messages for configuration
****************************************************************************/

BOOL FTYPE ConfigDlgProc
(
    HWND        hDlg,                          // window handle
    unsigned    message,                       // type of message
    WPARAM      wParam,                        // additional information
    LPARAM      lParam                         // additional information
)
{
    USHORT      i;
    DWORD       dwIndex;
    int         nOutEntries;
    USHORT      usStopChan;
	USHORT   uMaxSingleChannel;  
	USHORT   uMaxDiffChannel;
	
    usStopChan = usStartChan + usNumChan - 1;

    switch (message)
    {
    case WM_INITDIALOG :

        // --------------------------------
        // Initialize Device List Combobox
        // --------------------------------

        // get number of the installed devices

        if ((ErrCde = DRV_DeviceGetNumOfList((SHORT far *)&gnNumOfDevices)) !=
            SUCCESS)
        {
             DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
             MessageBox(hMainWnd,(LPCSTR)szErrMsg, "Driver Message", MB_OK);
             return TRUE;
        }


        // ----------------------------------------------------------------
        // used for dynamic allocation memory for these installed devices
        //
        // if ((hDeviceList = GlobalAlloc(GHND, gnNumOfDevices *
        //      sizeof(DEVLIST))) == NULL)
        // {
        //    MessageBox(hMainWnd, (LPCSTR)"Not Enough Memory",
        //        "Memory Allocation", MB_OK);
        //    return TRUE;
        // }
        // DeviceList = (LPDEVLIST)GlobalLock(hDeviceList);
        // ----------------------------------------------------------------

        // initialize the number of channel       
        ultoa(usNumChan, szBuffer, 10);

        SendDlgItemMessage(hDlg, IDC_NUMCHAN, EM_REPLACESEL, 0,
            (LPARAM)((LPSTR)szBuffer));


        if (gnNumOfDevices > MAX_DEVICES)
            gnNumOfDevices = MAX_DEVICES;

        // retrieve the information of all installed devices

        if ((ErrCde = DRV_DeviceGetList((DEVLIST far *)&DeviceList[0],
            (SHORT)gnNumOfDevices, (SHORT far *)&nOutEntries)) != (LONG)SUCCESS)
        {
            DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
            MessageBox(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
            return TRUE;
        }

        // initialize the Device List Combobox with the retrieved information

        for (i = 0; i < (USHORT)gnNumOfDevices; i ++)
            SendDlgItemMessage(hDlg, IDC_DEVICE, CB_ADDSTRING, 0,
                        (LPARAM)((LPSTR)DeviceList[i].szDeviceName));

        SendDlgItemMessage(hDlg, IDC_DEVICE, CB_SETCURSEL,(WPARAM)gwDevice,
                        (LPARAM)0);


        // -----------------------------------------------------------
        // Initialize Module List Combobox for COM port or CAN devices
        // -----------------------------------------------------------

        // check if there is any device attached on this COM port or CAN

        gnNumOfSubdevices = DeviceList[gwDevice].nNumOfSubdevices;
        if (gnNumOfSubdevices > MAX_DEVICES)
            gnNumOfSubdevices = MAX_DEVICES;


        // --------------------------------------------------------------
        // used for dynamic allocation memory for these installed devices
        //
        // if ((hSubDeviceList = GlobalAlloc(GHND, gnNumOfSubdevices *
        //    sizeof(DEVLIST))) == NULL)
        // {
        //    MessageBox(hMainWnd, (LPCSTR)"Not Enough Memory",
        //        "Memory Allocation", MB_OK);
        //    return TRUE;
        // }
        //
        // SubDeviceList = (LPDEVLIST)GlobalLock(hSubDeviceList);
        // --------------------------------------------------------------

        // retrieve the information of all installed devices
        if (gnNumOfSubdevices != 0)
        {
            if ((ErrCde = DRV_DeviceGetSubList(
                (DWORD)DeviceList[gwDevice].dwDeviceNum,
                (DEVLIST far *)&SubDeviceList[0],
                (SHORT)gnNumOfSubdevices,
                (SHORT far *)&nOutEntries)) != (LONG)SUCCESS)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                MessageBox(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                return TRUE;
            }


            // initialize the Module List Combobox with the retrieved
            // information

            EnableWindow(GetDlgItem(hDlg, IDC_MODULE), TRUE);
            SendDlgItemMessage(hDlg, IDC_MODULE, CB_RESETCONTENT, 0,
                    (LPARAM)((LPSTR)0));

            for (i = 0; i < (USHORT)gnNumOfSubdevices; i++)
                SendDlgItemMessage(hDlg, IDC_MODULE, CB_ADDSTRING, 0,
                        (LPARAM)((LPSTR)SubDeviceList[i].szDeviceName));

            SendDlgItemMessage(hDlg, IDC_MODULE, CB_SETCURSEL,
					(WPARAM)gwSubDevice, (LPARAM)0);
        }
        else
        {
            EnableWindow(GetDlgItem(hDlg, IDC_MODULE), FALSE);
            SendDlgItemMessage(hDlg, IDC_MODULE, CB_RESETCONTENT, 0,
                    (LPARAM)((LPSTR)0));
        }

        // ------------------------------------------------------------
        // Initialize Input Range List Combobox, it needs to get device
        // features for gain list
        // ------------------------------------------------------------

        // first : Open Device

        if (gnNumOfSubdevices == 0)
        {
            ErrCde = DRV_DeviceOpen(DeviceList[gwDevice].dwDeviceNum,
               (LONG far *)&DriverHandle);
        }
        else
        {
            ErrCde = DRV_DeviceOpen(
                SubDeviceList[gwSubDevice].dwDeviceNum,
                (LONG far *)&DriverHandle);
        }

        if (ErrCde != SUCCESS)
        {
            strcpy(szErrMsg,"Device open error !");
            MessageBox(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
            return 0;
        }

        // second: get device features

        ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
        ptDevFeatures.size = sizeof(DEVFEATURES);
        if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
            (LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
        {
            DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
            MessageBox(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
            DRV_DeviceClose((LONG far *)&DriverHandle);
            return 0;
        }

        // Have AI function support ?
        if ((DevFeatures.usMaxAIDiffChl == 0) &&
            (DevFeatures.usMaxAISiglChl == 0))
            AllWindows(hDlg);
        else
        {
            ptAIGetConfig.buffer = (LPDEVCONFIG_AI)&DevCfg;
            ptAIGetConfig.size = sizeof(DEVCONFIG_AI);

            // call AIGetConfig
            if ((ErrCde = DRV_AIGetConfig(DriverHandle,
                (LPT_AIGetConfig)&ptAIGetConfig)) != SUCCESS)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);

⌨️ 快捷键说明

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