CH392工作在TCP Server模式时,参考手册说明需要打开监听Socket端口,也要设置数据连接Socket端口,注意数据连接Socket的源端口和监听Socket的源端口一致。
配置TCP Server Socket数代码处理如下:
void InitCH392InfParam(void) { memset(&CH392Inf, 0, sizeof(CH392Inf)); /* Clear all CH392Inf to zero */ memcpy(CH392Inf.IPAddr, CH392IPAddr, sizeof(CH392IPAddr)); /* Enter the IP address in the CH392Inf file */ memcpy(CH392Inf.GWIPAddr, CH392GWIPAddr, sizeof(CH392GWIPAddr)); /* Enter the gateway IP address in the CH392Inf file */ memcpy(CH392Inf.MASKAddr, CH392IPMask, sizeof(CH392IPMask)); /* Enter the mask IP address in the CH392Inf file */ } /********************************************************************************** * Function Name : InitSocketParam * Description : Initialize Socket * Input : None * Output : None * Return : None **********************************************************************************/ void InitSocketParam(void) { memset(&SockInf[0], 0, sizeof(SockInf[0])); /* Clear all SockInf[0] to zero*/ SockInf[0].SourPort = Socket0SourPort; /* SourPort */ SockInf[0].ProtoType = PROTO_TYPE_TCP; /* TCP mode*/ memset(&SockInf[1], 0, sizeof(SockInf[1])); /* Clear all SockInf[1] to zero*/ SockInf[1].SourPort = Socket0SourPort; /* SourPort */ SockInf[1].ProtoType = PROTO_TYPE_TCP; /* TCP mode*/ memset(&SockInf[2], 0, sizeof(SockInf[1])); /* Clear all SockInf[1] to zero*/ SockInf[2].SourPort = Socket0SourPort; /* SourPort */ SockInf[2].ProtoType = PROTO_TYPE_TCP; /* TCP mode*/ } /********************************************************************************** * Function Name : CH392SocketInitOpen * Description : Set CH392 socket parameters to initialize and open the socket * Input : None * Output : None * Return : None **********************************************************************************/ void CH392SocketInitOpen(void) { UINT8 i; CH392CMDSetSocketProtType(0, SockInf[0].ProtoType); /* set socket 0 type */ CH392CMDSetSocketSourPort(0, SockInf[0].SourPort); /* set socket 0 sour port */ i = CH392CMDOpenSocket(0); /* open socket 0 */ mStopIfError(i); /* check the result */ i = CH392CMDTCPListen(0); mStopIfError(i); CH392CMDSetSocketProtType(1, SockInf[1].ProtoType); /* set socket 1 type */ CH392CMDSetSocketSourPort(1, SockInf[1].SourPort); /* set socket 1 sour port */ CH392CMDSetSocketProtType(2, SockInf[2].ProtoType); /* set socket 1 type */ CH392CMDSetSocketSourPort(2, SockInf[2].SourPort); /* set socket 1 sour port */ }
注意:代码开启了两个数据连接Socket,CH392F最多支持开启三个,CH392T最多支持开启七个。
标签:socket,CH392Inf,CH392,TCP,Server,SockInf,SourPort,Socket From: https://www.cnblogs.com/sw111/p/17987044