How to get data from serial port(TELEM2)?

Hi,everyone

I'm trying to get data from sonar which is connected  to "TELEM2" port of pixhawk by serial communication. However, my sorce code doesn't work and I can't see data which is sent by sonar.

My settings are

hardware: pixhawk(it connect to computer by USB)

sonar: MB7060-300 (MaxBotix, it connect to "TELEM2" port of pixhawk)

software: Misson planner

My sorce code are

User code cpp

#ifdef USERHOOK_MEDIUMLOOP
void Copter::userhook_MediumLoop()
{
static char incoming[10];
static uint8_t index=0;
static uint8_t value_index=0;

uint8_t data;
int16_t numc;

numc = sensor_port->available()
  for (int16_t i = 0; i < numc; i++) { 
    data = sensor_port->read();
    hal.console->printf("data= %c",data);
    ...
  }
  ...
}
And I rewrite "UserVariables.h".
When I tried it, many garbled messages appear in the terminal of mission planner. I attach the screenshot of this. I don't know why these garbled message appears.
Anyway, I want to see the data from sonar. Please give me some advise!
Thanks

.png

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…