IP Stack full

#1

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.

0 Likes

#2

I have noticed that modem status CTS change from CTS_X to CTS__ while is transffering data.

Somebody knows why this change?

Thanks.

0 Likes

#3

Using Event->content.read.readable and Event->content.write.writable is deprecated and not supported in WIP 5.00. What version do you use?
Also when sending data it is best to use:

wip_write(Channel, buffer, buffersize + 1)

By doing that you will send exactly buffersize bytes and you will be notified by an WIP_CEV_WRITE event when the bytes are completely sent. But before you do that you have to set your buffersize like that:

wip_setOpts(Channel, WIP_COPT_SND_BUFSIZE, buffersize, WIP_COPT_SND_LOWAT, buffersize, WIP_COPT_END);

Best regards,

wismo_coder

0 Likes

#4

Thanks for your answer. I’m using WIP 3.00.

I guess that is also best to use this for reading data:

wip_read(Channel, buffer, buffersize + 1)

and this:

wip_setOpts(Channel, WIP_COPT_RCV_BUFSIZE, buffersize, WIP_COPT_RCV_LOWAT, buffersize, WIP_COPT_END);

Right?

0 Likes

#5

By the way…

When I do:

nread = wip_read(Channel, buffer, buffersize + 1)

Do I need to assing ‘/0’ to to buffer[nread] ?

buffer[nread] = ‘/0’

Thanks.

0 Likes