How to use the "ttyTHS1" on deepstream-app?

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?

can you fill below info?

โ€ข Hardware Platform (dGPU) : aws ec2 g4dn.xlarge
โ€ข DeepStream Version ; deepstream_sdk_v4.0.2
โ€ข TensorRT Version : 5.0
โ€ข NVIDIA GPU Driver Version (valid for GPU only) : 440.82

i find answer this error

The error was solved by changing the local pointer to a member.

thankyou mchi

1 Like