主题 : 如何控制tiny6410 ttySAC1的RTS 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 27334
精华: 0
发帖: 41
金钱: 205 两
威望: 41 点
综合积分: 82 分
注册时间: 2010-08-24
最后登录: 2018-07-15
楼主  发表于: 2011-08-05 14:51

 如何控制tiny6410 ttySAC1的RTS

版主及各位
在下使用下列编程(想透过RTS控制rs486通讯)控制tiny6410 ttySAC1 的 RTS on 或 off 都没有反应!
不知道是否有那位兄台有使用tiny6410 的 rts.

/*
gcc -o setSerialSignal setSerialSignal.c
*/

#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>

/* we need a termios structure to clear the HUPCL bit */
struct termios tio;

int main(int argc, char *argv[])
{
  int fd;
  int status;

  if (argc != 4)
  {
    printf("Usage: setSerialSignal port         RTS\n");
    printf("Usage: setSerialSignal /dev/ttySAC1 0|1\n");
    exit( 1 );
  }

  if ((fd = open(argv[1],O_RDWR)) < 0)
  {
    printf("Couldn't open %s\n",argv[1]);
    exit(1);
  }
  tcgetattr(fd, &tio);          /* get the termio information */
  tio.c_cflag &= ~HUPCL;        /* clear the HUPCL bit */
  tcsetattr(fd, TCSANOW, &tio); /* set the termio information */

  ioctl(fd, TIOCMGET, &status); /* get the serial port status */

  if ( argv[2][0] == '1' )      /* set the RTS line */
    status &= ~TIOCM_RTS;
  else
    status |= TIOCM_RTS;

  ioctl(fd, TIOCMSET, &status); /* set the serial port status */

  close(fd);                    /* close the device file */
}
级别: 新手上路
UID: 27334
精华: 0
发帖: 41
金钱: 205 两
威望: 41 点
综合积分: 82 分
注册时间: 2010-08-24
最后登录: 2018-07-15
1楼  发表于: 2011-08-11 09:34
图片:
各位好:
只好采用硬件方式处理!
参考下列网站
http://www.lvr.com/rs-485_circuits.htm