Difference between revisions of "Hw message port add"
Jump to navigation
Jump to search
Line 6: | Line 6: | ||
'''hw_message_port_add''' is used to add a connection between your instrument and a custom Arduino program. It makes it possible to send messages between the instrument and the Arduino. | '''hw_message_port_add''' is used to add a connection between your instrument and a custom Arduino program. It makes it possible to send messages between the instrument and the Arduino. | ||
== Return value == | == Named == | ||
{{tip| Available from AM/AP 3.5.}} | |||
Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').<br/> | |||
Air Manager will present the user with a view where the assignment of pins can be done. | |||
=== Arguments === | |||
'''hw_message_port_id = hw_message_port_add(name, message_callback)''' | |||
{| class="wikitable" | |||
|- | |||
! # !! Argument !! Type !! Description | |||
|- | |||
| 1 || '''name''' || ''String'' || A functional name to define the message port. | |||
|- | |||
| 2 || '''message_callback''' || ''Function'' || This function will be called when a message is received from the Arduino. | |||
|- | |||
|} | |||
=== Return value === | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 15: | Line 35: | ||
|} | |} | ||
== | === Example === | ||
<source lang="lua"> | |||
-- This function will be called when a message is received from the Arduino. | |||
function new_message(id, payload) | |||
print("received new message with id " .. id) | |||
end | |||
id = hw_message_port_add("My message port", new_message) | |||
-- You can also send messages to the Arduino | |||
-- In this case a message with id 777 with 3 bytes (0x01, 0x02, 0x03) | |||
hw_message_port_send(id, 777, [ 1, 2, 3 ]) | |||
</source > | |||
== Hardware Id's == | |||
{{warning| Hardware Id's are not preferred, try to use named hardware instead. }} | |||
Define the used pin(s) right away. | |||
This is not preferred, since changing of pin assignment can only be done by changing the instrument/panel lua script. | |||
=== Arguments === | |||
'''hw_message_port_id = hw_message_port_add(hw_id, message_callback)''' | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 28: | Line 72: | ||
|} | |} | ||
== Example == | === Return value === | ||
{| class="wikitable" | |||
|- | |||
! Argument !! Type !! Description | |||
|- | |||
| '''hw_message_port_id''' || ''ID'' || This value can be used for further reference. Functions such as [[hw_message_port_send]] can use this hw_message_port_id. Its good practice to store this hw_message_port_id in your logic code. | |||
|} | |||
=== Example === | |||
<source lang="lua"> | <source lang="lua"> | ||
Line 42: | Line 95: | ||
-- In this case a message with id 777 with 3 bytes (0x01, 0x02, 0x03) | -- In this case a message with id 777 with 3 bytes (0x01, 0x02, 0x03) | ||
hw_message_port_send(id, 777, [ 1, 2, 3 ]) | hw_message_port_send(id, 777, [ 1, 2, 3 ]) | ||
</source > | </source > |
Latest revision as of 19:51, 11 October 2018
Description
hw_message_port_id = hw_message_port_add(name, message_callback) (from AM/AP 3.5) hw_message_port_id = hw_message_port_add(hw_id, message_callback)
hw_message_port_add is used to add a connection between your instrument and a custom Arduino program. It makes it possible to send messages between the instrument and the Arduino.
Named
Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').
Air Manager will present the user with a view where the assignment of pins can be done.
Arguments
hw_message_port_id = hw_message_port_add(name, message_callback)
# | Argument | Type | Description |
---|---|---|---|
1 | name | String | A functional name to define the message port. |
2 | message_callback | Function | This function will be called when a message is received from the Arduino. |
Return value
Argument | Type | Description |
---|---|---|
hw_message_port_id | ID | This value can be used for further reference. Functions such as hw_message_port_send can use this hw_message_port_id. Its good practice to store this hw_message_port_id in your logic code. |
Example
-- This function will be called when a message is received from the Arduino.
function new_message(id, payload)
print("received new message with id " .. id)
end
id = hw_message_port_add("My message port", new_message)
-- You can also send messages to the Arduino
-- In this case a message with id 777 with 3 bytes (0x01, 0x02, 0x03)
hw_message_port_send(id, 777, [ 1, 2, 3 ])
Hardware Id's
Define the used pin(s) right away. This is not preferred, since changing of pin assignment can only be done by changing the instrument/panel lua script.
Arguments
hw_message_port_id = hw_message_port_add(hw_id, message_callback)
# | Argument | Type | Description |
---|---|---|---|
1 | hw_id | String | The is the reference to the input. You can choose to bind to an existing Hardware ID (Hardware_id_list). |
2 | message_callback | Function | This function will be called when a message is received from the Arduino. |
Return value
Argument | Type | Description |
---|---|---|
hw_message_port_id | ID | This value can be used for further reference. Functions such as hw_message_port_send can use this hw_message_port_id. Its good practice to store this hw_message_port_id in your logic code. |
Example
-- This function will be called when a message is received from the Arduino.
function new_message(id, payload)
print("received new message with id " .. id)
end
id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message)
-- You can also send messages to the Arduino
-- In this case a message with id 777 with 3 bytes (0x01, 0x02, 0x03)
hw_message_port_send(id, 777, [ 1, 2, 3 ])