messagePort->SendMessage not functioning

Support for Arduino in combination with Air Manager and Air Player

Moderators: Ralph, russ

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

messagePort->SendMessage not functioning

#1 Post by lonespace » Sat May 08, 2021 2:47 am

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:
  1. id = hw_message_port_add("ARDUINO_LEONARDO_A", incoming_message_callback)
  2.  
  3.  
  4.  
  5. function incoming_message_callback(message_id, payload)
  6.  
  7.   print("incoming " .. message_id)
  8.  
  9. end
Arduino sketch:
  1.  
  2.  
  3. #include <si_message_port.hpp>
  4.  
  5.  
  6.  
  7.  
  8.  
  9. //init messageport
  10.  
  11. SiMessagePort* messagePort;
  12.  
  13.  
  14.  
  15. static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
  16.  
  17.   //do nothing for now
  18.  
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
  25. void setup() {
  26.  
  27.   messagePort = new SiMessagePort(
  28.  
  29.     SI_MESSAGE_PORT_DEVICE_ARDUINO_LEONARDO,  //board type
  30.  
  31.     SI_MESSAGE_PORT_CHANNEL_A,                //channel
  32.  
  33.     new_message_callback                      //function to call on message recieve
  34.  
  35.   );
  36.  
  37.  
  38.  
  39.   pinMode(30, OUTPUT);
  40.  
  41.  
  42.  
  43. }
  44.  
  45.  
  46.  
  47. void loop() {
  48.  
  49.   static unsigned long previous_time = 0;
  50.  
  51.   unsigned long current_time = millis();
  52.  
  53.  
  54.  
  55.   if (current_time > (previous_time + 1000)) {
  56.  
  57.     messagePort->SendMessage(777);  //this does not show in the console
  58.  
  59.     messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_DEBUG, "testing, testing");  //this does show in the console
  60.  
  61.     previous_time = current_time;
  62.  
  63.   };
  64.  
  65.  
  66.  
  67.   messagePort->Tick();
  68.  
  69.  
  70.  
  71.   digitalWrite(30, millis()%1000>500); //flash RX led to indicate loop still running
  72.  
  73.  
  74.  
  75.   delay(10);
  76.  
  77.  
  78.  
  79. }
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: 2368
Joined: Thu Nov 19, 2015 9:04 am

Re: messagePort->SendMessage not functioning

#2 Post by Corjan » Sat May 08, 2021 3:59 am

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: 50
Joined: Wed Mar 25, 2020 1:58 am

Re: messagePort->SendMessage not functioning

#3 Post by lonespace » Sat May 08, 2021 4:16 am

That worked, thanks.

Seems pretty obvious in hindsight, as these often do

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests