Hello all again.
I have a little problem once again. I have a M1306B modem which I use to send and receive data to an SCADA and from a remote station. The problem is that receiving works fine, but when I have to send something weird happens. It sends as it should be for just a while, but after a few moments -depending on the amount of data- it just stops sending. I have tried changing the size of the stack but the error stills appear; later on, but still appears. All this make me think that there is some kind of trouble with the stack or something. I paste my code for reading and writing. Perhaps it will help.
This is the common part and the reading
void Hdlr_TCPSocket ( wip_event_t *Event, t2r_cx_state *ctx ) {
u32 Read;
u32 Write;
u8 *DataBuffer;
wip_channel_t wct_Channel;
u32 snd_offset = (u32) ctx;
u32 nwrite;
TRACE ( ( 1, "Hdlr_TCPSocket: Entering" ) );
wct_Channel = Event->channel;
TRACE ( ( 1, "Hdlr_TCPSocket: Channel: %d", Event->channel ) );
//TRACE (( 1, "SpawnCanalServer en TCP_Handler: %d", SpawnCanalServer ));
switch ( Event->kind ) {
case WIP_CEV_READ:
if ( ctx == (t2r_cx_state *) NULL ) {
u8 myString[255];
TRACE ( ( 1, "Hdlr_TCPSocket: ctx NULL" ) );
sprintf ( myString, "Socket Error. CTX NULL" );
wip_write ( wct_Channel, myString, (u32) strlen(myString) );
wip_close ( wct_Channel );
}
else {
DataBuffer = adl_memGet ( ( Event->content.read.readable + 1 ) + 100 );
wm_memset ( DataBuffer, 0x00, Event->content.read.readable );
while ( ( Read = wip_read ( ctx->cx0, DataBuffer, Event->content.read.readable ) ) > 0 ) {
DataBuffer[Event->content.read.readable] = '\0';
if ( t2r_RS232_Open )
adl_fcmSendData ( V24M_Handle, DataBuffer, Event->content.read.readable );
}
adl_memRelease ( DataBuffer );
}
break;
And here comes my two tries for the writing:
-Try 1
case WIP_CEV_WRITE:
DataBuffer = adl_memGet ( ( Event->content.write.writable + 1 ) + 100 );
wm_memset ( DataBuffer, 0x00, Event->content.write.writable );
nwrite = wip_write( wct_Channel, DataBuffer + snd_offset, sizeof( DataBuffer ) - snd_offset);
snd_offset += nwrite;
wip_setCtx( wct_Channel, (void*) snd_offset);
break;
-Try 2
case WIP_CEV_WRITE:
DataBuffer = adl_memGet ( ( Event->content.write.writable + 1 ) + 100 );
wm_memset ( DataBuffer, 0x00, Event->content.write.writable );
while ( ( Read = wip_read ( ctx->cx0, DataBuffer, Event->content.write.writable ) ) > 0 ) {
DataBuffer[Event->content.write.writable] = '\0';
if ( t2r_RS232_Open )
adl_fcmSendData ( V24M_Handle, DataBuffer, Event->content.write.writable );
}
adl_memRelease ( DataBuffer );
break;
I hope someone can help me. Thank you very much in advance.