RS485 Communincation Hang on Long run

Am using an application written in C . Its trying to communicate with external device using RS 485 Communication within interval around 500ms .
Initially communication is working but after some time .May be couple of hours , data shifting happens and later no data is communicated .

Tested the Other side device with Desktop based serial port simulator software for long run and its able to communicate without data loss.

Hello @abhil and Welcome to the Toradex Community!

Could you provide the software version of your module? Which carrier board are you using?

Am using an application written in C

Could you provide a sample code, so we can reproduce the issue?

May be couple of hours , data shifting happens and later no data is communicated .

How did you detect the data shifting?

Best regards,
Jaski

Could you provide the software version of your module? Which carrier board are you using?

Colibri_VF_LinuxImageV2.8b3

How did you detect the data shifting? >> While Monitoring the data from serial port using serialport software on desktop side.

Please note that BSP 2.8b3 is no longer supported as it got superseded by BSP 2.8b6 meanwhile even having been declared stable.

Which serial-port software are you using? Could you provide a sample code?

Recently updated and tried with BSP 2.8b6 also.Obtained same result.

From VF61 , using c program to send data using modbus protocol to Outside device( tested with device and pc simulator software Docklite) and read the response from device. It happens less than 500ms.

please find the below Sample code

* Driver-specific ioctls: */
#define TIOCSRS485      0x542F
#define  MOD_FN_R 0x03	
#define	timecnt 3				
#define	bytecount 9

unsigned char writebuf[8]; 
int fid;   
int uart_init_485(void)
{
struct termios options;
struct serial_rs485 rs485conf;
fid = open("/dev/ttyLP2" , O_RDWR| O_NONBLOCK | O_NDELAY );	//open AXIO card port for VH-demand
if ( fid < 0 )
{
	perror("/dev/ttyLP2");
	return -1;
}
else
{
   	printf("port opened /dev/ttyLP2 - 485\n");
}
rs485conf.flags |= SER_RS485_ENABLED; 			//Enable RS485 mode 
rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND);	//set logical level for RTS pin equal to 0 when sending
rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;	// Set logical level for RTS pin equal to 1 after sending
rs485conf.delay_rts_before_send = 1000;			// Set rts delay before send, if needed
rs485conf.delay_rts_after_send = 1000;			//Set rts delay after send, if needed
if (ioctl (fid, TIOCSRS485, &rs485conf) < 0)//Read ttyLP2 by ioctl
{
	perror("/dev/ttyLP2 as 485");
}
fcntl(fid, F_SETFL, FNDELAY);        		// Configure port reading 
tcgetattr(fid, &options);	   				// Get the current options for the port 
cfsetispeed(&options, B9600);      				//Set the baud rates to 9600 
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD);	        //Enable the receiver and set local mode 
options.c_cflag &= ~PARENB; 					// Mask the character size to 8 bits, no parity
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |=  CS8;                		//Select 8 data bits 
options.c_cflag &= ~CRTSCTS;            		// Disable hardware flow control 
options.c_lflag &= ~(ICANON | ECHO | ISIG);   	// Enable data to be processed as raw input 
tcsetattr(fid, TCSANOW, &options);	        // Set the new options for the port 
    return 0;
}

int portread(int fid,char *data,int size)
{

int i = 0;
memset (data,' ',size);
i = read (fid,data,size);
fflush (stdout);
tcflush (fid,TCIFLUSH);
return i;
}

int uart_write(unsigned char *Uart_Write_buffer,unsigned char *aiovariable, int fid,int write_len)
{
int ret=0;
unsigned char data[20] = {0};
unsigned char readcount = 0,timeoutcount=0;     			

ret = write(fid,Uart_Write_buffer,write_len);
usleep(10000);
while((readcount < bytecount) && (timeoutcount<timecnt))
{
	if((ret = portread(fid, data+readcount, bytecount-readcount) )>0)
	{
		readcount=readcount+ret;
	}
	timeoutcount++;
}		
memcpy( aiovariable,data+3,data[2]-2);		
return(1);	
}

int read_reg(unsigned char AI_ID,unsigned char *variable)
{
int retval_srr = 0;
writebuf[0]=AI_ID;                      
writebuf[1]=MOD_FN_R;		                 	
writebuf[2]=0;			 
writebuf[3]=0;
writebuf[4]=0;			 
writebuf[5]=2;		
writebuf[6]=1;
writebuf[7]=5;

if(fid <=0)
{
	if(uart_init_485() < 0)
	{
		return 0;
	}
	else
	{
	 	printf("port open success->RS485\n");
	}
}
retval_srr=uart_write(writebuf,variable,fid,8);
return(retval_srr);
}

void main()
{
unsigned char j,i,k=0;
unsigned char auxio[4]={0},parray[2]={0};	
while(1)
{
	for(j=0;j<4;j++)
	{
		for(i=0;i<3;i++)
		{
			if(read_reg (j+1,parray) ==1 )          
			{
				k++;     
			}					
			if(k>=1)
			{
				auxio[j]=1;k=0;
				break;
			}
			sleep(2);
		}
	}			
    }
}

Hi @abhil

Thanks for the code. We will try to reproduce the issue on our side and come back tomorrow to you.

Best regards,
Jaski

Hi @abhil

I tried your code and I could not reproduce the issue. Could you use this python3 code on your host with adaptation for your needs and check if you can reproduce the error?

Thanks for your cooperation.

Best regards,
Jaski

Actually issue happens if we run for long time at high speed communication.

Am not familiar with python. Will try this code.

Are you using any flow control?
What is your communication speed?

Python is easy to learn.

hi @abhil

Is this issue solved?

Best regards,
Jaski