/* XDemo62: The Demo of Reads/Writes/Clears EEPROM. Compiler: BC++ 3.1 Compile mode: large Project: user.c v7000.c vModbus.c [after vcom3002.lib] ..\Lib\7188EL.Lib ..\Lib\TCPIP32.Lib ..\Lib\VcomNNNN.Lib, with NNNN being the lib file's version. 19r N,19R N -> read one byte from address N of EEPROM 19rm N,19RM N -> read multi-bytes from EEPROM N:maximum is 2048 bytes 19w N,19w N -> write one byte to address N of EEPROM 19wm N,19WM N -> write multi-bytes to EEPROM,N:maximum is 16 bytes 19we,19WE -> WriteEnable,Set EEPROM to write-enable mode. 19wp,19WP -> WriteProtect,Set EEPROM to write protect mode. 19ri, 19RI -> Read one Integer from EEPROM. 19ri, 19RI -> Read one Integer from EEPROM. 19wi, 19WI -> Write one Integer to EEPROM. 19rf, 19RF -> Read one Float from EEPROM. 19wf, 19WF -> Write one Float to EEPROM. 19rs, 19RS -> Read String from EEPROM. 19ws, 19WS -> Write String to EEPROM. The data stored in EEPROM will not disapper after power off the system. The total size of EEPROM is 2K bytes.EEPROM is suitable to store data that is not changed so frequently. For example: USER ID, PASSWORD, or other system parameters.It can be rewrited about 1,000,000 times. Note: 1.Block 0 and block 1 of EEPROM are used by Xserver to store COM port settings and toher system parameters. 2.Block 7 of EEPROM is used by Xserver to store the settings of IP ,gateway and other system parameters If you want to store data to EEPROM of 7188E/8000E, please use block 1 to block 6. Hardware: 7188E Refer 7188e\TCP\Doc\[Big5|Eng|Gb2312]\Vxcomm.htm 7188e\TCP\Xserver\Xserver.htm 7188e\TCP\Xserver\Function.htm 7188e\MiniOS7\doc\eng\lib\eeprom.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. [24,Aug,2002] by Sean [23,Sep,2004] Commented by Annita [27,May,2005] Modified by Liam Add commands ri, rf and rs to read integer, float, string from Flash. Add commands wi, wf and ws to write integer, float, string to Flash. [10/Aug/2005] by Liam [26,July,2011] by Nicholas */ #include #include #include #include #include "..\lib\7188e.h" #include "..\lib\tcpip32.h" #include "..\lib\vxcomm.h" int block=3; //block 1~6 char sWrite[50]; //sWrite for writing to EEPROM char sData[50]; //sData for reading from EEPROM char cWrite; //cWrite for reading from EEPROM 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. */ cWrite='@'; } 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 sC[4],sP[16]; int iData=0; float fData=0; int iRet,i; sscanf(Cmd,"%s%s",sC,sP); if (!strcmp(sC,"r")|| !strcmp(sC,"R")){ //Cmd[0]=='r' || Cmd[0]=='R') if(atoi(sP)<255){ iRet=EE_RandomRead(block,atoi(sP)); if(iRet<0){ sprintf(Response,"Read error!code(%d)",iRet); return 1; } } else{ sprintf(Response,"The maxaddress exceeds the range(0~255)"); return 1; } sprintf(Response,"The data on block%d,address%d of EEPROM is %c",block,atoi(sP),(char)iRet); } else if (!strcmp(sC,"rm")|| !strcmp(sC,"RM")){ if(atoi(sP)<2048){ iRet=EE_MultiRead(block,0,atoi(sP),sData); if(iRet!=0){ sprintf(Response,"Read error!code(%d)",iRet); return 1; } } else sprintf(Response,"The maximum bytes is 2048"); sprintf(Response,"The data on block%d,address0~%d of EEPROM is %s",block,atoi(sP),sData); } else if (!strcmp(sC,"w")|| !strcmp(sC,"W")){ if(atoi(sP)<255){ iRet=EE_RandomWrite(block,atoi(sP),cWrite); if(iRet!=0){ sprintf(Response,"write error!code(%d)",iRet,cWrite); return 1; } } else{ sprintf(Response,"The maxaddress exceeds the range(0~255)"); return 1; } sprintf(Response,"The data %c writes to block%d,address%d of EEPROM",cWrite,block,atoi(sP)); } else if (!strcmp(sC,"wm")|| !strcmp(sC,"WM")){ if(atoi(sP)<16){ for(i=0;iSocket,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 }