[FX30S] Use serial port with developer studio

Hello,

I try to read char on the serial port of a FX30S but I have trouble to make it work.

I use the R13.1.3.00.1 firmware :

I have set up the mapping on the serial port ttyHSL0 then reboot the modem (When I ask AT!MAPUART? after a reboot, it’s still “17,0” even if I set 17,1 before):

It looks like it worked when I interrogated the FX30S :

The ttyHSL0 port is no longer considered as disable like it was before I enter the AT command.

Then I use developer studio to write my C application. I use “le_tty.h” functions to configure the serial port :

The followed error message is displayed when I try to launch the app :

“Error opening serial device ‘dev/ttyHSL0’ : No such file or directory found”.

Is the code wrong ?
Do you have an example of programme using the serial port of a FX30S ?

If you need more information, let me know.

Regards,
Dylan Lemasson

Hi Dylan,
The output of the MAPUART query command is correct. There’s some confusion because the set command is , but the query command outputs:

,

In your C application, you’re missing a ‘/’ so try “/dev/ttyHSL0”

Cheers,
Chris

Hi Chris,

I have the same error with the “/”. At least the code is right now.

I have a warning message on the framework version when I build an app, it might come from that ?

Did I miss an update somewhere ?

Regards,
Dylan Lemasson

Hi Dylan,
Try adding the “O_RDWR | O_NOCTTY | O_NDELAY” flags instead of 0.

The warning is normal. Your FX30 is running Legato 16.10.3, but Developer Studio support is currently only up to 16.10.1.

Cheers,
Chris

Hi Chris,

I added the flags (Thanks btw I didn’t know how to use them without an example) but the error is still here.

You can get the program and console logs here : wetransfer.com/downloads/997515 … 339/0b42b6

Regards,
Dylan Lemasson

Hi Dylan,

Try setting sandboxed to false in the adef. Take a look at this posting:

forum.legato.io/t/how-to-send-an … ace/2403/3

BR,
Chris

Hi Chris,

Thanks for the link, it was very helpful.
The problem wasn’t running the app on sandboxed or unsandboxed mode but it was still in the .adef file.

This part was missing to allow read and write access to the serial port :

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

If someone is interested, here is my code to read char on the UART port /dev/ttyHSL0 of a FX30S. It’s probably far from being well optimized but it works and you will get the idea.

.c file :

#include <legato.h>
#include <interfaces.h>
#include <le_tty.h>
#include <string.h>
#include <unistd.h>


COMPONENT_INIT
{
	LE_INFO("begin app");
	const char *serialPort = "/dev/ttyHSL0";
	int port = le_tty_Open(serialPort, O_RDWR |O_NOCTTY);

	//Paramétrage de la communication série
	le_tty_SetBaudRate(port, LE_TTY_SPEED_19200);
	le_tty_SetRaw(port, 1, 2);
	//le_tty_SetFlowControl(port, LE_TTY_FLOW_CONTROL_NONE);
	char *parity = "N";
	le_tty_SetFraming(port, *parity, 8, 1);

	do {
		char buffer[1024];
		int readSerial;
		int i;
		readSerial = read(port, buffer, sizeof(buffer));
		if (readSerial > 0) {
			LE_INFO("Read : %d ", readSerial);
			for (i=0; i < readSerial;i++){
				printf("%02X", buffer[i]);
			}
			printf("\n");
		}
		else {
			printf("Else error, readSerial = %d", readSerial);
		}
	} while (1);
	LE_INFO("end app");
}

.adef file :

executables:
{
	serial = ( serialComponent )
}

processes:
{
	envVars:
	{
		LE_LOG_LEVEL = DEBUG
	}

	run:
	{
		( serial )
	}

	maxCoreDumpFileBytes: 512K
	maxFileBytes: 512K
}

requires:
{
	device:
	{
		// read and write acess to the UART2 port.
		[rw]	/dev/ttyHSL0	/dev/ttyHSL0
	}
}



version: 1.0.0
maxFileSystemBytes: 512K

regards,
Dylan Lemasson
Serial.zip (77.5 KB)

Hi Dylan,
That’s great, glad everything is working. Thanks for sharing.
BR,
Chris