I think I need help on this one, as message port is new to me and I'm kinda lost.
I installed the example code from the wiki, downloaded the library and uploaded it to Arduino.
Code: Select all
/*
Sim Innovations Message Port example:
In this example we can communicate with Air Manager or Air Player over a standard USB cable.
This is done using the Message Port library.
See the code below on how to implement this library.
More information on how to implement the Air Manager or Air Player side can be found here:
https://siminnovations.com/wiki/index.php?title=Hw_message_port_add
NOTE:
The Message Port library communicates with the PC using Serial Port 0 of the Arduino.
Do not use Serial port 0 yourself!
*/
#include <si_message_port.hpp>
SiMessagePort* messagePort;
static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
// Do something with a message from Air Manager or Air Player
// The arguments are only valid within this function!
// Make a clone if you want to store it
if (payload == NULL) {
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received without payload");
}
else {
switch(payload->type) {
case SI_MESSAGE_PORT_DATA_TYPE_BYTE:
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received " + payload->len + " bytes: " + payload->data_byte[0]);
break;
case SI_MESSAGE_PORT_DATA_TYPE_STRING:
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received string: " + payload->data_string);
break;
case SI_MESSAGE_PORT_DATA_TYPE_INTEGER:
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received " + payload->len + " integers" + payload->data_int[0]);
break;
case SI_MESSAGE_PORT_DATA_TYPE_FLOAT:
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received " + payload->len + " floats" + payload->data_float[0]);
break;
}
}
}
void setup() {
// Init library on channel A and Arduino type MEGA 2560
messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_MEGA_2560, SI_MESSAGE_PORT_CHANNEL_A, new_message_callback);
}
void loop() {
// Make sure this function is called regularly
messagePort->Tick();
// You can send your own messages to Air Manager or Air Player
messagePort->SendMessage(777,"RECEIVED");////////////////////////////////////// Message sent to AM
//messagePort->SendMessage(123, "hello");
//messagePort->SendMessage(123, (int32_t)1000);
//messagePort->SendMessage(123, 2.5f);
//messagePort->SendMessage(123, (uint8_t) 0xAA);
}
Code: Select all
-- This function will be called when a message is received from the Arduino.
function new_message(id, payload)
-- Do something with the message from the Arduino
print("Message received:"..id.."/"..payload)
end
Arduino_id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message)-- insert here the card and channel you are using.
---------------------------------------------------------------------------------------------------------
-- IMPORTANT NOTE: the Named hardware id doesn't work in AM 3;X, only in v4.0 and up.
-- Use Hardware id (like in the example above: "ARDUINO_MEGA2560_A" instead of a named hardware name.
--------------------------------------------------------------------------------------------------------
-- Send a message to Air Manager with id 101 and an INT as a payload (value) every 500 msec
timer_start(0,500, function()
i=i+1
hw_message_port_send(Arduino_id, 101, "INT", i)
end)
I declared the card in the instrument properties ARDUINO 2560, channel A
As far as I understand, i should have at least the debug messages in the console, correct?
Thanks for your help
Jacques