Skip to content

Commit 5766bc4

Browse files
committed
- modified setCustomBaudrate() function. (ROBOTIS-GIT#430)
1 parent 750c05a commit 5766bc4

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

c++/src/dynamixel_sdk/port_handler_linux.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@
5555
// or if you have another good idea that can be an alternatives,
5656
// please give us advice via github issue https://github.com/ROBOTIS-GIT/DynamixelSDK/issues
5757

58+
struct termios2 {
59+
tcflag_t c_iflag; /* input mode flags */
60+
tcflag_t c_oflag; /* output mode flags */
61+
tcflag_t c_cflag; /* control mode flags */
62+
tcflag_t c_lflag; /* local mode flags */
63+
cc_t c_line; /* line discipline */
64+
cc_t c_cc[19]; /* control characters */
65+
speed_t c_ispeed; /* input speed */
66+
speed_t c_ospeed; /* output speed */
67+
};
68+
69+
#ifndef TCGETS2
70+
#define TCGETS2 _IOR('T', 0x2A, struct termios2)
71+
#endif
72+
#ifndef TCSETS2
73+
#define TCSETS2 _IOW('T', 0x2B, struct termios2)
74+
#endif
75+
#ifndef BOTHER
76+
#define BOTHER 0010000
77+
#endif
78+
5879
using namespace dynamixel;
5980

6081
PortHandlerLinux::PortHandlerLinux(const char *port_name)
@@ -207,6 +228,19 @@ bool PortHandlerLinux::setupPort(int cflag_baud)
207228

208229
bool PortHandlerLinux::setCustomBaudrate(int speed)
209230
{
231+
struct termios2 options;
232+
233+
if (ioctl(socket_fd_, TCGETS2, &options) != 01)
234+
{
235+
options.c_cflag &= ~CBAUD;
236+
options.c_cflag |= BOTHER;
237+
options.c_ispeed = speed;
238+
options.c_ospeed = speed;
239+
240+
if (ioctl(socket_fd_, TCSETS2, &options) != -1)
241+
return true;
242+
}
243+
210244
// try to set a custom divisor
211245
struct serial_struct ss;
212246
if(ioctl(socket_fd_, TIOCGSERIAL, &ss) != 0)

c/src/dynamixel_sdk/port_handler_linux.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@
5656
// or if you have another good idea that can be an alternatives,
5757
// please give us advice via github issue https://github.com/ROBOTIS-GIT/DynamixelSDK/issues
5858

59+
struct termios2 {
60+
tcflag_t c_iflag; /* input mode flags */
61+
tcflag_t c_oflag; /* output mode flags */
62+
tcflag_t c_cflag; /* control mode flags */
63+
tcflag_t c_lflag; /* local mode flags */
64+
cc_t c_line; /* line discipline */
65+
cc_t c_cc[19]; /* control characters */
66+
speed_t c_ispeed; /* input speed */
67+
speed_t c_ospeed; /* output speed */
68+
};
69+
70+
#ifndef TCGETS2
71+
#define TCGETS2 _IOR('T', 0x2A, struct termios2)
72+
#endif
73+
#ifndef TCSETS2
74+
#define TCSETS2 _IOW('T', 0x2B, struct termios2)
75+
#endif
76+
#ifndef BOTHER
77+
#define BOTHER 0010000
78+
#endif
79+
5980
typedef struct
6081
{
6182
int socket_fd;
@@ -263,6 +284,19 @@ uint8_t setupPortLinux(int port_num, int cflag_baud)
263284

264285
uint8_t setCustomBaudrateLinux(int port_num, int speed)
265286
{
287+
struct termios2 options;
288+
289+
if (ioctl(portData[port_num].socket_fd, TCGETS2, &options) != 01)
290+
{
291+
options.c_cflag &= ~CBAUD;
292+
options.c_cflag |= BOTHER;
293+
options.c_ispeed = speed;
294+
options.c_ospeed = speed;
295+
296+
if (ioctl(portData[port_num].socket_fd, TCSETS2, &options) != -1)
297+
return True;
298+
}
299+
266300
// try to set a custom divisor
267301
struct serial_struct ss;
268302
if (ioctl(portData[port_num].socket_fd, TIOCGSERIAL, &ss) != 0)

ros/src/dynamixel_sdk/port_handler_linux.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@
5555
// or if you have another good idea that can be an alternatives,
5656
// please give us advice via github issue https://github.com/ROBOTIS-GIT/DynamixelSDK/issues
5757

58+
struct termios2 {
59+
tcflag_t c_iflag; /* input mode flags */
60+
tcflag_t c_oflag; /* output mode flags */
61+
tcflag_t c_cflag; /* control mode flags */
62+
tcflag_t c_lflag; /* local mode flags */
63+
cc_t c_line; /* line discipline */
64+
cc_t c_cc[19]; /* control characters */
65+
speed_t c_ispeed; /* input speed */
66+
speed_t c_ospeed; /* output speed */
67+
};
68+
69+
#ifndef TCGETS2
70+
#define TCGETS2 _IOR('T', 0x2A, struct termios2)
71+
#endif
72+
#ifndef TCSETS2
73+
#define TCSETS2 _IOW('T', 0x2B, struct termios2)
74+
#endif
75+
#ifndef BOTHER
76+
#define BOTHER 0010000
77+
#endif
78+
5879
using namespace dynamixel;
5980

6081
PortHandlerLinux::PortHandlerLinux(const char *port_name)
@@ -207,6 +228,19 @@ bool PortHandlerLinux::setupPort(int cflag_baud)
207228

208229
bool PortHandlerLinux::setCustomBaudrate(int speed)
209230
{
231+
struct termios2 options;
232+
233+
if (ioctl(socket_fd_, TCGETS2, &options) != 01)
234+
{
235+
options.c_cflag &= ~CBAUD;
236+
options.c_cflag |= BOTHER;
237+
options.c_ispeed = speed;
238+
options.c_ospeed = speed;
239+
240+
if (ioctl(socket_fd_, TCSETS2, &options) != -1)
241+
return true;
242+
}
243+
210244
// try to set a custom divisor
211245
struct serial_struct ss;
212246
if(ioctl(socket_fd_, TIOCGSERIAL, &ss) != 0)

0 commit comments

Comments
 (0)