# How to send and receive data using UART2 (RS232) interface

**URL:** <https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [April 1, 2017, 6:25am UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403 "2017-04-01T06:25:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [April 1, 2017, 6:25am UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403/1 "2017-04-01T06:25:18Z")

</div>

Hi  
I am having mangOH green board (WP8548) with legato Developer studio 5  
I want to send and receive some data through UART2 (from RS232 terminal)  
Which api need to be used in Developer studio or any sample code for Uart2 communication ?

---

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [April 1, 2017, 11:30am UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403/2 "2017-04-01T11:30:18Z")

</div>

Hi,  
I am using le\_tty api for uart communication.  
out of these api, first I am using le\_tty\_open() method and then other api methods to set all baudrate, flow control, parity, stop bits etc.  
after that I have used write method to send data and read to receive data.

But my application get stopped at

> le\_tty\_Open(“/dev/ttyHSL1”,O\_RDWR);

with error:

> LE\_FILENAME le\_tty\_Open() 231 | Error opening serial device ‘/dev/ttyHSL1’: No such file or directory

I have also tried with /dev/ttyAT , but same error.  
I have also tried below command on terminal and then executed application, but same error persist.

> echo -e “AT!MAPUART=17,1\r” \> /dev/ttyAT  
> reboot

where I am doing wrong ? please suggest me solution

---

<div class="post-metadata">

**Author:** ![raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@raf](https://forum.legato.io/u/raf)\
**Post date:** [April 2, 2017, 11:59pm UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403/3 "2017-04-02T23:59:34Z")

</div>

Hi @rups

If you’re running the app as ‘sandboxed’, you will need to request read/write acces to the device in your `.adef` file.

```auto
requires:
{
    device:
    {
        // read and write access to the UART2 port.
        [rw] /dev/ttyHSL1 /dev/ttyHSL1
    }
}

```

Alternately, you can try running the app unsandboxed:

```auto
sandboxed: false

```

Cheers,  
Raf

---

<div class="post-metadata">

**Author:** ![Kalai](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kalai/32/1135_2.png) [@Kalai](https://forum.legato.io/u/Kalai)\
**Post date:** [August 11, 2021, 8:14am UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403/4 "2021-08-11T08:14:47Z")

</div>

HI,  
I can able to Transmit and receive data over Uart , i need a sample code to send a file over UART any once can guide me How to transmit a file ove UART

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [August 11, 2021, 9:12am UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403/5 "2021-08-11T09:12:22Z")

</div>

You can use attached lrz binary.  
Here is an example to transfer file via UART console:

1. transfer this lrz binary to /tmp of module by WINSCP
2. cd /tmp; chmod 777 ./lrz;
3. ./lrz -X cwe \</dev/ttyHSL1 \>/dev/ttyHSL1
4. In tera term, File → Transfer → XMODEM → tick 1K box → choose the file you want to transfer.
5. the file will be in /tmp with filename “cwe”.

[lrz](https://forum.legato.io/uploads/short-url/AoG97UPbPfQ2xS4vgYQKO4AQz2A) (202.7 KB)

---

<div class="post-metadata">

**Author:** ![Kalai](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/kalai/32/1135_2.png) [@Kalai](https://forum.legato.io/u/Kalai)\
**Post date:** [August 11, 2021, 9:50am UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403/6 "2021-08-11T09:50:54Z")

</div>

Through C program how can we send a file ???

---

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [August 11, 2021, 9:54am UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403/7 "2021-08-11T09:54:30Z")

</div>

@Kalai ,

From your question do I understand it correctly that you are looking for a basic C program to read and write to UART 2 in that case you can check the below link for a basic program [Serial Port Programming on Linux | xanthium enterprises](https://www.xanthium.in/Serial-Port-Programming-on-Linux)

For using UART 2 in linux application you will need to configure it with AT!MAPUART=17,2 and then reset the device and use the correct /dev/ttyHS1 port in your C Code.

Hope this helps

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [August 11, 2021, 10:00am UTC](https://forum.legato.io/t/how-to-send-and-receive-data-using-uart2-rs232-interface/2403/8 "2021-08-11T10:00:40Z")

</div>

you can refer to the source code of lrz and port to your code.

> <https://github.com/jnavila/lrzsz/blob/master/src/lrz.c>

Or you can use system() API to call the lrz binary program.
