Hi
i make a terminal.h file and i did include in deepstream_app_main.c
#include <gst/gst.h>
#include <termios.h>
#include <fcntl.h>
struct termios newtio;
char sbuff[1024];
int terminalfd;
gboolean terminal_init();
gboolean terminal_close();
gboolean terminal_write();
int terminal_read(char *buff);
gboolean terminal_init(){
terminalfd = open("/dev/ttyTHS1", O_RDWR | O_NONBLOCK | O_NOCTTY );
if(terminalfd < 0 )
{
g_print("terminal Error\n");
return FALSE;
}
memset( &newtio, 0, sizeof(newtio) );
newtio.c_cflag = B115200; // ํต์ ์๋ 115200
newtio.c_cflag |= CS8; // ๋ฐ์ดํฐ ๋นํธ๊ฐ 8bit
newtio.c_cflag |= CLOCAL; // ์ธ๋ถ ๋ชจ๋์ ์ฌ์ฉํ์ง ์๊ณ ๋ด๋ถ ํต์ ํฌํธ ์ฌ์ฉ
newtio.c_cflag |= CREAD; // ์ฐ๊ธฐ๋ ๊ธฐ๋ณธ, ์ฝ๊ธฐ๋ ๊ฐ๋ฅํ๊ฒ
newtio.c_iflag = 0; // parity ๋นํธ๋ ์์
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 0;
tcflush (terminalfd, TCIFLUSH );
tcsetattr(terminalfd, TCSANOW, &newtio ); // ํฌํธ์ ๋ํ ํต์ ํ๊ฒฝ์ ์ค์ ํฉ๋๋ค.
//close(fd);
return TRUE;
}
gboolean terminal_close(){
if(terminalfd < 0)
{
g_print("terminal already closed\n");
return FALSE;
}
close(terminalfd);
return TRUE;
}
gboolean terminal_write(char *data, unsigned int length){
if(terminalfd < 0)
{
g_print("terminal Error\n");
return FALSE;
}
write(terminalfd, data, length);
g_print("send : %s\n ", data);
}
gboolean terminal_read(char *buff){
if(terminalfd < 0)
{
g_print("terminal Error\n");
return -1;
}
int bytes = read(terminalfd, buff, 4);
g_print("can read length = %d \n", bytes);
if(bytes < 0)
{
return 0;
}
g_print("recv(%d) : ", bytes);
for(int i = 0 ; i < bytes ; ++i)
{
g_print("%c", buff[i]);
}
g_print("\n");
return 1;
}
and add new event g_timeout_add (1000, event_thread_terminal_test, NULL);
static gboolean event_thread_terminal_test (gpointer arg)
{
terminal_write(โtestโ, 4);char *buff;
terminal_read(buff);
g_print(โcheck\nโ);
return TRUE;
}
There is no problem when writing, but the segment failure error occurs as soon as the data is read and the program ends.
How can UART Serial communicate in deepstream-app?