larry1
July 26, 2022, 7:58am
1
Hi,
I want to use legato API to read ttyUSB0, but i can’t open ttyUSB0.
#include “legato.h”
#include “le_tty.h”
COMPONENT_INIT
{
int SerialPortFd = -1;
int ret = 0 , num_ret = 0;
char buf[1024] = {0};
SerialPortFd = le_tty_Open("/dev/ttyUSB0" , O_RDWR | O_NOCTTY | O_NDELAY );
...
}
Error log
I can find my device like below:
I don’t know why!
jyijyi
July 26, 2022, 8:14am
2
are you using unsandboxed legato application?
larry1
July 26, 2022, 8:19am
3
jyijyi:
unsandboxed
Hi @jyijyi ,
I can’t understand what is “unsandboxed” ?
I follow APP doc to write myAPP.
jyijyi
July 26, 2022, 8:21am
4
if it is sandboxed, it cannot see there is /dev/ttyUSB0.
you need to go to .adef and add:
sandboxed: false
If you still want to use sandboxed feature, you can see this application note:
In .cdef, you need to add something like:
requires:
{
device:
{
[rw] /dev/ttyHSL1 /dev/ // WP UART2 mangOH debug Console
[rw] /dev/ttyHS0 /dev/ // WP UART2 or IoT Connector UART
// [rw] /dev/ttyHSL0 /dev/ // FX30S UART
}
}
larry1
July 26, 2022, 8:33am
5
Hi @jyijyi ,
Thanks for your help.
I fixed the problem.
may I have other question about print log?
I want to use “printf” to print log on console, but it seems not work.
larry1
July 26, 2022, 9:08am
7
Hi @jyijyi ,
Thanks for your help. I will read it.
Now I try to read ttyUSB0 like
num_ret = read(SerialPortFd, buf, sizeof(buf));
usleep ((7 + 25) * 1000);
buf[num_ret+1] = ‘\0’;
if (num_ret > 0) {
LE_ERROR(“read result: %s \n”, buf, num_ret);
sprintf(cmd, “echo "%s" > /tmp/test.log”,buf);
system(cmd);
}
I can see the length > 0, but i can’t get the string
but I can use “cat” to get result.
Why?
jyijyi
July 26, 2022, 9:12am
8
why don’t you print it out in LE_INFO()?
you can print the %i instead of %s as there might be NULL character
larry1
July 27, 2022, 1:51am
9
Hi @jyijyi
I got a error from update but I can’t find the detail log, please help me
jyijyi
July 27, 2022, 1:54am
10
Not sure if you compiled with the correct legato version…
you can try with a simple helloworld application first which should be able to download to the module.
If it works, port the code to it line by line and see which line makes the update failed.
larry1
July 27, 2022, 2:07am
11
Hi @jyijyi ,
I used it yesterday, but it can’t work now
jyijyi
July 27, 2022, 2:11am
12
does “logread” command show any reason on this?
I never see this before, maybe you need to redownload FW?
larry1
July 27, 2022, 7:21am
13
Hi @jyijyi ,
I fixed it, I have other question about read result,
I use “stty” to set the com port and use “cat” to read result like below:
But I use API it can not get the result.
SerialPortFd = le_tty_Open(“/dev/ttyUSB0” , O_RDWR);
ret = le_tty_SetBaudRate(SerialPortFd, LE_TTY_SPEED_1152000);
ret = le_tty_SetFraming(SerialPortFd, ‘N’, 8, 1);
ret = le_tty_SetRaw(SerialPortFd, 0, 0);
…
num_ret = read(SerialPortFd, buf, sizeof(buf));
Is my setting the same as “stty” ?
Please help me thanks.
jyijyi
July 27, 2022, 7:39am
14
The easiest way is you use unsandboxed legato app, and run system(“cat /dev/ttyUSB0 > /tmp/test.txt”)
After you can read the file in your app
larry1
July 27, 2022, 7:51am
15
jyijyi:
After
But I don’t want to use “cat” because I want to save the result in the buffer.
jyijyi
July 27, 2022, 7:58am
16
You can read the content of the file and save the result in your buffer…
BTW, you can try this UART_TEST1 app and see if it works on your environment:
Yes I know, but Sierra requested whether R17 ioctrl() worked correctly as customer’s requirement. This is customer validation status. So we would like to know whether issue was caused by either source code or yocto FW. Sorry for inconvenient you,...
larry1
July 27, 2022, 8:17am
17
Hi @jyijyi ,
I think read and write the same file that is a problem in multi thread.
I will ty UART_Test1.rar
larry1
July 28, 2022, 3:25am
18
Hi @jyijyi ,
I tested UART_Test1.rar and I got some conclusions.
I only use OpenPort(), then it doesn’t work.
I only use le_tty_xxx API to setup and open, the it doesn’t work too.
I use OpenPort() + le_tty_SetRaw(), then it worked, so I want to know what diffrernt between le_tty_SetRaw and OpenPort() to set RAW step ?
Thanks!
jyijyi
July 28, 2022, 3:32am
19
I think it related to c_iflag, c_lflag and c_oflag of the port setting.
you can see the source code of le_tty_SetRaw() here:
//--------------------------------------------------------------------------------------------------
/**
* @file tty.c
*
* Routines for dealing with serial ports. Port configuration, simple reads and writes are handled
* here.
*
* Copyright (C) Sierra Wireless Inc.
*/
//--------------------------------------------------------------------------------------------------
#include "legato.h"
#include "smack.h"
#include "fileDescriptor.h"
#include "le_tty.h"
#include <termios.h>
// ==============================================
// PRIVATE DATA
// ==============================================
This file has been truncated. show original
larry1
July 28, 2022, 6:12am
20
Hi @jyijyi ,
Thanks for your help and I keep try to find out which settings will affect.
And I have other question.
I can’t use printf to print to my ssh window by following hello1.rar, I use command “app runProc XXX XXX --exe=XXX” but I still can see the log in “logread”.
I print log to LE_INFO, my question is that function have limit ? because I saw the log and check string length is 162 but it doesn’t show all the string.