⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udconfig.c

📁 工业组态软件modbus驱动源代码, 包括帮助文件.共享.
💻 C
📖 第 1 页 / 共 5 页
字号:
    DialogBoxParam(  hInst,
                "TOPIC_DEF",
                hWnd,
                lpprocConfig,
                bModifyAllowed);
#ifndef WIN32
    FreeProcInstance(lpprocConfig);
#endif
} /* ConfigTopicCfg */

/*************************************************************************
 * End of callbacks for TOPIC configuration                              *
 *************************************************************************/

/***********************************************************************/
/** Handle dialog for TOPIC configuration **/

BOOL
WINAPI
TopicDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    BOOL            ok;
    char            topicName[33];
    LPTOPIC_CFG     lpTopicCfg;
    int             iChannelType;
    int             iComboBoxSelectionNumber;
    int             iMsgId;
    int             L;
    char            boardName[33];
    LPBOARD_CFG     lpBoardCfg;
    CHAINSCANNER    board_scanner;

    switch (message) {


    case WM_INITDIALOG:
        WWCenterDialog( hDlg );

        if (lpTopicCfgToEdit == (LPTOPIC_CFG) NULL) {
            lpTopicCfgToEdit = TopicCfgAlloc();
            newTopicEntry = TRUE;
        } else {
            newTopicEntry = FALSE;
        }
        if (lpTopicCfgToEdit == (LPTOPIC_CFG) NULL) {
            EndDialog(hDlg, 0);
            return FALSE;
        }
        lpTopicCfg = lpTopicCfgToEdit;

        InitChannelNameComboBox(hDlg);

        dwEditChannelID = lpTopicCfg->tc_channelID;
        iChannelType = GetChannelType (dwEditChannelID);
        if (iChannelType == COMPORT_CHANNEL_TYPE)
        {
            /* ComPort channel, ensure valid or none selected */
            if( dwEditChannelID > MAX_COMPORT) {
                dwEditChannelID = 0;
            }
            /* get combo box selection index (-1 == none) */
            iComboBoxSelectionNumber = (int) dwEditChannelID - 1;
        }
        else
        {
            /* board channel, ensure valid or not selected */
            if( !dwEditChannelID ) {
                /* no, select the first one in the list, if any */
                lpBoardCfg = (LPBOARD_CFG) FindFirstItem (&BoardCfgList, SCAN_FROM_HEAD,
                                                          NULL, NULL, &board_scanner);
                /* get corresponding channel ID, if found */
                if (lpBoardCfg)
                    dwEditChannelID = BoardCfgGetID(lpBoardCfg);
            } else {
                /* yes, get pointer to corresponding board config structure */
                lpBoardCfg = BoardCfgFromID( dwEditChannelID );
                if (!lpBoardCfg)
                    /* no such board, force to not selected */
                    dwEditChannelID = 0;
            }
            /* get combo box selection index (-1 == none) */
            if ((dwEditChannelID > 0) && (dwEditChannelID >= MIN_BOARD_CHANNEL_ID))
            {
                iComboBoxSelectionNumber = (int) (dwEditChannelID - MIN_BOARD_CHANNEL_ID);
                if (bUsesComPorts)
                    /* offset index past the Com Ports */
                    iComboBoxSelectionNumber += MAX_COMPORT;
            }
            else
            {
                /* indicate none selected */
                iComboBoxSelectionNumber = -1;
            }
        }

        if ((iChannelType == COMPORT_CHANNEL_TYPE) ||
            (iComboBoxSelectionNumber < 0))
        {
            /* select item by index */
            SendMessage (GetDlgItem(hDlg, CI_CHANNEL_NAME_LIST),
                         CB_SETCURSEL, (WPARAM)(iComboBoxSelectionNumber), (LPARAM)0 );
        }
        else
        {
            /* select item by name */
            BoardCfgGetName(lpBoardCfg, boardName);
            SendMessage (GetDlgItem(hDlg, CI_CHANNEL_NAME_LIST),
                         CB_SELECTSTRING, (WPARAM)-1, (LPARAM)(LPSTR)boardName);
        }

        /* disable OK button if modification privilege not enabled */
        EnableWindow(GetDlgItem(hDlg, IDOK), (BOOL)lParam);

        /* Initialize the dialog edits and controls for this topic */
        SetDlgItemText(hDlg, CI_TOPIC_NAME, lpTopicCfg->tc_name);
        SendMessage(GetDlgItem(hDlg, CI_TOPIC_NAME), EM_LIMITTEXT, 32, 0);
        SetDlgItemInt(hDlg, CI_TOPIC_ADDR, lpTopicCfg->tc_topicAddress, FALSE);
        SetDlgItemInt(hDlg, CI_COIL_READ_SIZE,
                      lpTopicCfg->tc_coilReadSize, FALSE);
        SetDlgItemInt(hDlg, CI_REG_READ_SIZE,
                      lpTopicCfg->tc_regReadSize, FALSE);
        PutIntg(hDlg, CI_UPDATE_INTERVAL, lpTopicCfg->tc_updateInterval);

        /* toolkit portable EM_SETSEL - deals with Win16, Win32 differences */
        PfnSendEmSelectAll( hDlg, CI_TOPIC_NAME, TRUE );
        SetFocus(GetDlgItem(hDlg, CI_TOPIC_NAME));

        return (FALSE);
        break;


    case WM_COMMAND:
        switch (LOWORD(wParam)) {

        case CI_CHANNEL_NAME_LIST:     /* I/O channel combo box */
#ifdef WIN32
            if (HIWORD(wParam) == CBN_SELCHANGE)
#else
            if (HIWORD(lParam) == CBN_SELCHANGE)
#endif
            {
                iComboBoxSelectionNumber =
                    (int)SendMessage (GetDlgItem(hDlg, CI_CHANNEL_NAME_LIST),
                            CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
                if( iComboBoxSelectionNumber == CB_ERR )  {
                    /* error, indicate nothing selected */
                    dwEditChannelID = 0;
                }
                else
                {
                    /* get selected channel ID */
                    dwEditChannelID = iComboBoxSelectionNumber + 1;
                    iChannelType = GetChannelType (dwEditChannelID);
                    if (iChannelType == BOARD_CHANNEL_TYPE)
                    {
                        /* Board channel, get board name from combo box */
                        SendMessage(GetDlgItem(hDlg, CI_CHANNEL_NAME_LIST),
                            CB_GETLBTEXT, (WPARAM)iComboBoxSelectionNumber,
                            (LPARAM)(LPSTR)boardName);
                        /* search for board with indicated name */
                        lpBoardCfg = (LPBOARD_CFG) FindFirstItem (
                                                   &BoardCfgList, SCAN_FROM_HEAD,
                                                   BoardCfgNameMatch,
                                                   (LPSTR) boardName,
                                                   &board_scanner);
                        dwEditChannelID = BoardCfgGetID(lpBoardCfg);
                    }
                }
            }
            break;

        case IDOK:
            ok = TRUE;

            /* get the topic name and address and verify those */
            GetDlgItemText(hDlg, CI_TOPIC_NAME, topicName, sizeof(topicName));

            if (!TopicCfgCheckName(hDlg, lpTopicCfgToEdit, (LPSTR) topicName)) {
                SetFocus(GetDlgItem(hDlg, CI_TOPIC_NAME));
                PfnSendEmSelectAll( hDlg, CI_TOPIC_NAME, TRUE );
                return (TRUE);
            }

            /* check that user selected an I/O channel */
            if (dwEditChannelID == 0L) {
                ok = FALSE;
            }
            if (!ok) {
                MessageBox(hDlg,
                  GetString(STRUSER + 38)  /* "Must select an I/O Channel" */ ,
                  GetAppName(), MB_OK | MB_ICONEXCLAMATION);
                SetFocus(GetDlgItem(hDlg, CI_CHANNEL_NAME_LIST));
                return (TRUE);
            }

            /* verify topic address */
            defTopicAddress = (BYTE) GetDlgItemInt(hDlg, CI_TOPIC_ADDR,
                                                   &ok, FALSE);
            if (!ok) {
                MessageBox(hDlg,
                       GetString(STRUSER + 39)
                        /* "Illegal Topic Address - Invalid Integer" */ ,
                  GetAppName(), MB_OK | MB_ICONEXCLAMATION);
                SetFocus(GetDlgItem(hDlg, CI_TOPIC_ADDR));
                PfnSendEmSelectAll( hDlg, CI_TOPIC_ADDR, TRUE );
                return (TRUE);
            }

            /* verify coil read size */
            defCoilReadSize = (WORD) GetDlgItemInt(hDlg, CI_COIL_READ_SIZE,
                                                   &ok, FALSE);
            if (!ok) {
                /* "Invalid Integer" */
                iMsgId = STRUSER + 40;
            } else if ((defCoilReadSize == 0) || ((defCoilReadSize % 8) != 0)) {
                /* "Coil read size must be positive and multiple of 8" */
                iMsgId = STRUSER + 41;
                ok = FALSE;
            } else if (defCoilReadSize > MAX_COIL_READ_SIZE) {
                /* "Coil read size must be <= 2040" */
                iMsgId = STRUSER + 42;
                ok = FALSE;
            }
            if (!ok) {
                /* "Illegal Coil Read Size" */
                strcpy (tmpBuf, GetString(STRUSER + 43));
                /* append specific error message */
                L = strlen (tmpBuf);
                tmpBuf[L++] = '\n';
                strcpy (&tmpBuf[L], GetString(iMsgId));
                /* display error indication to user */
                MessageBox(hDlg,
                       tmpBuf,
                       GetAppName(),
                       MB_OK | MB_ICONEXCLAMATION);
                SetFocus(GetDlgItem(hDlg, CI_COIL_READ_SIZE));
                PfnSendEmSelectAll( hDlg, CI_COIL_READ_SIZE, TRUE );
                return (TRUE);
            }

            /* verify register read size */
            defRegReadSize = (WORD) GetDlgItemInt(hDlg, CI_REG_READ_SIZE,
                                                  &ok, FALSE);
            if (!ok || (defRegReadSize == 0)) {
                /* "Invalid Integer" */
                iMsgId = STRUSER + 44;
                ok = FALSE;
            } else if (defRegReadSize > MAX_REG_READ_SIZE) {
                /* "Register read size must be <= 255" */
                iMsgId = STRUSER + 45;
                ok = FALSE;
            }
            if (!ok) {
                /* "Illegal Register Read Size" */
                strcpy(tmpBuf, GetString(STRUSER + 46));
                /* append specific error message */
                L = strlen (tmpBuf);
                tmpBuf[L++] = '\n';
                strcpy (&tmpBuf[L], GetString(iMsgId));
                /* display error indication to user */
                MessageBox(hDlg,
                       tmpBuf,
                       GetAppName(),
                       MB_OK | MB_ICONEXCLAMATION);
                SetFocus(GetDlgItem(hDlg, CI_REG_READ_SIZE));
                PfnSendEmSelectAll( hDlg, CI_REG_READ_SIZE, TRUE );
                return (TRUE);
            }

            /* verify update interval */
            if (!GetIntg(hDlg, CI_UPDATE_INTERVAL, &defUpdateInterval)) {
                return (TRUE);
            }
            if (defUpdateInterval <= 0) {
                MessageBox(hDlg,
                       GetString(STRUSER + 47)
                        /* "Update Interval must be positive integer" */ ,
                       GetAppName(),
                       MB_OK | MB_ICONEXCLAMATION);
                SetFocus(GetDlgItem(hDlg, CI_UPDATE_INTERVAL));
                PfnSendEmSelectAll( hDlg, CI_UPDATE_INTERVAL, TRUE );
                return (TRUE);
            }

            /* everything is OK */
            lpTopicCfgToEdit->tc_channelID      = dwEditChannelID;
            lpTopicCfgToEdit->tc_topicAddress   = defTopicAddress;
            lpTopicCfgToEdit->tc_coilReadSize   = defCoilReadSize;
            lpTopicCfgToEdit->tc_regReadSize    = defRegReadSize;
            lpTopicCfgToEdit->tc_updateInterval = defUpdateInterval;
            lstrcpy(lpTopicCfgToEdit->tc_name, topicName);
            lstrcpy(defTopicName, topicName);

            if (newTopicEntry) {
                /* put this entry into list */
                TopicCfgAddToList(lpTopicCfgToEdit);
            }
            if (ConfigureSave()) {
                EndDialog(hDlg, 1);
            } else {
                TopicCfgDeleteFromList(lpTopicCfgToEdit);
                lpTopicCfgToEdit = (LPTOPIC_CFG) NULL;
            }
            break;


        case IDCANCEL:
            if (newTopicEntry) {
                /* discard new topic, free the memory */
                wwHeap_FreePtr( hHeap, lpTopicCfgToEdit);
                lpTopicCfgToEdit = (LPTOPIC_CFG) NULL;
            }
            EndDialog(hDlg, 0);
            break;
        default:
            return (FALSE);
        }
        break;

    default:
        return (FALSE);
    }
    return (TRUE);
} /* TopicDialogProc */

/***********************************************************************/
/** check whether topic configuration can be deleted from list;
    get confirmation from user that it really should be deleted;
    if OK, delete topic configuration and re-write CFG file **/

static
VOID
WINAPI
TopicCfgCheckDelete(HWND hDlg, LPTOPIC_CFG lpTopicCfg)
{
    BOOL            bDelete;

    /* initialize flag */
    bDelete = TRUE;

    if (bDelete) {
        TopicCfgDeleteFromList(lpTopicCfg);
        ConfigureSave();
    }
} /* TopicCfgCheckDelete */

/***********************************************************************/
/** initialize Combo Box containing the names of configured I/O channels;
    this is done as part of the setup for the Topic configuration dialog
    so that the user may easily select which I/O channel to use for the
    topic being configured 

⌨️ 快捷键说明

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