/* XDemo30: X304 Compiler: BC++ 3.1 Compile mode: large Project: user.c v7000.c vModbus.c [after vcom3002.lib] ..\Lib\XBoard\X304.lib [For X304] ..\Lib\7188E32.Lib ..\Lib\TCPIP32.Lib ..\Lib\VcomNNNN.Lib, with NNNN being the lib file's version. 19AI 0 -> Analog inputs from channel 0 19ai 1 -> Analog inputs from channel 1 19AO 0 2.5 -> Analog outputs 2.5V to channel 0 19ao 1 -3.5 -> Analog outputs -3.5V to channel 1 19DI -> Digital inputs 19DO 3 -> Digital outputs (DO0~DO1 on, DO2~DO3 off) To use X304, Step1: include "X304.h" to your c file Step2: add X304.lib into project file Step3: call X304_Init at beginnig of your c file. Hardware: 7188EX + X304 Refer 7188e\TCP\Doc\[Big5|Eng|Gb2312]\Vxcomm.htm 7188e\TCP\Xserver\Xserver.htm 7188e\TCP\Xserver\Function.htm to get more information. Because the kernal of Xserver used InstallCom() function. Please use printCom1() instead of Print() if you want to send formatted output from COM1. [11/Mar/2002] by Kevin [06,Oct,2004] Commented by Annita [26/May/2005] Modified by Liam (Include X304.lib) [10/Aug/2005] by Liam [26,July,2011] by Nicholas ************************************************************************* X304: 3 channel 12-Bit A/D (Analog input) +-5.0V 1 channel 12-Bit D/A (Analog output)+-5.0V 4 channel D/I 4 channel D/O ************************************************************************* ************************************************************************* * [Software specific] * * Input/Output range: -5.0V -0.0V +0.0V +5.0V * * Decimal integer: 0 2047 2048 4095 * * Hexadecimal: 000 7FF 800 FFF * * * * [A/D] * * Sampling rate: 1800 data/sec (with floating convertion) * * Accuracy==> Typical: +- 1 LSB (+- 2.4 mV) * * Maximum: +- 2 LSB (+- 4.8 mV) * * [D/A] * * Thoughput: 1300 data/sec (with floating convertion) * * Accuracy==> Typical: +- 1 LSB (+- 2.4 mV) * * Maximum: +- 2 LSB (+- 4.8 mV) * * [D/O] * * Throughput: can generate 2KHz square wave signals. * ************************************************************************* */ #include #include #include #include "..\lib\7188e.h" #include "..\lib\tcpip32.h" #include "..\lib\vxcomm.h" #include "..\lib\Xboard\X304.h" 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. */ /* 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(). */ SetBaudrate1(115200L); X304_Init(); } 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. */ float fValue; char sMode[5]; // AO, AI, DO, DI int i,iRet,iValue,iChannel; if(Cmd[0]) { sscanf(Cmd,"%s",&sMode); strupr(sMode); //Analog input if(!strcmp(sMode,"AI")) { sscanf(Cmd+3,"%d",&iChannel); /* To void noise effect, you should do software fitering. Of couse, that will speed down sampling rate. */ fValue=0; for(i=0;i<2;i++) fValue+=X304_AnalogIn(iChannel)/2.0; sprintf(Response,"AI= %7.4fV",fValue); printCom1("AI[%d]= %7.4fV\n\r",iChannel,fValue); } //Analog output else if(!strcmp(sMode,"AO")) { sscanf(Cmd+2,"%d %f",&iChannel,&fValue); X304_AnalogOut(iChannel,fValue); sprintf(Response,"AO[%d] %7.4fV OK.",iChannel,fValue); printCom1("AO[%d] %7.4fV OK.\n\r",iChannel,fValue); } else if(!strcmp(sMode,"DI")) { iValue=X304_DigitalIn(); sprintf(Response,"DI=%01X",iValue); printCom1("DI=%01X\n\r",iValue); } else if(!strcmp(sMode,"DO")) { sscanf(Cmd+3,"%x",&iValue); X304_DigitalOut(iValue); sprintf(Response,"DO %2X",iValue); printCom1("DO %01X\n\r",iValue); } 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 }