Uart works via example not via ardupilot code

Hi,

i’m trying to write a module for IBus telemetry via telemetry uart/port 2.

First step is to see that I can read out the discovery message from the IBus device (FS-I6AB).
I started with adapting the uart example and put in the setup:

hal.uartD->begin(115200);

and in the loop function:

while (hal.uartD->available())
{
uint8_t val = hal.uartD->read();
hal.console->printf(“%X\n”,val);
}
hal.scheduler->delay(1);

This works well and I can see the correct hex discovery messages from the FS-I6AB.

I created a new module AP_IBus_Telemetry (took some example code from AP_Devo_Telem).
I added a new serial protocol and configured it.
The serial manager finds the protocol and provides me the UARTDriver uartD (I named the variable _port).
When I do the same as in the example:

void AP_IBus_Telem::init()
{
hal.uartD->begin(115200);
hal.scheduler->register_timer_process(FUNCTOR_BIND_MEMBER(&AP_IBus_Telem::loop, void));
}

void AP_IBus_Telem::loop(){

    if (hal.uartD == nullptr) {
    // that UART doesn't exist on this platform
        hal.console->println("AP_IBus_Telem: uart issue");
    return;
    }
    if (hal.uartD->available())
    {
        uint8_t val = hal.uartD->read();
        hal.console->printf("%X\n",val);
    }

}

It only returns “FF” multiple times but not my discovery messages.

Any idea what i’m doing wrong?

Thanks in advance for the help.

Can you share your branch? The discord is a great place to get dev help. https://discord.gg/6EjhBhj6

1 Like

I created an account on discord, but it seems i don’t have rights to post a message in the channel.

I got it working now. I moved the _port->begin(115200) from the init function towards the loop function and used a thread.

Maybe some other process sets the baud rate to something else… not sure why it didn’t worked before.

rather than starting a new thread you should be using the scheduler table,

1 Like

Done (and I have put the init method in the ardupilot init method) that works! Thanks for the guidance!

1 Like

Even better is if you post your code as a github.com/ardupilot/ardupilot pull request

Will do so, it will be my first pull request, so let me check it out.

done: https://github.com/ArduPilot/ardupilot/pull/16545

Thanks, I took a look at it, seams fine. Communication will continue on the PR.