Arduino could not be found in MessagePort-Mode

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
Marcus
Posts: 5
Joined: Wed Nov 02, 2022 7:41 am

Arduino could not be found in MessagePort-Mode

#1 Post by Marcus »

Hi all,
i need some help connecting an Arduino to AM in messagePort-Mode.
I use an Arduino Mega 2560 and uploaded the "BasicExample"-sketch that comes with the MessagePort-Lib.
When i click on new device in AM, the 'add device'-window appears with the correct COM-port preselected. But after adding, the device could not be found by AM ("Seaching on port 'COM xy'").
Any ideas, what's going wrong?

By the way: When i flash the Arduino via AM, the device is found by AM correctly, but of course only in Pinmode.

Thanks for helping
Marcus

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Arduino could not be found in MessagePort-Mode

#2 Post by jph »

Marcus wrote: Wed Nov 02, 2022 7:56 am Hi all,
i need some help connecting an Arduino to AM in messagePort-Mode.
I use an Arduino Mega 2560 and uploaded the "BasicExample"-sketch that comes with the MessagePort-Lib.
When i click on new device in AM, the 'add device'-window appears with the correct COM-port preselected. But after adding, the device could not be found by AM ("Seaching on port 'COM xy'").
Any ideas, what's going wrong?

By the way: When i flash the Arduino via AM, the device is found by AM correctly, but of course only in Pinmode.

Thanks for helping
Marcus
Have you uploaded the basic example 'as is' or have you edited it to send a value in the loop ?
I am sure you have simply uncommented one of the 'send' lines in the main loop()
This will massively stuff the buffer as you are trying to send data every iteration of the loop.

You need a delay. Avoid using arduino delay() ! . Use a non blocking one. An example is shown here using a simple non blocking delay. Of course, In the 'real world' usage you would be sending data in response to events occurring and not specifically a timed loop. It is just here as an example and to control the data flow.

test with this

Code: Select all


/*
**********************************************************************************************************************
             very basic message port library example with non blocking timed send delay   - Joe (JPH)
**********************************************************************************************************************
*/

// includes
#include <si_message_port.hpp>

// defines
// constants
const uint16_t DELAY_PERIOD = 1000;     // delay period

// variables
uint32_t millisLast = millis();         // for our transparent delay 

/* other actions prior to 'setup' */
SiMessagePort* messagePort;

/* transparent delay constituents - JPH 2020.
   // constants
  const uint16_t DELAY_PERIOD = 1000;     // delay period
  // variables
  uint32_t millisLast = millis();         // for our transparent delay 
  //transparent delay wrapper
  if (millis() - millisLast >= DELAY_PERIOD) {    
    // do things
    millisLast = millis();
  }
*/

/* *************************************************************************************************** */

void setup() {                                     //  setup: run once

  // Init library on channel M and Arduino type UNO
  messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_UNO, SI_MESSAGE_PORT_CHANNEL_M, new_message_callback);

}                                                  //  setup end

/* *************************************************************************************************** */

void loop() {                                      // main program loop

  // Make sure this function is called regularly
  messagePort->Tick();

if (millis() - millisLast >= DELAY_PERIOD) {      // transparent delay

    // You can send your own messages to Air Manager or Air Player
    //messagePort->SendMessage(123);
    // messagePort->SendMessage(123, (uint8_t) 99);
    uint8_t payload[3] = { 0x00, 0x01, 0x02 };
    messagePort->SendMessage(777, payload, 3);

    millisLast = millis();
  }




  //messagePort->SendMessage(123, "hello");
  //messagePort->SendMessage(123, (int32_t)1000);
  //messagePort->SendMessage(123, 2.5f);
  //messagePort->SendMessage(123, (uint8_t) 0xAA);

}                                      // main program loop end

/*
*********************************************************************************************************
                                            Subroutines
*********************************************************************************************************
*/

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

  // Breakdown of what we get

  // payload->type            //
  // payload->len             // amount of 'type' received
  // message_id               // As it says
  // payload->data_byte[n]    // The 'array' of the type to amount

  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;
    }
  }
}

/* *************************************************************************************************** */
You don't need to change the device from UNO if you are using another type of device as messageport doesn't care. It is simply for reference.
Joe. CISSP, MSc.

Marcus
Posts: 5
Joined: Wed Nov 02, 2022 7:41 am

Re: Arduino could not be found in MessagePort-Mode

#3 Post by Marcus »

Hi Joe,

thanks al lot, now it works fine.
Yes, In fact, I just commented out one of the send lines and added a delay(500).

Would by great, if someone could update the example-sketch in the messageport-lib. An example, which doesn't work, ist not really a good example.

Kind regards
Marcus

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Arduino could not be found in MessagePort-Mode

#4 Post by SimPassion »

Marcus wrote: Wed Nov 02, 2022 7:56 am Hi all,
i need some help connecting an Arduino to AM in messagePort-Mode.
I use an Arduino Mega 2560 and uploaded the "BasicExample"-sketch that comes with the MessagePort-Lib.
When i click on new device in AM, the 'add device'-window appears with the correct COM-port preselected. But after adding, the device could not be found by AM ("Seaching on port 'COM xy'").
Any ideas, what's going wrong?

