




已阅读5页,还剩22页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
前置机端的程序设计一、物理组织结构图:图1 能量采集系统组织结构图图1中数据采集和Web服务器作为能量采集系统中的前置机部分,负责从其他通讯设备中读取能量采集表中的数据和根据后台工作站配置信息进行相应的配置。二、设计要求:l 支持多种通讯方式。例如:RS232、SOCKET方式等。l 支持多种通讯规约。例如:龙电、其他电能表生产厂家等。l 支持多种数据库的访问方式。例如:ODBC、DBLIB、CTLIB、PRO*C等。l 支持多种操作系统。例如:Linux、Windows平台等。三、设计的总体思想:WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char * lpCmdLine, int nCmdShow) MSG msg; if (!InitApplication(hInstance) return (FALSE); if (!InitInstance(hInstance, nCmdShow) return (FALSE); if (!InitTCPIP() return (FALSE); OsStart();/add by zhangdy OsInit(); /add by zhongh .1.#ifdef _MIN_ICON_ NOTIFYICONDATA NotifyData; NotifyData.cbSize = sizeof(NOTIFYICONDATA);NotifyData.hWnd = hWnd;NotifyData.uID = (UINT)100;NotifyData.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; NotifyData.uCallbackMessage = WM_USER + 998;NotifyData.hIcon = LoadIcon(NULL, IDI_WINLOGO);strcpy(NotifyData.szTip, SCP_KERNEL);Shell_NotifyIcon(NIM_ADD, &NotifyData);ShowWindow(hWnd, SW_HIDE); #endif while (GetMessage(&msg, NULL, 0, 0) TranslateMessage(&msg); DispatchMessage(&msg); #ifdef _MIN_ICON_ NOTIFYICONDATA NotifyData; NotifyData.cbSize = sizeof(NOTIFYICONDATA); NotifyData.hWnd = hWnd; NotifyData.uID = (UINT)100; NotifyData.uFlags = NIF_ICON | NIF_TIP; NotifyData.hIcon = LoadIcon(NULL, IDI_WINLOGO); strcpy(NotifyData.szTip, SCP_KERNEL); Shell_NotifyIcon(NIM_DELETE, &NotifyData); #endif return msg.wParam; lpCmdLine; hPrevInstance;BOOL InitApplication(HINSTANCE hInstance) WNDCLASS wc; if (!IS_NT) /This application only for NT MessageBeep(MB_OK); MessageBox(NULL, 本程序只适用于 WINDOWS NT 平台!, 警告, MB_ICONSTOP | MB_OK); return FALSE; if (FindWindow(szAppName, szTitle) / 防止程序的重复启动/add by zhongh .6. MessageBox(NULL,An old version already exist,Quit it and retry., !警告!, MB_ICONSTOP | MB_OK); return FALSE; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hbrBackground = (struct HBRUSH_ *)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = szAppName; return RegisterClass(&wc);int UnhandledExceptionHappen = 0; LONG MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo) UnhandledExceptionHappen = 1; OsWriteExceptionToFile(0,0xffff,(void *)ExceptionInfo); SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX); return EXCEPTION_EXECUTE_HANDLER; ExceptionInfo;BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) hWnd = CreateWindow(szAppName, szTitle, WS_MINIMIZE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!hWnd) return (FALSE); / modifyed by zhongh .1.#ifdef _DEBUG ShowWindow(hWnd, SW_SHOW); #else ShowWindow(hWnd, SW_HIDE); #endif UpdateWindow(hWnd); SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST);/added by txm SetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER)MyUnhandledExceptionFilter); /*SetUnhandledExceptionFilterThe SetUnhandledExceptionFilter function lets an application supersede the top-level exception handler that Win32 places at the top of each thread and process. After calling this function, if an exception occurs in a process that is not being debugged, and the exception makes it to the Win32 unhandled exception filter, that filter will call the exception filter function specified by the lpTopLevelExceptionFilter parameter. LPTOP_LEVEL_EXCEPTION_FILTER SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter / exception filter function ); ParameterslpTopLevelExceptionFilter Pointer to a top-level exception filter function that will be called whenever the UnhandledExceptionFilter function gets control, and the process is not being debugged. A value of NULL for this parameter specifies default handling within UnhandledExceptionFilter. The filter function has syntax congruent to that of UnhandledExceptionFilter: It takes a single parameter of type LPEXCEPTION_POINTERS, and returns a value of type LONG. The filter function should return one of the following values: Value Meaning EXCEPTION_EXECUTE_HANDLER Return from UnhandledExceptionFilter and execute the associated exception handler. This usually results in process termination. EXCEPTION_CONTINUE_EXECUTION Return from UnhandledExceptionFilter and continue execution from the point of the exception. Note that the filter function is free to modify the continuation state by modifying the exception information supplied through its LPEXCEPTION_POINTERS parameter. EXCEPTION_CONTINUE_SEARCH Proceed with normal execution of UnhandledExceptionFilter. That means obeying the SetErrorMode flags, or invoking the Application Error pop-up message box. Return ValuesThe SetUnhandledExceptionFilter function returns the address of the previous exception filter established with the function. A NULL return value means that there is no current top-level exception handler. RemarksIssuing SetUnhandledExceptionFilter replaces the existing top-level exception filter for all existing and all future threads in the calling process. The exception handler specified by lpTopLevelExceptionFilter is executed in the context of the thread that caused the fault. This can affect the exception handlers ability to recover from certain exceptions, such as an invalid stack. */using by zhongh, 1999.05.08 MyProcessHeapHandle = GetProcessHeap(); return (TRUE); nCmdShow;/在初始时,初始化网络部分BOOL InitTCPIP(void) WSADATA WSAData; int status; BOOL TempBool = TRUE; if (!GetConfig() MessageBeep(MB_OK); MessageBox(hWnd, 通讯配置或参数出错!, 警告, MB_ICONSTOP | MB_OK); return FALSE; if (WSAStartup(MAKEWORD(1,1), &WSAData) != 0) MessageBeep(MB_OK); MessageBox(hWnd, TCP/IP 协议初始化出错!, 警告, MB_ICONSTOP | MB_OK); return FALSE; if (LOBYTE( WSAData.wVersion ) != 1) | (HIBYTE( WSAData.wVersion ) != 1) MessageBeep(MB_OK); MessageBox(hWnd, 套接字版本不匹配!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; CancelBlocking(); if (IsServer = TRUE) SOCKET TempSocket; SOCKADDR_IN local_sin; TempSocket = socket(AF_INET, SOCK_STREAM, 0); if (TempSocket = INVALID_SOCKET) MessageBeep(MB_OK); MessageBox(hWnd, 建立数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; local_sin.sin_family = AF_INET; local_sin.sin_port = htons(u_short)ZXJ10B_TCP_PORT); local_sin.sin_addr.s_addr = INADDR_ANY; if (bind(TempSocket, (PSOCKADDR)&local_sin, sizeof(local_sin) = SOCKET_ERROR) MessageBeep(MB_OK); MessageBox(hWnd, 捆扎数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; if (listen(TempSocket, MAX_PENDING_CONNECTS) = SOCKET_ERROR) MessageBeep(MB_OK); MessageBox(hWnd, 监听数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; if (WSAAsyncSelect(TempSocket, hWnd, WSA_ACCEPT, FD_ACCEPT) = SOCKET_ERROR) MessageBeep(MB_OK); MessageBox(hWnd, 设置数据流套接字模式失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; SocketStatus0.Socket = TempSocket; if (IS_CLIENT(CurrentNode) SOCKET TempSocket; SOCKADDR_IN remote_sin, local_sin; BYTE i; local_sin.sin_family = AF_INET; local_sin.sin_port = 0; local_sin.sin_addr.s_addr = LocalIPAddr; remote_sin.sin_family = AF_INET; remote_sin.sin_port = htons(u_short)ZXJ10B_TCP_PORT); for (i = 1; i MAX_SOCKET_NUM; i+) if (SocketStatusi.PeerIPAddr != INADDR_NONE) TempSocket = socket(AF_INET, SOCK_STREAM, 0); if (TempSocket = INVALID_SOCKET) MessageBeep(MB_OK); MessageBox(hWnd, 建立数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; / BOOL TempBool = TRUE; / move to head if (setsockopt(TempSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&TempBool, sizeof(BOOL) = SOCKET_ERROR) MessageBeep(MB_OK); MessageBox(hWnd, 设置数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; status = bind(TempSocket, (PSOCKADDR)&local_sin, sizeof(local_sin); if (status = SOCKET_ERROR) MessageBeep(MB_OK); MessageBox(hWnd, 捆扎数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; if (WSAAsyncSelect(TempSocket, hWnd, WSA_CONNECT, FD_CONNECT) MessageBeep(MB_OK); MessageBox(hWnd, 设置数据流套接字模式失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; SocketStatusi.Socket = TempSocket; remote_sin.sin_addr.s_addr = SocketStatusi.PeerIPAddr; status = connect(TempSocket, (PSOCKADDR)&remote_sin, sizeof(remote_sin); if (status = SOCKET_ERROR) status = WSAGetLastError(); if (status != WSAEWOULDBLOCK) MessageBeep(MB_OK); MessageBox(hWnd, 数据流套接字连接失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; #ifdef _SCP_KERNEL_ / add by bzj for debug channel SOCKET TempSocket; SOCKADDR_IN remote_sin, local_sin; TempSocket = socket(AF_INET, SOCK_STREAM, 0); if (TempSocket = INVALID_SOCKET) MessageBeep(MB_OK); MessageBox(hWnd, DEBUG CHANNEL 建立数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; local_sin.sin_family = AF_INET; local_sin.sin_port = htons(u_short)DEBUG_CHANNEL_PORT); local_sin.sin_addr.s_addr = INADDR_ANY; if (bind(TempSocket, (PSOCKADDR)&local_sin, sizeof(local_sin) = SOCKET_ERROR) MessageBeep(MB_OK); MessageBox(hWnd, DEBUG CHANNEL 捆扎数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; if (listen(TempSocket, MAX_PENDING_CONNECTS) = SOCKET_ERROR) MessageBeep(MB_OK); MessageBox(hWnd, DEBUG CHANNEL 监听数据流套接字失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; if (WSAAsyncSelect(TempSocket, hWnd, WSA_ACCEPT, FD_ACCEPT) = SOCKET_ERROR) MessageBeep(MB_OK); MessageBox(hWnd, DEBUG CHANNEL 设置数据流套接字模式失败!, 警告, MB_ICONSTOP | MB_OK); WSACleanup(); return FALSE; g_DebugChannel = TempSocket; / add end #endif MakeCheckMsg(); SetTimer(hWnd, REPEAT_SEND_WAIT_PACKET, REPEAT_SEND_PACKET_TIME, NULL); SetTimer(hWnd, SEND_CHECK_LINK_PACKET, SEND_CHECK_PACKET_TIME, NULL); SetTimer(hWnd, CHECK_IF_LINK_CONNECT, SEND_CHECK_PACKET_TIME, NULL); return TRUE; BOOL GetConfig(void) int nRet, i, PostCount, RefNode; BYTE node = 1; #ifdef _SCP_KERNEL_ for (i = 0; i MAX_SOCKET_NUM + 1; i+)/by bzj#else for (i = 0; i MAX_SOCKET_NUM; i+)#endif InitSocketStatus(BYTE)i); nRet = GetPrivateProfileInt(General, PCNode, 0, INIT_FILE_NAME); if (!IS_PC(nRet) return FALSE; else CurrentNode = (BYTE)nRet; nRet = GetPrivateProfileInt(General, Postoffice, 0, INIT_FILE_NAME); if (!IS_VALID_POST(nRet) return FALSE; else CurrentPost = (BYTE)nRet; nRet = GetPrivateProfileInt(General, AreaCode, 0, INIT_FILE_NAME); if (!IS_VALID_AREACODE(nRet) return FALSE; else CurrentAreaCode = (DWORD)nRet; IsServer = IS_SERVER(CurrentNode); LocalIPAddr = htonl(0xC0000000 + (CurrentAreaCode 19) + (CurrentPost 8) + CurrentNode); if (!IsServer) / Evaluate Local Machine IP Address nRet = GetPrivateProfileInt(General, IsRemoteNode, 2, INIT_FILE_NAME); if (nRet != 0) & (nRet != 1) return FALSE; else IsRemoteNode = nRet; if (IsRemoteNode) nRet = GetPrivateProfileInt(General, ReferNode, 0, INIT_FILE_NAME); if (!IS_CLIENT(nRet) return FALSE; else RefNode = (BYTE)nRet; LocalIPAddr = htonl(0xC0000000 + (CurrentAreaCode + 0x0100) & 0x0300) + RefNode) 19) + (CurrentPost 8) + CurrentNode); PostCount = 1; if (IS_CLIENT(CurrentNode) / Evaluate current post if this machine is Centrex nRet = GetPrivateProfileInt(General, TerminalType, 0, INIT_FILE_NAME); if (nRet TERMINAL_TYPE_CENTRAX) return FALSE; else if (nRet = TERMINAL_TYPE_CENTRAX) int argCount = 0; LPWSTR * argPtr; nRet = GetPrivateProfileInt(General, PostCount, 0, INIT_FILE_NAME); if (nRet MAX_MAINTAIN_POST_NUM) return FALSE; else PostCount = (BYTE)nRet; argPtr = CommandLineToArgvW(GetCommandLineW(), &argCount); if (argPtr = NULL) | (argCount 3) return FALSE; else CurrentPost = _wtoi(*(argPtr + 1); CurrentAreaCode = _wtoi(*(argPtr + 2); for (i = 1; i PostCount) return FALSE; for (i = 1; i = PostCount; i+) char PostPatNAME_LEN, ServerNamePatNAME_LEN, ServerNodePatNAM
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025镇村(社区)后备干部选拔考试题及答案
- 出租户安全知识培训课件
- 维护患者合法权益及知情同意培训试题附答案
- 2025生猪配合饲料供应合同
- 免疫检查点阻断研究-洞察及研究
- 出品部安全培训总结课件
- 2025物流公司管理资料范本货运合同
- 企业安全培训讲座内容课件
- 2025茶叶加盟合同茶叶专卖店合作协议
- 冲转安全培训课件
- 2025年三类人员安全员C证继续教育题库及参考答案
- 2025内蒙古锡林郭勒盟公安局招聘警务辅助人员95人考试参考题库附答案解析
- 急性肾小球肾炎
- 工程管理面试题目及答案
- 《一年级开学第一课》课件
- 2025秋人教版(2024)八年级上册英语一学期教学计划
- 会展推广的合同范本
- 武消院火灾调查B讲义01电气火灾调查
- 起搏器植入患者全程护理要点
- (2025年标准)会议代办协议书
- 工贸企业企业安全检查表
评论
0/150
提交评论