/* XDemo09: Timer trigger demo 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. 19c, 19C -> clear count value 19r, 19R -> read count value UserCount will be executed every second. Count value will be increased in UserCount. PC can read count value to know number of seconds after count value is cleared. Hardware: uPAC-7186EX [Dec 18, 2008] by Liam */ #include #include #include "..\lib\7186e.h" #include "..\lib\Tcpip32.h" #include "..\lib\vxcomm.h" unsigned int cnt; char c_cnt[20]; void UserCount(void) { /* user's timer trigger function. Call AddUserTimerFunc can trigger this function periodly. Example: void UserInit(void) { AddUserTimerFunc(UserCount, 1000); // 1000 ms } 7188E/8000E executes UserCount every second. In this function, users should avoid to use any function that could conflict hardware signals. Such as: 1. ClockHigh(), ClockLow(), ClockHighLow(), 2. EEPROM functions. 3. 5DigitLed functions. 4. NVRAM function. 5. RTC function.(GetTime(), SetTime(), GetDate() and SetDate()) 6. float point calculation. */ cnt++; } void UserInit(void) { /* In this function, user CAN: 1. initialize user's program. 2. set time interval for calling UserCount(). 3. set initial value of I/O or variables for UserLoopFun(). 4. set initial value of I/O or variables for another functions. 5. change the default TCP PORT 10000/9999/502 to others value. [after vcom3004.lib] Syntax: Port10000=newport_10000; for calling UserCmd (user.c) Port9999=newport_9999; for calling VcomCmd7000 (v7000.c) Port502=newport_502; for calling VcomCmdModbus (vModbus.c) [after vcom3002.lib] PortUser=newport_User; for calling VcomCmdUser (user.c) [after vcom3005.lib] Default port value: Port10000=10000; Port9999=9999; Port502=502; PortUser=0; If the port value is 0, Xserver will not listen that port. That means the port will be disable. */ InitLib(); cnt=0; AddUserTimerFunction(UserCount, 1000); // call UserCnt every 1000 ms } 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. */ int i; if (Cmd[0]) // Not Null command { switch(Cmd[0]) { case 'c': // 19c, 19C --> clear count case 'C': cnt=0; break; case 'r': // 19r, 19R --> read count case 'R': break; default: return 0; // Command Error } sprintf(c_cnt,"%d",cnt); strcpy(Response,c_cnt); // return count value return 1; // return OK } return 0; // return ERROR } 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 }