Baud definitions (B9600 for example) are again encoded; Now supports the BOTHER settings which allows specifying the baud via c_ispeed and c_ospeed termios fields
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4970 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
6071b29253
commit
713497f886
@ -24,15 +24,6 @@ config MB_TCP_ENABLED
|
|||||||
depends on MODBUS
|
depends on MODBUS
|
||||||
default y
|
default y
|
||||||
|
|
||||||
config MB_TERMIOS
|
|
||||||
bool "Driver TERMIOS supported"
|
|
||||||
depends on MB_ASCII_ENABLED || MB_RTU_ENABLED
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Serial driver supports termios.h interfaces (tcsetattr, tcflush, etc.).
|
|
||||||
If this is not defined, then the terminal settings (baud, parity, etc).
|
|
||||||
are not configurable at runtime; serial streams will not be flushed when closed.
|
|
||||||
|
|
||||||
config MB_ASCII_TIMEOUT_SEC
|
config MB_ASCII_TIMEOUT_SEC
|
||||||
int "Character timeout"
|
int "Character timeout"
|
||||||
depends on MB_ASCII_ENABLED
|
depends on MB_ASCII_ENABLED
|
||||||
|
@ -60,10 +60,6 @@ The NuttX-named configuration options that are available include:
|
|||||||
CONFIG_MB_ASCII_ENABLED - Modbus ASCII support
|
CONFIG_MB_ASCII_ENABLED - Modbus ASCII support
|
||||||
CONFIG_MB_RTU_ENABLED - Modbus RTU support
|
CONFIG_MB_RTU_ENABLED - Modbus RTU support
|
||||||
CONFIG_MB_TCP_ENABLED - Modbus TCP support
|
CONFIG_MB_TCP_ENABLED - Modbus TCP support
|
||||||
CONFIG_MB_TERMIOS - Serial driver supports termios.h interfaces (tcsetattr,
|
|
||||||
tcflush, etc.). If this is not defined, then the terminal settings (baud,
|
|
||||||
parity, etc.) are not configurable at runtime; serial streams will not be
|
|
||||||
flushed when closed.
|
|
||||||
CONFIG_MB_ASCII_TIMEOUT_SEC - Character timeout value for Modbus ASCII. The
|
CONFIG_MB_ASCII_TIMEOUT_SEC - Character timeout value for Modbus ASCII. The
|
||||||
character timeout value is not fixed for Modbus ASCII and is therefore
|
character timeout value is not fixed for Modbus ASCII and is therefore
|
||||||
a configuration option. It should be set to the maximum expected delay
|
a configuration option. It should be set to the maximum expected delay
|
||||||
@ -106,6 +102,13 @@ The NuttX-named configuration options that are available include:
|
|||||||
CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED - If the Read/Write Multiple
|
CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED - If the Read/Write Multiple
|
||||||
Registers function should be enabled.
|
Registers function should be enabled.
|
||||||
|
|
||||||
|
See also other serial settings, in particular:
|
||||||
|
|
||||||
|
CONFIG_SERIAL_TERMIOS - Serial driver supports termios.h interfaces (tcsetattr,
|
||||||
|
tcflush, etc.). If this is not defined, then the terminal settings (baud,
|
||||||
|
parity, etc.) are not configurable at runtime; serial streams will not be
|
||||||
|
flushed when closed.
|
||||||
|
|
||||||
Note
|
Note
|
||||||
====
|
====
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
# include <termios.h>
|
# include <termios.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ static uint8_t ucBuffer[BUF_SIZE];
|
|||||||
static int uiRxBufferPos;
|
static int uiRxBufferPos;
|
||||||
static int uiTxBufferPos;
|
static int uiTxBufferPos;
|
||||||
|
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
static struct termios xOldTIO;
|
static struct termios xOldTIO;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ void vMBPortSerialEnable(bool bEnableRx, bool bEnableTx)
|
|||||||
|
|
||||||
if (bEnableRx)
|
if (bEnableRx)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
(void)tcflush(iSerialFd, TCIFLUSH);
|
(void)tcflush(iSerialFd, TCIFLUSH);
|
||||||
#endif
|
#endif
|
||||||
uiRxBufferPos = 0;
|
uiRxBufferPos = 0;
|
||||||
@ -112,9 +112,8 @@ bool xMBPortSerialInit(uint8_t ucPort, uint32_t ulBaudRate,
|
|||||||
char szDevice[16];
|
char szDevice[16];
|
||||||
bool bStatus = true;
|
bool bStatus = true;
|
||||||
|
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
struct termios xNewTIO;
|
struct termios xNewTIO;
|
||||||
speed_t xNewSpeed;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
snprintf(szDevice, 16, "/dev/ttyS%d", ucPort);
|
snprintf(szDevice, 16, "/dev/ttyS%d", ucPort);
|
||||||
@ -125,7 +124,7 @@ bool xMBPortSerialInit(uint8_t ucPort, uint32_t ulBaudRate,
|
|||||||
szDevice, errno);
|
szDevice, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
else if (tcgetattr(iSerialFd, &xOldTIO) != 0)
|
else if (tcgetattr(iSerialFd, &xOldTIO) != 0)
|
||||||
{
|
{
|
||||||
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't get settings from port %s: %d\n",
|
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't get settings from port %s: %d\n",
|
||||||
@ -163,35 +162,20 @@ bool xMBPortSerialInit(uint8_t ucPort, uint32_t ulBaudRate,
|
|||||||
bStatus = false;
|
bStatus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ulBaudRate)
|
|
||||||
{
|
|
||||||
case 9600:
|
|
||||||
xNewSpeed = B9600;
|
|
||||||
break;
|
|
||||||
case 19200:
|
|
||||||
xNewSpeed = B19200;
|
|
||||||
break;
|
|
||||||
case 38400:
|
|
||||||
xNewSpeed = B38400;
|
|
||||||
break;
|
|
||||||
case 57600:
|
|
||||||
xNewSpeed = B57600;
|
|
||||||
break;
|
|
||||||
case 115200:
|
|
||||||
xNewSpeed = B115200;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bStatus = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bStatus)
|
if (bStatus)
|
||||||
{
|
{
|
||||||
if (cfsetispeed(&xNewTIO, xNewSpeed) != 0)
|
/* Set the new baud using the (non-standard) BOTHER mechanism
|
||||||
{
|
* supported by NuttX.
|
||||||
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n",
|
*/
|
||||||
ulBaudRate, errno);
|
|
||||||
}
|
xNewTIO.c_ispeed = (speed_t)ulBaudRate;
|
||||||
else if (cfsetospeed(&xNewTIO, xNewSpeed) != 0)
|
xNewTIO.c_ospeed = (speed_t)ulBaudRate;
|
||||||
|
|
||||||
|
/* NOTE: In NuttX, cfset[i|o]speed always return OK. Failures will
|
||||||
|
* only be reported when tcsetattr() is called.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (cfsetispeed(&xNewTIO, BOTHER) != 0 || cfsetospeed(&xNewTIO, BOTHER) != 0)
|
||||||
{
|
{
|
||||||
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n",
|
vMBPortLog(MB_LOG_ERROR, "SER-INIT", "Can't set baud rate %ld for port %s: %d\n",
|
||||||
ulBaudRate, szDevice, errno);
|
ulBaudRate, szDevice, errno);
|
||||||
@ -231,7 +215,7 @@ void vMBPortClose(void)
|
|||||||
{
|
{
|
||||||
if (iSerialFd != -1)
|
if (iSerialFd != -1)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_MB_TERMIOS
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
(void)tcsetattr(iSerialFd, TCSANOW, &xOldTIO);
|
(void)tcsetattr(iSerialFd, TCSANOW, &xOldTIO);
|
||||||
#endif
|
#endif
|
||||||
(void)close(iSerialFd);
|
(void)close(iSerialFd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user