# \[Solved\]UART project question - solved, with example code

**URL:** <https://forum.legato.io/t/solved-uart-project-question-solved-with-example-code/2935>\
**Category:** Legato Application Framework\
**Created:** [January 5, 2018, 7:25pm UTC](https://forum.legato.io/t/solved-uart-project-question-solved-with-example-code/2935 "2018-01-05T19:25:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![griggs](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@griggs](https://forum.legato.io/u/griggs)\
**Post date:** [January 5, 2018, 7:25pm UTC](https://forum.legato.io/t/solved-uart-project-question-solved-with-example-code/2935/1 "2018-01-05T19:25:11Z")

</div>

FIXED - See REPLY

Based on information from [http://forum.mangoh.io/t/sample-to-send-receive-serial-data-from-rs232-and-send-it-to-3g/285](http://forum.mangoh.io/t/sample-to-send-receive-serial-data-from-rs232-and-send-it-to-3g/285)

- The .adef is modified to call out /dev/ttyHS0 as a required device
- at!mapuart? shows UART1 is in fact mapped as a Linux app device
- The base Legato is 17.11
- The code is based on the sample app httpGet, and the 3G works fine
- The callback handler is very much being called

but still no output to UART1 I can see. Note that ttyHSL0 becomes ttyHS0 if you map UART1 to be a Linux port.

## See Reply Below.

static size\_t PrintCallback  
(  
void \*bufferPtr,  
size\_t size,  
size\_t nbMember,  
void \*userData // unused, but can be set with CURLOPT\_WRITEDATA  
)  
{  
int tty0;  
int errcd;  
//const char \* mytxt =“TTYWRITE”;

```
tty0 = open("/dev/ttyHS0", O_RDWR | O_NOCTTY | O_NDELAY);
printf("Succesfully received data:\n");
printf("%d byte, nmembdat %d\n",size,nbMember);
printf ((char*)bufferPtr);
printf("==================================\n");

```

// fwrite(bufferPtr, size, nbMember, stdout);  
fwrite(bufferPtr, size, nbMember, stdout);  
errcd = write (tty0,“TTYWRITE\n”, 9);  
if (errcd \<0){  
LE\_ERROR(“port write error %d\n”,errcd);  
}

```
close (tty0);
return size * nbMember;

```

}

---

<div class="post-metadata">

**Author:** ![griggs](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@griggs](https://forum.legato.io/u/griggs)\
**Post date:** [January 5, 2018, 8:22pm UTC](https://forum.legato.io/t/solved-uart-project-question-solved-with-example-code/2935/2 "2018-01-05T20:22:49Z")

</div>

Got it. Misdefinition in the open.

If anybody wants to use this as an example, go for it. it is taking data from 3G callback handler in httpGet sample app, write to terminal port.

* * *

static size\_t PrintCallback  
(  
void \*bufferPtr,  
size\_t size,  
size\_t nbMember,  
void _userData // unused, but can be set with CURLOPT\_WRITEDATA  
)  
{  
int tty0;  
int errcd;  
// tty0 = open(“/dev/ttyHS0”, O\_RDWR | O\_NOCTTY | O\_NDELAY);  
tty0 = open(“/dev/pts/0”, O\_RDWR | O\_NOCTTY | O\_NDELAY);  
printf(“Succesfully received data:\n”);  
printf(“%d byte, nmembdat %d\n”,size,nbMember);  
printf ((char_)bufferPtr);  
printf(“==================================\n”);  
fwrite(bufferPtr, size, nbMember, stdout);  
errcd = write (tty0,bufferPtr, nbMember);  
if (errcd \<0){  
LE\_ERROR(“port write error %d\n”,errcd);  
}

```
close (tty0);
return size * nbMember;

```

}
