I am using WP8548 UART 1 & 2 ports to communicate with two sensors . The serial communication is for polling Modbus parameter registers 3 times in 30 sec delay.The polled data is then uploaded to Airvantage cloud.
In my code I am using tty channels as mentioned below-
#define UART1 “/dev/ttyHS0” // Aquagate Serial Port 1
#define UART2 “/dev/ttyHSL1” //Aquagate Serial Port 2
port setup code-
static void setupSerialUART_MOdbus(char * port)
{
// Open the serial port.
fd = open(port, O_RDWR| O_NONBLOCK | O_NDELAY ); //Debug port
if (fd == -1)//check if device opened properly
{
LE_INFO(“AutoWPtoAV:Open failed with error no: %d (%m)”, errno);
}
else
{
struct termios options; //config structure
if( tcgetattr(fd , &options) != 0)
{
LE_INFO(“AutoWPtoAV:Read attributes failed with error no: %d (%m)”, errno);
}
/* Set Baud Rate */
if(!strcmp(port,UART1)){
cfsetispeed (&options, B19200);
cfsetospeed (&options, B19200);
LE_INFO(“Opened Aquagate UART1 with 9600 baud rate”);
}
else if(!strcmp(port,UART2)){
cfsetispeed (&options, B19200);
cfsetospeed (&options, B19200);
LE_INFO(“Opened Aquagate UART2 with 19200 baud rate”);
}
/* Setting other Port Stuff */
// Disable break and EOL character conversions.
options.c_iflag &= ~(BRKINT | IGNCR | INLCR | ICRNL);
// Disable canonical, signal handling and local echo.
options.c_lflag &= ~(ICANON | IEXTEN | ISIG | ECHO);
// Disable post-processing and character conversion.
options.c_oflag &= ~(OPOST | ONLCR | OCRNL);
options.c_cflag &= ~PARENB; // Make 8n1
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cflag &= ~CRTSCTS; // no flow control
options.c_cc[VMIN] = 1; // read doesn’t block : Interchar timer used
options.c_cc[VTIME] = 5; // 1 seconds read timeout : Inter character timeout (TIME is exceeded (t = TIME *0.1 s).
options.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
cfmakeraw(&options); // Make raw
tcflush( fd, TCIFLUSH ); //Flush Port, then applies attributes
if( tcsetattr(fd ,TCSANOW , &options) != 0)
{
LE_INFO(“AutoWPtoAV:Set attributes failed with error no: %d (%m)”, errno);
}
}
// Create a File Descriptor Monitor object for the serial port’s file descriptor.
// Monitor for data available to read.
fdSerial = le_fdMonitor_Create(“Serial Port”, // Name for diagnostics
fd, // fd to monitor
SerialPortHandler, // Handler function
POLLOUT); // Monitor readability
}
when I am running my legato App code for UART polling with USB connected to my PC (Developer Studio), I am able to receive data from both the UART (1 & 2) without any problems.
but when I am disconnecting USB from PC and running the same code, I am missing data from WP8548 UART2, same time UART 1 is working normally.
I had already configured both wp8548 UART’s for Linux applications.
My Current WP8548 UART Configuration
How do I can access my UART 2 of wp8548 same as USB connected even when USB is disconnected from PC…?
Do I need to configure UART 2 differently…?