Weird ioctl behaviour in a linux program called using system()
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have a C program that allows setting a custom baud rate on a serial device.
It uses ioctl() to do so under linux, but its behavior is different when I use it under matlab, compared to a standard invocation from my terminal.
set_baud.c
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stropts.h>
#include <asm/termios.h>
int main(int argc, char* argv[]) {
if (argc != 2) {
printf("Usage: %s <serial device>", argv[0]);
return 1;
}
int fd = open(argv[1], O_RDWR);
int speed = 31250;
struct termios2 tio;
ioctl(fd, TCGETS2, &tio);
tio.c_cflag &= ~CBAUD;
tio.c_cflag |= BOTHER;
tio.c_ispeed = speed;
tio.c_ospeed = speed;
int r = ioctl(fd, TCSETS2, &tio);
close(fd);
return r;
}
relevant matlab line
serial_port = '/dev/ttyUSB1';
system('gcc set_baud.c -o set_baud');
system(['./set_baud ' serial_port]);
When calling it from matlab, a baud rate of 38400 (which is a default baud rate) is set, while calling it from my terminal sets the correct one.
I still have to run strace to it, is anybody aware of a reason for this?
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Install Products en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!