Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Serial Device - RTS: (5 Items)
   
Serial Device - RTS  
Hello

I am bringing up some new hardware and need a simple method to toggle the RTS line on the output of a serial device 
(uart 16550). I looked at the online help and found that the utility stty used to provide this functionality but not in 
6.4.1 which I am using.

Is there an alternative method, I could do this programmatically (could you provide an example) but would also like a 
command line option for scripting purposes.
Thanks for your help
Re: Serial Device - RTS  
Try this....



#include <devctl.h>
#include <sys/dcmd_chr.h>

/* For "open()" */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

/* For Errors */
#include <stdlib.h>
#include <stdio.h>

int check_statuses(int fd);

int main(int argc, char* argv[])
{
    int data = 0, fd, i;
    int rts = -1, dtr = -1;
    
    
    for(i = 1; i < argc ; i++){
    	if(!strcmpi(argv[i], "+RTS")){
    	  rts = 1;
    	} else if(!strcmpi(argv[i], "-RTS"))	{
    	  rts = 0;
    	} else if(!strcmpi(argv[i], "+DTR")){
    	  dtr = 1;
    	} else if(!strcmpi(argv[i], "-DTR"))	{
    	  dtr = 0;
    	}
    }
    

    if(rts != -1){
    	data |= _CTL_RTS_CHG;
    	if(rts){
	  data |= _CTL_RTS;
    	}
    }
    
    if(dtr != -1){
    	data |= _CTL_DTR_CHG;
    	if(dtr){
    	  data |= _CTL_DTR;
    	}
    }
    
    if(data){
    
	    if (devctl (0, DCMD_CHR_SERCTL, &data, sizeof(data), NULL))
	    {
  		  fprintf(stderr, "Error setting RTS.\n");
		  perror (NULL);
	        exit(EXIT_FAILURE);
	    }
    
    }

    check_statuses(0);

    return (0);
}


int check_statuses(int fd)
{
    int data = 0;

    
    if(devctl (fd, DCMD_CHR_LINESTATUS, &data, sizeof(data), NULL))
    {
	    fprintf(stderr, "Error getting statuses.\n");
	    perror (NULL);
	    exit(EXIT_FAILURE);
    }

    if (data & _LINESTATUS_SER_RTS)
        printf("+RTS ");
    else
        printf("-RTS ");
        
    if (data & _LINESTATUS_SER_DTR)
        printf("+DTR ");
    else
        printf("-DTR ");
        
    if (data & _LINESTATUS_SER_CTS)
        printf("+cts ");
    else
        printf("-cts ");

    if (data & _LINESTATUS_SER_DSR)
        printf("+dsr ");
    else
        printf("-dsr ");

    if (data & _LINESTATUS_SER_RI)
        printf("+ri ");
    else
        printf("-ri ");

    if (data & _LINESTATUS_SER_CD)
        printf("+cd ");
    else
        printf("-cd ");

    printf("\n");

    return(1);
}
Re: Serial Device - RTS  
Hello,

I got the original problem resolved, thanks for your help.

During testing I noticed that I can assert and negate the RTS line but DTR is also toggled even though I have not 
attempted to manipulate the DTR line. On further investigation I noticed that when I negate DTR it is automaticallly 
asserted.

Any ideas what is causing this automatic DTR behaviour?

I thought it might be devc-con or devc-ser8250 but cannot track it down.

I tried "stty < /dev/ser2 -ohflow" to disable hardware flow control but this did not have any effect.

I tried tracking this behaviour down in the source but have not been able to find it, any ideas where to look?

Thanks in advance. 
Re: Serial Device - RTS  
-ihflow -ohflow
?
Re: Serial Device - RTS  
Hello,

I interpret ihflow to enable/disable hardware input flow control (CTS and DSR) and ohflow to enable/disable hardware 
output flow control (RTS and DTR). These are command line options to the stty utility.