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

📄 udmain.c

📁 工业组态软件modbus驱动源代码, 包括帮助文件.共享.
💻 C
📖 第 1 页 / 共 4 页
字号:
/* $Header: "%n Ver=%v  %f  LastEdit=%w  Locker=%l" */
/* "UDMAIN.C Ver=3  26-Nov-97,11:18:30  LastEdit=JIMV  Locker=***_NOBODY_***" */
/***********************************************************************\
*                                                                       *
*       Copyright Wonderware Software Development Corp. 1992-1997       *
*                                                                       *
*               ThisFileName="L:\ww\dde_serv\src\udsample\udmain.c"     *
*               LastEditDate="1997 Nov 26  11:18:00"                    *
*                                                                       *
\***********************************************************************/

// #define USING_WW_COMMONUI  /* use Wonderware common UI splash screen, about box */
   #define USING_WW_ABOUT     /* use Wonderware about box */
// #define USING_WW_LICENSE   /* use Wonderware License Manager */

//DV - Porting to FS2000
//#define SERVER_VERSION  GetString( STRUSER+0 )

#define LINT_ARGS
#include <windows.h>
#include <windowsx.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <string.h>

#include "ntconv.h"
#include "hmemcpy.h"
#include "chainmgr.h"
#include "udprot.h"
#include "uddefs.h"
#include "protocol.h"
#include "debug.h"
#include "system.h"
#include "debug.h"
#include "wwassert.h"
#include "tmpbuf.h"
#include "strval.h"
#include "udgetstr.h"
#include "config.h"
#include "menu.h"
#include "windeflt.h"
#include "srvrhelp.h"
#include "rc.h"
#include "wwcomdlg.h"
#include "wwcommui.h"
#include "CheckItem.h"
#ifdef USING_WW_LICENSE
#include "servlic.h"
#endif

USES_ASSERT

extern HWND     hWndParent;
extern HANDLE   hInst;
extern char szCfgPath[];

HHEAP hHeap;
WORD  tickChange;
DWORD lastTimer;
char  dbgBuf[DBG_BUF_SIZE];
CHAIN PortList;                 /* linked list of ports being used */
BOOL  ProtocolSuspended;
BOOL  ShowingSend = FALSE;      /* display commands to PLC in logger */
BOOL  ShowingReceive = FALSE;   /* display replies from PLC in logger */
BOOL  ShowingErrors = TRUE;     /* display error messages in logger */
BOOL  ShowingEvents = FALSE;    /* display events in logger */
BOOL  IndefWriteRetry = FALSE;  /* retry write messages even after loss of connection */
BOOL  Verbose = TRUE;          /* display program trace messages */
BOOL  DebugMenu = FALSE;        /* enable debug menu on server window */
BOOL  WriteConfigInASCII=FALSE; /* write configuration file as structures */
BOOL  bDoHelp = TRUE;
int   yDebug;                   /* text row position for dump screens */
int   iAllocatedDevices = 0;    /* Count of Active Devices */
BOOL  SimulatorWritePaused = FALSE; /* stop writes to simulated PLC */
BOOL  SimulatorReadPaused = FALSE;  /* stop reads from simulated PLC */

static DWORD dwValidDataTimeout;

static DWORD WINAPI TickDiff (DWORD dwFrom, DWORD dwTo);

#ifdef WIN32
char szServerIDstring[100];
#endif

/***********************************************************************/

