# SerialportCommunication

**URL:** https://forum.legato.io/t/serialportcommunication/3981
**Category:** Uncategorized
**Created:** [January 2, 2019, 11:10am UTC](https://forum.legato.io/t/serialportcommunication/3981 "2019-01-02T11:10:29Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![subrahmaniam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@subrahmaniam](https://forum.legato.io/u/subrahmaniam)
#### Post date: [January 2, 2019, 11:10am UTC](https://forum.legato.io/t/serialportcommunication/3981/1 "2019-01-02T11:10:29Z")

</div>

Hi,  
I am using mangohred 7502 module. i am trying serial port program between host to target . I tried DM COM and all other com ports in terminal in windows. I am using max232 and voltage level shifter yf08E. I mapped uart to 17,1 and i used /dev/hs0 . i am posting the program below. in .adef file i added [rw] /dev/hs0 /dev/hs0 also. I am unable to read/write data from/to the terminal. please guide me to establish communication.  
Thanks and regards,  
K Subrahmaniam

#include “legato.h”  
#include “interfaces.h”  
#include \<le\_tty.h\>  
#include \<unistd.h\>  
#include \<string.h\>

//void uartInit();  
COMPONENT\_INIT  
{  
le\_result\_t result;  
char buffer[20]= “Hello\n”;  
// int readSerial;  
int i=0;  
int len;  
//printf(“hI”);  
const char \*serialport = “/dev/ttyHS0”;

```
int fd = le_tty_Open(serialport, O_RDWR|O_NDELAY|O_NOCTTY|O_NONBLOCK);
if(fd == -1)
    {
    	//LE_FATAL("Error Opening %S err[%d]: %s", SERIAL_PORT,errno,strerror(errno));
    	LE_INFO("failed");
    }
else
	LE_INFO("SUCCESS opening");
    LE_INFO("%d", fd);
 le_tty_SetBaudRate(fd,13);
 char parity = 'N';

 le_tty_SetFraming(fd,parity,8,1);

 result = le_tty_SetCanonical(fd);
 		if(result == LE_OK)
 			LE_INFO("canonical mode is set");

 do
 {

	 LE_INFO("Enter do while loop");
	len = write(fd,buffer,6);
	sleep(2);
 LE_INFO("Number of bytes writen is %d",len);

	// readSerial = read(fd,buffer,sizeof(buffer));
	// LE_INFO("Read bytes are:%d",readSerial );

// LE_INFO(buffer);
	 i++;

	/* if(readSerial > 0)
	 {
		 LE_INFO("Read bytes are:%d",readSerial );
		 for(i=0;i<readSerial;i++)
		 {
			 printf("%c",buffer[i]);
		 }printf("\n");
	 }
	 else
	 {
		 printf("error readSerial = %d\n",readSerial);
	 }*/
 }while(1);
 le_tty_Close(fd);

```

}

---

<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: [January 2, 2019, 11:37am UTC](https://forum.legato.io/t/serialportcommunication/3981/2 "2019-01-02T11:37:45Z")

</div>

Is it ok if you disable the sandbox feature?

---

<div class="post-metadata">

### Author: ![subrahmaniam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@subrahmaniam](https://forum.legato.io/u/subrahmaniam)
#### Post date: [January 2, 2019, 4:30pm UTC](https://forum.legato.io/t/serialportcommunication/3981/3 "2019-01-02T16:30:48Z")

</div>

I tested it with disabling sandbox also please guide me

---

<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: [January 2, 2019, 10:07pm UTC](https://forum.legato.io/t/serialportcommunication/3981/4 "2019-01-02T22:07:21Z")

</div>

What is the result then?

---

<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: [January 3, 2019, 1:13am UTC](https://forum.legato.io/t/serialportcommunication/3981/5 "2019-01-03T01:13:03Z")

</div>

maybe you can have a look on these topics:

> [@How to start UART communication on UART1 port ie pin(8,10) on mangOH red using WP7502?](https://forum.legato.io/t/how-to-start-uart-communication-on-uart1-port-ie-pin-8-10-on-mangoh-red-using-wp7502/3232/24):
>
> this is to route the console to UART1. After reboot, there should be some kernel log coming out from UART1, can you see it?

> [@Legato serial Communication FX30S](https://forum.legato.io/t/legato-serial-communication-fx30s/3287/3):
>
> I think so. The output of the AT!MAPUART? command is this: " AT!MAPUART? !MAPUART: 17,17 OK " As i see in other topics, this is the correct output that permits the use of the ttyHS0 port. Is this correct?

The sample code there should be working with UART.

---

<div class="post-metadata">

### Author: ![subrahmaniam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@subrahmaniam](https://forum.legato.io/u/subrahmaniam)
#### Post date: [January 3, 2019, 9:17am UTC](https://forum.legato.io/t/serialportcommunication/3981/6 "2019-01-03T09:17:07Z")

</div>

Hi,  
I tested with sandbox disabled . I am unable get the data . should i do any mux or binding settings, I connected cf3 to pc. i connected iot connector to connect the serial port. In that iot 12 and 13 pins are used for tx rx pins . form that i give to max232 via vlotage level shifter. i set 17,2 in uart mapping, i used ttyhs0 and tried ttyhsl1 . should i include any bindings or mux ? please guide me  
Thakyou  
K Subrahmaniam

---

<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: [January 3, 2019, 9:58am UTC](https://forum.legato.io/t/serialportcommunication/3981/7 "2019-01-03T09:58:15Z")

</div>

have you tried the application in the link I provide to you?

---

<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: [January 3, 2019, 10:09am UTC](https://forum.legato.io/t/serialportcommunication/3981/8 "2019-01-03T10:09:27Z")

</div>

17,2 uart mapping is for uart2 ,not uart1

---

<div class="post-metadata">

### Author: ![subrahmaniam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@subrahmaniam](https://forum.legato.io/u/subrahmaniam)
#### Post date: [March 20, 2019, 3:18am UTC](https://forum.legato.io/t/serialportcommunication/3981/9 "2019-03-20T03:18:37Z")

</div>

Hi good morning,  
Can you guide me to write http program to get and put . We are getting curl errors . Is http necessary to implement sota . Aiantage apis are also giving errors .  
Thanks and regards,  
K subrahmaniam

---

<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: [March 20, 2019, 6:23am UTC](https://forum.legato.io/t/serialportcommunication/3981/10 "2019-03-20T06:23:00Z")

</div>

you can try the sample application httpGet.
