Page 1 of 2

Receiving multiple messages from message port

Posted: Wed Jul 28, 2021 9:02 pm
by alkargr
When you have more than one instruments that receive messages from the same hardware_id, the instrument gets the same message times the number of instruments.

E.g. If you have instr A with id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message) and instrB with id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message),
and you send one message from arduino, you get 2 messages to both instruments.

And if the message is for example to execute a function to type letter A on scratchpad of FMS, then you get AA.
If the message is to toggle something ON/OFF then you get OFF->ON->OFF.

I used timer to ignore redundant messages, but that's not the solution.

Re: Receiving multiple messages from message port

Posted: Wed Jul 28, 2021 9:32 pm
by Sling
Hi,

Your example is not 2 instruments as you state but 2 message port links added to the same instrument. Why are you adding the same message port link twice. Just pass the data via one only.

Re: Receiving multiple messages from message port

Posted: Wed Jul 28, 2021 11:36 pm
by lonespace
I’m not sure you read it right, @Sling. From the description, he’s got two instruments with the message port connection set up (instr a and instr b)

Re: Receiving multiple messages from message port

Posted: Thu Jul 29, 2021 5:11 am
by Sling
Hi,

Thanks lonespace. Upon reading again I think I latched onto the idea that you wouldn’t do what the OP is doing and convinced myself it was therefore within the same instrument. Either way both are flawed.

With that in mind, on to the original question. You shouldn’t be trying to communicate with the same message port board from 2 separate instruments. The best way to do what you want would be to do the message port comms in one of your instruments and then pass whatever the other instrument needs via iic (inter instrument communication). That’s specifically what iic is for.

Hope this helps you arrive at a better solution. Let us know if you have questions about iic but if you have message port working it should be easy to get to grips with iic.

Tony

Re: Receiving multiple messages from message port

Posted: Thu Jul 29, 2021 5:46 am
by alkargr
That's a good idea! I'll try it with si commands.
Thank you!

Re: Receiving multiple messages from message port

Posted: Sat Jul 31, 2021 12:25 pm
by JackZ
You could try to differentiate the receiving instrument’s target by the payload ID, ie reserving messages in the 0-99 I’d range for Inst A, then say in the 1000-1099 for inst B?

In the Arduino code you check the payload ID then react only to the ID range it’s supposed to work with?

Re: Receiving multiple messages from message port

Posted: Sat Jul 31, 2021 3:46 pm
by lonespace
That still doesn’t solve the problem of the duplicate messages

Re: Receiving multiple messages from message port

Posted: Sat Jul 31, 2021 6:38 pm
by JackZ
@lonespace So if you have a ready made solution, I’d love to know it.

The payload ID should do the trick, since the « redundant » messages will have a different ID so each instrument can just ignore the non relevant one.

Re: Receiving multiple messages from message port

Posted: Sat Jul 31, 2021 10:54 pm
by lonespace
@JackZ I don’t think that’ll work; from the sounds of it, if you send:
Message ID=1, payload 0x5F intended for instrument A
Message ID=2, payload 0xB2 intended for instrument B

Both instruments will receive *two copies* of both payloads. If you tell instrument A to ignore payload 2, you still have to code instrument A to also ignore duplicate payload 1’s

Re: Receiving multiple messages from message port

Posted: Sat Jul 31, 2021 11:59 pm
by Sling
I think my suggestion of iic or the method suggested by @JackZ should work. Without knowing how much data is passing it’s hard to say which approach would be best for the application.