ソフトウェア開発およびカスタマイズを承ります。
●
●
Veris社/PowerMonitoringSystem(H663,Modbus)
H663サンプルソース
H663からRS485経由データ取得するPRGサンプル
EGX100経由で、H663からデータ取得手順/サンプル
H663取得手順/サンプル
EGX100設定画面
EGX100経由H663通信機器構成/Modbus
H663 H8822との接続(RS-485) CT接続例
CT接続例(拡大)
サンプルソースコード/H663Sample.c)
/*---------------------------------------------------- H663Sample.c: Send command to H663 to get CH#1 data. */ #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int DoPrintAndPutLOG(unsigned char *LogData); int DoPutLOG_2(unsigned char *LogData); char g_LogMes[512]; /*---------------------------------------- Make Words message(command) to send to EGX100(H663) to get CH# data. Exit: Number of SendData */ int DoMakeCommand(unsigned char *Dat, char intSlaveNo ) { int intLen; Dat[0] = 0x00; Dat[1] = 0x00; Dat[2] = 0x00; Dat[3] = 0x00; /* Number Transfer bytes */ Dat[4] = 0x00; /* High */ Dat[5] = 0x06; /* Low */ /* Slave Addres */ Dat[6] = intSlaveNo; /* Function 03H = Read */ Dat[7] = 0x03; /* Start Reg Address */ Dat[8] = 0x00; /* High */ Dat[9] = 0x00; /* Low */ /* Number of words to read */ Dat[10] = 0x00; /* High */ Dat[11] = 0x01; /* Low */ intLen = 12; sprintf(g_LogMes,"--->%02x %02x %02x %02x %02x %02x %02x %02x", Dat[0],Dat[1],Dat[2],Dat[3],Dat[4],Dat[5],Dat[6],Dat[7]); DoPrintAndPutLOG(g_LogMes); sprintf(g_LogMes,"--->%02x %02x %02x %02x", Dat[8],Dat[9],Dat[10],Dat[11]); DoPrintAndPutLOG(g_LogMes); return intLen; } /*---------------------------------------- Main proc. */ int main(argc, argv) int argc; char *argv[]; { unsigned char sSnd[256]; unsigned char sRcv[256]; char intSlaveNo; int fd,tcp_port,i; struct sockaddr_in dest; FILE *fh; int SockOptflag; int intRet; int intLen; struct timeval tv; int intChrCnt,intFirstTime; char sWork[9]; DoPrintAndPutLOG("H663Sample Start"); if ( argc < 4 ){ sprintf(g_LogMes,"usage: H663Sample [IPAdr][PortNo][H663SlaveAdr]"); DoPrintAndPutLOG(g_LogMes); return 0; } intSlaveNo = argv[3][0] & 0x0f; bzero(sSnd,sizeof(sSnd)); intLen = DoMakeCommand( sSnd, intSlaveNo ); sprintf(g_LogMes,"SendData[%02d]bytes",intLen); DoPrintAndPutLOG(g_LogMes); /* Create a socket */ fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd < 0) { DoPrintAndPutLOG("Socket failed"); return 0; } bzero(&dest, sizeof(dest)); dest.sin_family = AF_INET; tcp_port = atoi(argv[2]); /* get server port */ dest.sin_port = htons(tcp_port); inet_aton(argv[1], &dest.sin_addr); /* get server ip */ /* Connect to Equiptment, retry 3 times*/ for(i=0; i<3; i++) { intRet = connect(fd, (struct sockaddr*)&dest, sizeof(dest)); if (intRet == 0) { DoPrintAndPutLOG("Connect OK"); break; } } if (i == 3) { DoPrintAndPutLOG("Connect failed"); close(fd); return 0; } /* Send Command to EGX100(H663) */ send(fd, sSnd, intLen, 0); /*when data received, send them back*/ DoPrintAndPutLOG("Recv Start"); bzero(sRcv,sizeof(sRcv)); intRet = recv(fd, sRcv, 128, 0); sprintf(g_LogMes,"Recv End Ret[%d]",intRet); DoPrintAndPutLOG(g_LogMes); if (intRet < 1) intRet = 32; DoPrintAndPutLOG("<---"); intChrCnt = 0; g_LogMes[0] = '\0'; for(i=0; i
= 16){ DoPrintAndPutLOG(g_LogMes); g_LogMes[0] = '\0'; intChrCnt = 0; } } if ( intChrCnt > 0 ){ DoPrintAndPutLOG(g_LogMes); } close(fd); DoPrintAndPutLOG("H663Sample End"); return 0; } /*---------------------------------------- Display String to Console also save it to log file. */ int DoPrintAndPutLOG(unsigned char *LogData) { time_t timer; struct tm* t_st; pid_t pid; unsigned char sNowString[32]; unsigned char sLogString[512]; pid=getpid(); time(&timer); t_st = localtime(&timer); time(&timer); t_st = localtime(&timer); sprintf(sNowString,"%04d/%02d/%02d %02d:%02d:%02d", t_st->tm_year+1900,t_st->tm_mon+1,t_st->tm_mday, t_st->tm_hour,t_st->tm_min,t_st->tm_sec); sprintf(sLogString,"%s[%d]:%s\n",sNowString,pid,LogData); printf(sLogString); return(DoPutLOG_2(sLogString)); } /*---------------------------------------- Save String Message to log file. */ int DoPutLOG_2(unsigned char *LogData) { FILE *fp; unsigned char sFullPath[256]; strcpy(sFullPath,"H663Sample.log"); /* Open File */ if ((fp=fopen((const char *)sFullPath,"a"))==NULL){ return 1; } /* Put File */ fputs((const char *)LogData,fp); /* File Close */ fclose(fp); return 0; }
免責事項:
弊社は、本ソフトウェアの使用、または使用できないことにより生じた損害に関していかなる責任も負わないものとします。