void WINAPI UdDisplayAbout (HWND hWnd);
BOOL WINAPI UdPrivateAbout (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

/***********************************************************************/
/** Initialize protocol.
    Called by the toolkit when the server starts up.
    Should perform any initialization needed by the program.
    returns TRUE if everything is OK, FALSE if error **/

BOOL
WINAPI
ProtInit(void)
{
    int             L;
    char            driverName[20];
    int             nProtTimer;
    int             nReqTimer;
    HMENU           hMenu;
    WORD            wCheckMenu;
    int             piMajorRev;
    int             piMinorRev;
    WORD            wSymsize = SIZE_SYMENT;


    /*******************************************************************\
    *                                                                   *
    *       Get user-selections from the WIN.INI file.                  *
    *                                                                   *
    *   The WIN.INI controls for this application are all optional.     *
    *   Defaults are provided in the code that follows.                 *
    *   The controls that may be provided take the form:                *
    *                                                                   *
    *   [UDSAMPLE]                                                      *
    *   ProtocolTimer=n                                                 *
    *   ValidDataTimeout=n                                              *
    *   RequestTimer=n                                                  *
    *                                                                   *
    *   ShowEvents=0/1                                                  *
    *   ShowSend=0/1                                                    *
    *   ShowReceive=0/1                                                 *
    *   ShowErrors=0/1                                                  *
    *                                                                   *
    *   The application name ([UDSAMPLE]) may be changed to suit your   *
    *   needs.  The keywords may be changed or others added.            *
    *                                                                   *
    \*******************************************************************/

    /* set window size as is appropriate */
    AdjustWindowSizeFromWinIni(hWndParent);

    /* Get driver name for lookups in WIN.INI */
    ProtGetDriverName(driverName, sizeof(driverName));

// DV - porting to FS2000
/*
#ifdef WIN32
    // set up string with server name and version number 
    strcpy (szServerIDstring, GetString(STRUSER+142)); // "Sample I/O Server" 
    L = strlen (szServerIDstring);
    sprintf (&szServerIDstring[L], GetString(STRUSER+145), // "- Version %s" 
                         SERVER_VERSION);
#endif
*/

#if (defined(USING_WW_COMMONUI) && defined(WIN32))
    /* set up to display common start-up message and splash screen */
    WWAnnounceStartup(COMMON_IOSERVER32ID, (LPSTR) szServerIDstring);
#else
// DV - changed for porting to FS2000.
/*
    // Log our own startup message and version number 
    strcpy (tmpBuf, GetString(STRUSER+144)); // "Startup" 
    L = strlen (tmpBuf);
    sprintf (&tmpBuf[L], GetString(STRUSER+145), // "- Version %s" 
                         SERVER_VERSION);
    debug (tmpBuf);
    // set up to display start-up splash screen with resource name WWStartup 

 #ifdef WIN32
    // select WWStartup splash screen instead of Common UI splash screen
    SetSplashScreenParams (FALSE, 0, COMMON_IOSERVER32ID, (LPSTR) szServerIDstring);
    // ensure common user interface has instance handle for application 
    Common_SetAppInstance (hInst);
 #endif

*/
	WWAnnounceStartup(COMMON_IOSERVER32ID,(LPSTR)"");
#endif

    /* Check the version number of WWCOMDLG.DLL to make sure it's high enough */
    if( !WWVerifyComDlgRev( GetAppName(),
                            WWCOMDLG_MAJOR_REV,
                            &piMajorRev,
                            &piMinorRev ) ) {
        debug("Wonderware Common Dialog - Version %d.%d is too old.", piMajorRev, piMinorRev );
        return (FALSE);
    }
    else {
        debug("Wonderware Common Dialog - Version %d.%d", piMajorRev, piMinorRev );
    }

#ifndef WIN32
    /* check size of symbol table entries */
    if (sizeof(SYMENT) != wSymsize) {
        debug("Symbol Table size error -- actual:%d  desired:%d",
              sizeof(SYMENT), wSymsize);
        ASSERT_ERROR;
        return (FALSE);
    }
#endif

    /* initialize last time count */
    lastTimer = GetCurrentTime ();

    /* Initialize the heap used for dynamic memory allocation */
    hHeap = wwHeap_Init();

    /* verify that linked lists are intact */
#ifdef ENABLE_CHAIN_CHECKS
    EnableChainCheck();
#endif

#ifdef USING_WW_LICENSE
    /* check whether this product has a license to run */
    if (!GetIOServerLicense (NULL, FALSE))
        return FALSE;
#endif

    /* Setup frequency at which we'd like to have ProtTimerEvent() called */
    /* Value is in milliseconds */
    nProtTimer      = GetProfileInt( driverName,
                                     NAME_PROTTIMER,
                                     DEFAULT_PROTTIMER);

    SysTimerSetupProtTimer((DWORD) nProtTimer); /* Start timer */


    /*
     * How much time should DDE wait for valid data from the driver
     * before NACKing REQUESTs for data?
     */
    GetProfileString( driverName,
                      NAME_VDTIMEOUT,
                      WW_DEFAULT_VDTIMEOUT,
                      tmpBuf,
                      sizeof(tmpBuf));

    dwValidDataTimeout = atol(tmpBuf);

    /*
     * Setup frequency at which we'd like to have valid data request
     * timeouts checked by the toolkit ( in milliseconds ).
     */
    nReqTimer       = GetProfileInt( driverName,
                                     NAME_RQTIMER,
                                     DEFAULT_RQTIMER);

    SysTimerSetupRequestTimer((DWORD) nReqTimer);

    /* Setup some control variables for the driver */

    WriteConfigInASCII = GetProfileInt( driverName,
                                     GetString(STRUSER + 120)
                                       /* "WriteConfigInASCII" */ ,
                                     WriteConfigInASCII);

    /* Initialize the debugging menu items */

    IndefWriteRetry = GetProfileInt( driverName,
                                     GetString(STRUSER + 112)
                                       /* "WriteRetryIndefinitely" */ ,
                                     IndefWriteRetry);

    ShowingEvents   = GetProfileInt( driverName,
                                     GetString(STRUSER + 71)
                                       /* "ShowEvents" */ ,
                                     FALSE);

    ShowingSend     = GetProfileInt( driverName,
                                     GetString(STRUSER + 72)
                                       /* "ShowSend" */ ,
                                     FALSE);

    ShowingReceive  = GetProfileInt( driverName,
                                     GetString(STRUSER + 73)
                                       /* "ShowReceive" */ ,
                                     FALSE);

    ShowingErrors   = GetProfileInt( driverName,
                                     GetString(STRUSER + 74)
                                       /* "ShowErrors" */ ,
                                     TRUE);

    Verbose         = GetProfileInt( driverName,
                                     GetString(STRUSER + 121)
                                       /* "Verbose" */ ,
                                     Verbose);

    DebugMenu       = GetProfileInt( driverName,
                                     GetString(STRUSER + 122)
                                       /* "DebugMenu" */ ,
                                     DebugMenu);

    /* check whether to display debug menu */
    hMenu = GetSystemMenu(hWndParent, FALSE);
    if (DebugMenu && (hMenu != (HANDLE) NULL)) {
        /* enabled, and menu handle is not null -- set up menu items */
        AppendMenu(hMenu, MF_SEPARATOR, 0xFFFF, (LPSTR)NULL);
        AppendMenu(hMenu, MF_STRING, MENU_SUSPEND,
                   GetString(STRUSER + 123) /* "Suspend Protocol" */);
        AppendMenu(hMenu, MF_STRING, MENU_RESUME,
                   GetString(STRUSER + 124) /* "Resume Protocol" */);
        AppendMenu(hMenu, MF_SEPARATOR, 0xFFFF, (LPSTR)NULL);
        wCheckMenu = (WORD)(ShowingEvents ? MF_CHECKED : MF_UNCHECKED);
        AppendMenu(hMenu, (UINT) (wCheckMenu | MF_STRING), MENU_SHOWEVENTS,
                   GetString(STRUSER + 125) /* "Show Events" */);
        wCheckMenu = (WORD)(ShowingSend ? MF_CHECKED : MF_UNCHECKED);
        AppendMenu(hMenu, (UINT) (wCheckMenu | MF_STRING), MENU_SHOWSEND,
                   GetString(STRUSER + 126) /* "Show Send" */);
        wCheckMenu = (WORD)(ShowingReceive ? MF_CHECKED : MF_UNCHECKED);
        AppendMenu(hMenu, (UINT) (wCheckMenu | MF_STRING), MENU_SHOWRECEIVE,
                   GetString(STRUSER + 127) /* "Show Receive" */);
        wCheckMenu = (WORD)(ShowingErrors ? MF_CHECKED : MF_UNCHECKED);
        AppendMenu(hMenu, (UINT) (wCheckMenu | MF_STRING), MENU_SHOWERROR,
                   GetString(STRUSER + 128) /* "Show Errors" */);
        wCheckMenu = (WORD)(Verbose ? MF_CHECKED : MF_UNCHECKED);
        AppendMenu(hMenu, (UINT) (wCheckMenu | MF_STRING), MENU_VERBOSE,
                   GetString(STRUSER + 129) /* "Verbose" */);
        if (IsSimulatorEnabled()) {
            wCheckMenu = (WORD)(SimulatorWritePaused ? MF_CHECKED : MF_UNCHECKED);
            AppendMenu(hMenu, (UINT) (wCheckMenu | MF_STRING), MENU_SIMULATOR_WRITE,
                       GetString(STRUSER + 133) /* "Simulator Write Paused" */);
            wCheckMenu = (WORD)(SimulatorReadPaused ? MF_CHECKED : MF_UNCHECKED);
            AppendMenu(hMenu, (UINT) (wCheckMenu | MF_STRING), MENU_SIMULATOR_READ,
                       GetString(STRUSER + 134) /* "Simulator Read Paused" */);
        }
        AppendMenu(hMenu, MF_SEPARATOR, 0xFFFF, (LPSTR)NULL);
        AppendMenu(hMenu, MF_STRING, MENU_DUMP,
                   GetString(STRUSER + 130) /* "&Dump" */);
        AppendMenu(hMenu, MF_STRING, MENU_DUMP_SCREEN,
                   GetString(STRUSER + 131) /* "Dum&p Screen" */);
        AppendMenu(hMenu, MF_STRING, MENU_DEBUGGER_CLS,
                   GetString(STRUSER + 132) /* "Clear Screen" */);
        DrawMenuBar(hWndParent);
    }

    /* initialize list of ports to empty */
    InitializeChain (&PortList);

    /* initialize the driver state */
    UdprotResume();     /* Initially the driver is active.     */
                        /* It can be suspended by a menu item. */

    /* Initialize the configuration handler */
    if (!ConfigureInit()) {
        /* could not read configuration file or perform configuration */

⌨️ 快捷键说明

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