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

FIXED - See REPLY

Based on information from Sample to send /receive serial data from RS232 and send it to 3G - Tutorials - mangOH forum

  • 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;

}

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;

}