Hy guys,
I have an application that looks like this :
I wrote the application that takes the Modbus message from the SCADA, sends it to the serial interface, waits for response and then forwards the response back to the SCADA application.
All works fine for about 2minutes and a half. After that i receive a WIP_CEV_ERROR event in the tcp handler.
When i read the ev->content.error.errnum it gives me -1000. That means WIP_CERR_ABORTED.
But the data continues to be sent ok, even if i close the channel in case of an error.
I cannot understand why this happens. Maybe someone encountered this type of problem or has a better understanding of WIP library.
This is my code :
Creating the TCP server
void TCPCreate()
{
TRACE((1, "TCP CREATE FUNCTION"));
wip_channel_t c;
c = wip_TCPServerCreate (8080, TCPHandler, NULL);
}
TCP Handler
void TCPHandler(wip_event_t *ev, void *ctx)
{
u8 lbuffer[1000];
u16 i;
TRACE((1, "TCP HANDLER"));
c = ev->channel;
switch (ev->kind)
{
case WIP_CEV_OPEN:
break;
case WIP_CEV_READ: //Data on the socket
nread = wip_read(c, lbuffer, sizeof(lbuffer));
TRACE((1,"nread = %d",nread));
buffer = (u8 *) malloc(sizeof(u8[nread]));
for (i=0; i<=nread;i++)
{
buffer[i] = lbuffer[i];
}
DUMP(1,buffer,sizeof(u8[nread]));
sendData();
break;
case WIP_CEV_ERROR:
TRACE((1,"Channel Error - %d",ev->content.error.errnum));
adl_atSendResponse(ADL_AT_RSP, "Channel Error\n\r");
TRACE((1,"Close channel : %d",wip_close(c)));
break;
case WIP_CEV_PEER_CLOSE:
TRACE((1,"Peer close connection"));
break;
case WIP_CEV_WRITE:
TRACE((1,"WIP_CEV_WRITE"));
break;
default:
break;
}
}
Function that forwards data received from TCP to the serial interface
void sendData()
{
s8 result;
result = adl_fcmSendData(fcm_Handle,buffer,nread);
if (result == 0 )
{
TRACE((1,"Data sent - [OK]"));
free(buffer);
}
else
{
TRACE((1,"Data sent - [ERROR]"));
free(buffer);
}
}
FCM Data Handler
bool DataHdlr(u16 Datalen, u8 * Data)
{
if (Datalen!=0)
{
wip_write(c, Data, Datalen);
adl_fcmReleaseCredits(fcm_Handle, 0xFF);
}
return true;
}
Hope i was clear enough describing my problem…
Thanks in advance!