@lonespace Good advice, thanks!
That’s what I did here, still with no messages on the console. Weird.
https://siminnovations.com/forums/view ... 350#p35350
I'm currently implementing the test code from the excellent Tony's video on MessagePort (wished
@Sling had supplied the whole C++ Arduino & AM lua codes in the comments of the vid, BTW
), so far still nothing appears in the console.
For other people that might be interested, here are the codes copied from the video.
AM test instrument:
Code: Select all
-- This function will be called when a message is received from the Arduino MEGA_2560_D7 is pulled LOW.
function message_callback(id, payload)
payload_str=""
i=0
for _ in pairs(payload) do
i = i + 1
if i == 1 then
payload_str = tostring(payload[i])
else
payload_str=payload_str..","..tostring(payload[i])
end
end
print("Message received with id:"..id.." and payload of :"..payload_str)
end
msg_port_id = hw_message_port_add("My_message_port", message_callback)
function button_press()
state = not state
send_int = fif(state == true, 1, 0)
-- sata type can be INT, INT[n],FOAT,FLOAT[n}, BYTE, BYTE[n] or STRING
hw_message_port_send(msg_port_id, 7, "INT[2]", {send_int, 3})
hw_message_port_send(msg_port_id, 8, "STRING", "This is a TEST")
end
button_id = button_add(nil, nil,0, 0, 100, 100, button_press)
And the Arduino code.
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;
int led=13;
int button1=7;
int button_live=LOW;
int button_current= HIGH;
unsigned long last_debounce_time=0;
unsigned long debounce_wait=50;
static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
// Do something with a message from Air Manager or Air Player
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_TRACE,String(payload->type));
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO,String(payload->len));
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_WARN,"WARNING");
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_ERROR,"ERROR");
if (message_id==7) {
digitalWrite(led,payload->data_int[0]);
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_DEBUG,String(payload->data_int[1]));
} else if (message_id==8) {
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_DEBUG,String(payload->data_string));
}
}
// 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);
pinMode(led,OUTPUT);
pinMode(button1,INPUT_PULLUP);
}
void loop() {
// Make sure this function is called regularly
messagePort->Tick();
int button_read=digitalRead(button1);
if (button_read!=button_live) {
last_debounce_time= millis();
}
if ((millis()-last_debounce_time)>debounce_wait) {
if (button_read!=button_current) {
button_current=button_read;
uint8_t payload[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
messagePort->SendMessage(2,payload,8);
}
// You can send your own messages to Air Manager or Air Player
//messagePort->SendMessage(123);
//messagePort->SendMessage(123, "hello");
//messagePort->SendMessage(123, (int32_t)1000);
//messagePort->SendMessage(123, 2.5f);
//messagePort->SendMessage(123, (uint8_t) 0xAA);
}
button_live=button_read;
}
I can see the TX led blinking when i connect the pin#7 to ground but there is absolutely no message on the console neither coming IN or OUT. Same applies when i press the virtual button on the AM instrument side.
And in Air Manager the Arduino is recognized, and the Message Port is displayed as "Active" in the Device tab.
Out of options here, so any help greatly appreciated.
Jacques