AnsweredAssumed Answered

Sensor data reading thr. UART

Question asked by Tsung-Fang Tu on Jul 16, 2012
Latest reply on Jul 19, 2012 by Martin Kojtal

Dear All,

 

Our environment are: CW10.2 / MQX3.8 / TWR-K60N512+TWR-SER. We are working on a project which should connect a sensor to the TWR-SER and read dara thr. RS485 interface.

 

Before the mqx software implementation, we consulted a hardware engineer to confirm the connection is working. Based on his suggestion(he confirmed the RS485 on TWR-SER is RS422, which is not compatible w. the RS485 on the sensor), we config theTWR-SER to RS232 and add a RS232-RS485 converter. The whole set passed the communication testing w. a PC.

 

Then we connect the sensor to TWR-SER(thr. the RS232-RS485 converter) and try to read the data. A 4-byte command should be sent to the sensor then a 12-byte data will be automatically replied. Unfortunately, below simple codes doesn't work, we don't get the correct data format in the rxbuff:

 

ret = _io_write(uart_dev, command, 4);
printf("_io_write ret = %d\n", ret);

ret = _io_read (uart_dev, rxbuff, 12);
printf("_io_read ret = %d\n", ret);
printf("rxbuff = %s\n", rxbuff);

 

However, we parallely connect the sensor to PC, the correct data can be read on a terminal, which means the write command through above code (execute in CW debug mode) is working but failed on read command. A friend comments we should read the buffer immediately after the write command, the read command is too late, but we don't know how it implement in mqx.

 

Any suggestion or comment is highly appreciated!

 

-tftu

Outcomes