By the way: When i flash the Arduino via AM, the device is found by AM correctly, but of course only in Pinmode.

Thanks for helping
Marcus
AM is reporting devices prepared using the AM UI embedded Flash features
Arduino devices should be prepared in another way, mostly using Arduino IDE, so they don't appears as directly handled by AM, they are rather autonomous devices, using a dedicated and different way for communication between Arduino device MessagePort compliant and AM instruments

Here's the current MessagePort sample which really target the Arduino MEGA2560, so I don't understand what could be wrong ???

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(123);
	//messagePort->SendMessage(123, "hello");
	//messagePort->SendMessage(123, (int32_t)1000);
	//messagePort->SendMessage(123, 2.5f);
	//messagePort->SendMessage(123, (uint8_t) 0xAA);

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Arduino could not be found in MessagePort-Mode

#5 Post by jph »

Hi Gilles, it is exactly as I listed above. The provided example, untouched, works fine in that it will connect to AM, but to make it do anything further it needs adapting and the problem was that the poster had uncommented a send example without adding an appropriate delay hence overloading the buffer.

Messageport is an Arduino library, but it still needs a 'device' adding to AM once the arduino is flashed from the arduino IDE. This is not related to AM image flashing. AM has to have the device added from the device icon as it will not scan com ports to avoid conflicts. It waits to be told to look at a specific port. After that AM reports messageport devices so that they appear exactly the same way as any other flashed AM arduino or similar, even the exact same naming convention..although the board type means nothing in messageport apart from being useful to list the board type for reference but that is all. You can call a messageport PICO a MEGA if you want as it makes absolutely no difference at all to AM. Again, the exact same naming convention is used for messageport devices as per the AM pre written flash. Looking at the list in AM with a mega on messageport and a mega on a standard AM flash then without right click and inspect the device in the list you could not tell the difference. Personally I would rather it used a different convention for the name but it is no big deal as the whole cockpit will be messageport only.
Joe
Last edited by jph on Thu Nov 03, 2022 9:54 pm, edited 1 time in total.
Joe. CISSP, MSc.

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Arduino could not be found in MessagePort-Mode

#6 Post by SimPassion »

jph wrote: Thu Nov 03, 2022 9:36 pm Hi Gilles, it is exactly as I listed above. The provided example, untouched, works fine in that it will connect to AM, but to make it do anything further it needs adapting and the problem was that the poster had uncommented a send example without adding an appropriate delay hence overloading the buffer.

Messageport is an Arduino library, but it still needs a 'device' adding to AM once the arduino is flashed from the arduino IDE. This is not related to AM image flashing. AM has to have the device added from the device icon as it will not scan com ports to avoid conflicts. It waits to be told to look at a specific port. After that AM reports messageport devices so that they appear exactly the same way as any other flashed AM arduino or similar, even the exact same naming convention..although the board type means nothing in messageport apart from being useful to list the board type bur that is all. You can call a messageport PICO a MEGA if you want as it makes absolutely no difference to AM. Again, the same naming convention is used as per the AM pre written flash.
Joe
Thanks for the refresh Joe, it's been a while I've not started instruments with MessagePort communication and I don't think we previously had to perform all of those actions you've reported
Will see with my ready to run Radio COMM/NAV ... potentially missed some AM Internals reworking at some point in the AM dev story ;)

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Arduino could not be found in MessagePort-Mode

#7 Post by jph »

:D no worries, The com port scanning was removed a few versions back, I cant remember exactly when so you have to use the device icon and add the messageport hardware once programmed from the Arduino IDE. To tell AM where to look. Again, the naming convention and the displayed name is no different to an AM flashed device now.
Joe
Joe. CISSP, MSc.

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Arduino could not be found in MessagePort-Mode

#8 Post by SimPassion »

 
Just to mention, after having flashed the MEGA 2560 using the Arduino IDE, then exit it, next started AM, I have no action to perform, the Arduino MEGA 2560 is seen straight forward showing the active Message Port Mode on the [Home] tab and in a connected state

image.png
 

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Arduino could not be found in MessagePort-Mode

#9 Post by SimPassion »

Working properly :
image.png
image.png
Last edited by SimPassion on Thu Nov 03, 2022 10:23 pm, edited 1 time in total.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Arduino could not be found in MessagePort-Mode

#10 Post by jph »

SimPassion wrote: Thu Nov 03, 2022 10:14 pm  
Just to mention, after having flashed the MEGA 2560 using the Arduino IDE, then exit it, next started AM, I have no action to perform, the Arduino MEGA 2560 is seen straight forward showing the active Message Port Mode on the [Home] tab and in a connected state


image.png
 
Hi Gilles, yes thats exactly what I said. In an untouched state the example will work and connect and show in the list. However, if you uncomment one of the send lines in the arduino code without an appropriate eelay then you will stuff the buffers and it wont connect. That is what the op had done.
The example I posted is the same as the basic example but I added a simple non blocking delay for simulation for testing.there is no problem with the example. There is only an issue if the send is called on every loop iteration. As he was doing.
:) Joe
Joe. CISSP, MSc.

Post Reply