// SerialTest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include "Net5BoardLibEx.h" #include "Cod5BoardLibEx.h" #define MAX_SERIAL_DATA_SIZE 1024 #define DEFAULT_URL "rtsp://192.168.13.4" #define BYTES_TO_RECEIVE 6 struct UDA5GlobAPI{ BOOL (__stdcall *Cmn5CreateInstance)(IUnknown **pUnknown); }; int main(int argc, char* argv[]) { UDA5GlobAPI Uda5Api; HMODULE hModule = NULL; IUnknown *pUnknown; INet5 *pNet5Api; ICod5 *pCod5Api; HANDLE hNetEvent; NET5_EVENT_DATA EventData; unsigned char pData[MAX_SERIAL_DATA_SIZE]; ULONG uPortNum = 1; ULONG uBuffIndex = 0; ULONG uMaxSize = MAX_SERIAL_DATA_SIZE; ULONG uDataSize = 0; hModule = LoadLibrary("UdaNVE.dll"); if(hModule){ *(FARPROC*)&Uda5Api.Cmn5CreateInstance = GetProcAddress(hModule,"Cmn5CreateInstance"); }else{ printf("cannot load library\n"); return 0; } Uda5Api.Cmn5CreateInstance(&pUnknown); pUnknown->QueryInterface (IID_INet5,(void**)&pNet5Api); pUnknown->QueryInterface (IID_ICod5,(void**)&pCod5Api); pUnknown->Release(); if (!pNet5Api || !pCod5Api) { printf("cannot get interface\n"); return 0; } if (!pNet5Api->Net5ConnectEx(DEFAULT_URL, NET5_ST_RTP_UDP, 5)) { printf("cannot connect\n"); return 0; } if (!pNet5Api->Net5Login("root", "pass")) { printf("cannot login\n"); return 0; } if (!pNet5Api->Net5GetEventHandle(CMN5_DT_NET_EX, &hNetEvent)) { printf("cannot get event handle\n"); return 0; } UCHAR ActivationCode[CMN5_ACTIVATION_CODE_SIZE]; if (!pCod5Api->Cod5Activate(0, ActivationCode)) { printf("cannot activate\n"); return 0; } if (!pCod5Api->Cod5Setup()) { printf("cannot setup\n"); return 0; } if (!pCod5Api->Cod5Run()) { printf("cannot setup\n"); return 0; } while (1) { printf("wait serial event\n"); ULONG uRs = WaitForSingleObject(hNetEvent, INFINITE); if (uRs != WAIT_OBJECT_0) { break; } pNet5Api->Net5GetEventData(CMN5_DT_NET_EX, &EventData); if (EventData.uNetDataType == NET5_NDT_RECV_SERIAL_DATA) { pNet5Api->Net5Command(NET5_NC_RECV_SERIAL_DATA, &uPortNum, (ULONG*)(&pData[uBuffIndex]), &uMaxSize, &uDataSize); printf("Received serial data: \n"); for (ULONG i=0; iCod5Stop(); pCod5Api->Cod5Endup(); pNet5Api->Net5Disconnect(); return 0; }