Hello
when modbus program (free MODBUS/TCP to MODBUS/RTU gateway server (mbusd)) on ttyS0 is run, inserted parameter not initialize.
Quote:
$ mbusd -d -v 2 -p /dev/ttyS0 -P 502 -s 19200 -R 1 -W 25 -C 128
1307941684:339882 mbusd-0.1.2 started...
|
Quote:
$ stty -F /dev/ttyS0 -a
speed 0 baud; cs5 -cread -clocal ,...
|
But when i run this command in command line : $ stty -F /dev/ttyS0 speed 19200 cs8 cread , modbus program works without any error.
this section of mbusd source code is for initializing :
Quote:
/*
* Setting up tty device MOD attributes
*/
int
tty_set_attr(ttydata_t *mod)
{
int flag;
if (tcgetattr(mod->fd, &mod->savedtios))
return RC_ERR;
memcpy(&mod->tios, &mod->savedtios, sizeof(mod->tios));
mod->tios.c_cflag &= ~(CSTOPB | PARENB | PARODD | CRTSCTS);
mod->tios.c_cflag |= CS8 | CREAD | CLOCAL;
mod->tios.c_iflag = FALSE;
mod->tios.c_oflag = FALSE;
mod->tios.c_lflag = FALSE;
mod->tios.c_cc[VTIME] = 0;
mod->tios.c_cc[VMIN] = 1;
#ifdef HAVE_CFSETSPEED
cfsetspeed(&mod->tios, tty_transpeed(mod->speed));
#else
cfsetispeed(&mod->tios, tty_transpeed(mod->speed));
cfsetospeed(&mod->tios, tty_transpeed(mod->speed));
#endif
if (tcsetattr(mod->fd, TCSANOW, &mod->tios))
return RC_ERR;
#if defined(TIOCSETA)
ioctl(mod->fd, TIOCSETA, &mod->tios);
#else
/* if TIOCSETA is not defined, try to fallback to TCSETA */
ioctl(mod->fd, TCSETA, &mod->tios);
#endif
tcflush(mod->fd, TCIOFLUSH);
#ifdef TRXCTL
tty_clr_rts(mod->fd);
#endif
flag = fcntl(mod->fd, F_GETFL, 0);
if (flag < 0)
return RC_ERR;
return fcntl(mod->fd, F_SETFL, flag | O_NONBLOCK);
}
|
If the source code has any problem?
anybody can help me to solve this problem.
Thanks