messagePort->SendMessage not functioning

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Post Reply
Message
Author
lonespace
Posts: 64
Joined: Wed Mar 25, 2020 1:58 am

messagePort->SendMessage not functioning

#1 Post by lonespace »

Arduino: Pro Micro clone
Air Manager version: 3.7.10
OS: Windows 10.0.19042

I currently have the same hardware working through messagePort, but I'm only sending data from the instrument to the arduino (code here, if you're interested). However, if I try to send data back to the instrument, it never arrives (the print statement in the lua code never fires off). What's odd is that the debug messages do get received successfully.

I'm trying to boil this down to the simplest case where it fails, and I believe this is it:

Air Manager lua code:

Code: Select all

id = hw_message_port_add("ARDUINO_LEONARDO_A", incoming_message_callback)

function incoming_message_callback(message_id, payload)
print("incoming " .. message_id)
end
Arduino sketch:

Code: Select all


#include <si_message_port.hpp>


//init messageport
SiMessagePort* messagePort;

static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
//do nothing for now
}


void setup() {
messagePort = new SiMessagePort(
SI_MESSAGE_PORT_DEVICE_ARDUINO_LEONARDO, //board type
SI_MESSAGE_PORT_CHANNEL_A, //channel
new_message_callback //function to call on message recieve
);

pinMode(30, OUTPUT);

}

void loop() {
static unsigned long previous_time = 0;
unsigned long current_time = millis();

if (current_time > (previous_time + 1000)) {
messagePort->SendMessage(777); //this does not show in the console
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_DEBUG, "testing, testing"); //this does show in the console
previous_time = current_time;
};

messagePort->Tick();

digitalWrite(30, millis()%1000>500); //flash RX led to indicate loop still running

delay(10);

}
And to reiterate, I have the same hardware working when I'm sending data to the arduino from the instrument, so this isn't a com port issue or anything like that.

Thanks in advance for your help.

User avatar
Corjan
Posts: 2936
Joined: Thu Nov 19, 2015 9:04 am

Re: messagePort->SendMessage not functioning

#2 Post by Corjan »

Hi,


The ‘incoming_message_callback’ should be defined before using it in the ‘hw_message_port_add’.
Note that code is executed top to bottom.


Corjan

lonespace
Posts: 64
Joined: Wed Mar 25, 2020 1:58 am

Re: messagePort->SendMessage not functioning

#3 Post by lonespace »

That worked, thanks.

Seems pretty obvious in hindsight, as these often do

Post Reply