/* XDemo19: Reads system serial number. Compiler: BC++ 3.1 Compile mode: large Project: user.c v7000.c vModbus.c [after vcom3002.lib] ..\Lib\7186EL.Lib ..\Lib\tcp_dm32.lib ..\Lib\VcomNNNN.Lib, with NNNN being the lib file's version. 19 -> Any command will be accepted. Unique hardware serial number is used to protect user's software. Using 7188xw.exe to entry 7188E, MiniOS7 will show the serial number. User can check the number at first, then decide to execute Xserver forward. Hareware: uPAC-7186EX [Dec 18, 2008] by Liam */ #include #include #include #include "..\lib\7186e.h" #include "..\lib\tcpip32.h" #include "..\lib\vxcomm.h" int bSerialNumOk; char cID[8]={0x9,0x31,0xa4,0x39,0x3,0,0,0x5}; // Change this to suit the 64-bit // hardware serial number of your // 7188E mudule. void UserCount(void) { /* User's timer trigger function. Please refer to XDemo04 for detail description. Please refer to XDemo09 for example code. */ } void UserInit(void) { /* Initialize user's program. Please refer to XDemo04 for detail description. Please refer to XDemo09 for example code. */ char cSerialNumber[8]; InitLib(); GetSerialNumber(cSerialNumber); if(!strcmp(cSerialNumber,cID)) bSerialNumOk=1; // Matching ! else bSerialNumOk=0; // Unmatched ! } void UserLoopFun(void) { /* VxComm.exe will call this function every scan time Please refer to XDemo11 for Real-time I/O control */ } int UserCmd(unsigned char *Cmd,unsigned char *Response) { /* Xserver executes this function when received a package form TCP port 10000 and the first two bytes are "19". XServer trims "19" and passes the other data (without "19") to Cmd. You can put a message to Response. Xserver will reply it to the Client when finish this function. Maximum length of Cmd is 1458 bytes. Maximum length of Response is 1024 bytes. [16,Sep,2004] Commented by Annita */ if (bSerialNumOk) strcpy(Response,"ID ok."); else strcpy(Response,"ID error."); return 1; // return OK } int VcomUserBinaryCmd(TCPREADDATA *p) { /* VXCOMM.EXE 2.6.12(04,Sep,2001) or later will support this function. Xserver executes this function when received a package form TCP port 10000 and the first two bytes are "23". Please refer to XDemo04 for detail description. Please refer to XDemo23 for example code. */ return 1; /* any value will be accept */ } int VcomCmdUser(TCPREADDATA *p) { /* VCOM3005 (Feb,22,2002) or later will call this function for PortUser. When packets received by TCP PORT PortUser(user defined) of 7188E/8000E, Xserver will call this function. Please refer to XDemo04 for detail description. */ VcomSendSocket(p->Socket,p->ReadUartChar,p->Length); return 1; /* any value will be accept */ } void PortUserStart(int skt) { /* XS8_3200.Lib Version 3.2.00 (20,Apr,2004) or later version supports this function. When a TCP/IP client connects to the 7188E/8000E via the user's defined port(PortUser), the Xserver calls the function once. Please refer to XDemo04 for detail description. */ skt=skt; //do nothing } void Port9999Start(int skt) { /* XS8_3200.Lib Version 3.2.00 (20,Apr,2004) or later version supports this function. When a TCP/IP client connects to the 7188E/8000E TCP port 9999, the Xserver calls the function once. Please refer to XDemo04 for detail description. */ skt=skt; //do nothing } void Port502Start(int skt) { /* XS8_3200.Lib Version 3.2.00 (20,Apr,2004) or later version supports this function. When a TCP/IP client connects to the 7188E/8000E TCP port 502, the Xserver calls the function once. Please refer to XDemo04 for detail description. */ skt=skt; //do nothing }