Difference between revisions of "Hw message port add"

From Sim Innovations Wiki
Jump to navigation Jump to search
Line 32: Line 32:


-- This function will be called when a message is received from the Arduino.
-- This function will be called when a message is received from the Arduino.
function new_message(id, value)
function new_message(id, payload)
   print("received new message with id " .. id)
   print("received new message with id " .. id)
end
end

Revision as of 12:19, 11 December 2017

Description

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.

Return value

Argument Type Description
hw_message_port_id String 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.

Arguments

# 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.

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