Hw message port add

From Sim Innovations Wiki
Jump to navigation Jump to search

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

Info Available from AM/AP 3.5.

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

Info 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)
# 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 ])