/* XDemo18: Reads i-7000 series module's ID. 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. This demo shows how to communication with i-7000 series which connected to COM2 of 7188E. Hareware: uPAC-7186EX + i-7000 series module whose address is 01, baudrate is 9600, checksum is disable. [Dec 18, 2008] by Liam */ #include #include #include "..\lib\7186e.h" #include "..\lib\Tcpip32.h" #include "..\lib\vxcomm.h" char cStr[9]; // Receive data from 7000: "!017021" + 0x0c char cModuleID[5]; // Store module ID: "7021" + 0x00 void UserCount(void) { /* User's timer trigger function. Please refer to XDemo04 for detail description. Please refer to XDemo09 for example code. */ int i; SendCmdTo7000(2,"$01M",0); ReceiveResponseFrom7000(2, cStr, 1000, 0); // cut "!01" and cr strcpy(cModuleID,cStr+3); cModuleID[4]=0; // Show moduleID to PC monitor printCom(1, "Address: 01, ModuleID:%s\n\r",cModuleID); } void UserInit(void) { /* Initialize user's program. Please refer to XDemo04 for detail description. Please refer to XDemo09 for example code. */ InitLib(); AddUserTimerFunction(UserCount,1000); /* All of the program user.c needn't function Installcom(). Becuase they have install When the Xserver initialize. If you want to change the baud rate.data format, please using the function SetBaudrate().SetDataFormat(). */ SetBaudrate(1,115200L); SetBaudrate(2,9600); } 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". Funtion of Xserver, Please refer to XDemo04 for detail description. */ char cStr[20]; sprintf(cStr,"ModuleID:%s",cModuleID); strcpy(Response,cStr); 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 }