LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   problem with mbusd source code (https://www.linuxquestions.org/questions/programming-9/problem-with-mbusd-source-code-885976/)

alireza976 06-13-2011 12:44 AM

problem with mbusd source code
 
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

alireza976 06-13-2011 01:50 AM

when working with usb to serial adapter and cable, mbusd program works without any problem. (/dev/ttyUSB0)
but when working with serial port (/dev/ttyS0) does not work.

In builder site (mbus.sourceforge.net) posted :
Please note that currently mbusd can't operate with RS-232/RS-485 converters with direction switching by RTS pin. Use converters with automatic data direction control (i.e. Moxa Transio series).

why when i use "$ stty -F /dev/ttyS0 speed 19200 cs8 cread" on ttyS0 my mbusd starts working?


All times are GMT -5. The time now is 06:14 PM.