Reading from UART fails

Hi All,
Im trying to read a buffer from uart port.I can able to write a buffer. For that ill be getting a response back. But i couldnt able to read that respose through the UARt. Read operation fails everytime. this is my code and trace im getting backwhile running the program. Please let me know why the read operation is getting failed everytime. Im using FX100 modem to connect through the external UART device. Which will be replying “06” as response for the command :: written to the UART port.

#include “adl_global.h”
#include “generated.h”
#include “adl_OpenDevice.h”
#include “wm_uart.h”
#include “adl_traces.h”

static psGItfCont_t uart_if;
static u32 uart1_hdl;
void* ptrbuff = “::”;
void* rx_buf;

void main_task(void) {
sUartSettings_t settings;
sUartLc_t line_coding;
// Set the line coding parameters
u8 write_ret, read_ret;
line_coding.valid_fields = UART_LC_STOP;
line_coding.rate = (eUartRate_t)( UART_RATE_USER_DEF | 4800 );
line_coding.stop = UART_STOP_BIT_1; = UART_DATALENGTH_7;
line_coding.parity = UART_PARITY_EVEN;
// UART2 will be opened in NULL MODEM role / with synchronous read/write
settings.identity = “UART1”;
settings.role = UART_ROLE_NM;
settings.capabilities = NULL;
settings.event_handlers = NULL;
//settings.interface = &pinterface1;
settings.interface = &uart_if;
settings.line_coding = &line_coding;
uart1_hdl = adl_OpenDevice( DF_UART_CLID, &settings );
if( !uart1_hdl ){
adl_atSendResponse ( ADL_AT_UNS, “\r\nNOT OPENED\r\n” );
TRACE((1,“UART is not opened”));
adl_atSendResponse ( ADL_AT_UNS, “\r\nOPENED UART DEVICE\r\n” );
TRACE((2,“UART is opened”));

   write_ret = uart_if->write(uart1_hdl,ptrbuff, 2);

   if (write_ret == CH_STATUS_NORMAL) {
	   DUMP (3,ptrbuff,wm_strlen(ptrbuff));
	   TRACE ((3,"Write Successful"));
   else {
	   TRACE ((4,"Write failed"));

   DUMP (5,rx_buf,sizeof(rx_buf));

   read_ret = uart_if->read(uart1_hdl,rx_buf,wm_strlen(rx_buf));

   if (read_ret == CH_STATUS_NORMAL) {
  		   DUMP (6,rx_buf,sizeof(rx_buf));
   else {
  		   TRACE ((7,"read failed"));

   DUMP (8,ptrbuff,wm_strlen(ptrbuff));
   DUMP (9,rx_buf,sizeof(rx_buf));

   if(rx_buf == 6){
	   TRACE((10,"ack received"));
	   adl_atSendResponse( ADL_AT_UNS, "\r\n ack received\r\n" );
   else {
	   TRACE((10,"ack Not received"));
	   adl_atSendResponse( ADL_AT_UNS, "\r\nack Not received\r\n" );

Traces are:
2014/09/30;19:54:28:417;001;ADL;1;Binary header at 10700000
2014/09/30;19:54:28:417;002;ADL;16;[ADL PORT] subs (107028B1) : 0
2014/09/30;19:54:28:420;001;ADL;16;[ADL PORT] subs (10704549) : 1
2014/09/30;19:54:28:421;001;ADL;22;[ADL] flash subs 2 : -4
2014/09/30;19:54:28:421;002;ADL;22;Flh Obj 0000 Len : 4
2014/09/30;19:54:28:422;001;ADL;22;Read Flh Obj 0000 (4) : 0
2014/09/30;19:54:28:429;001;ADL;16;[ADL PORT] event : 0 (port 80 ; state 0)
2014/09/30;19:54:28:430;001;ADL;16;[ADL PORT] event : 0 (port 03 ; state 0)
2014/09/30;19:54:28:431;001;ADL;22;Flh Obj 0000 Len : 4
2014/09/30;19:54:28:431;002;ADL;16;[ADL PORT] unsubs (1) : 0
2014/09/30;19:54:28:431;003;ADL;2;UART is opened
2014/09/30;19:54:28:432;001;ADL;3;3A 3A
2014/09/30;19:54:28:432;002;ADL;3;Write Successful
2014/09/30;19:54:30:221;001;ADL;5;00 00 00 00
2014/09/30;19:54:30:222;001;ADL;7;read failed
2014/09/30;19:54:30:223;001;ADL;8;3A 3A
2014/09/30;19:54:30:223;002;ADL;9;00 00 00 00
2014/09/30;19:54:30:223;003;ADL;10;ack Not received

Please help me regarding this…
Thanks in advance.


Can you output the response value of ‘read_ret’ in you code at this line:

TRACE ((7,"read failed"));

Also, the open UART stuff is event driven - so you need to set up the event handlers etc as per the sample in Dev Studio. You may be getting the error because there is nothing in the buffer to read.

The documentation for OpenUART is a bit sparse and cryptic unfortunately, but I recommend that you go through the example code provided and see how they’re doing the event handling.

ciao, Dave

p.s. Please use the CODE tags to mark-up your example code - it makes it a lot easier for the rest of us to read.