Skip to content

Instantly share code, notes, and snippets.

@robinvanemden
Last active August 3, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinvanemden/641992a824a21fff1937 to your computer and use it in GitHub Desktop.
Save robinvanemden/641992a824a21fff1937 to your computer and use it in GitHub Desktop.
-- Authware 7.0 Script,
-- Robin van Emden 2015
-- http://pavlov.tech/2015/03/04/authorware-to-arduino-interface/
-- Communicates with an Arduino
-- Over Serial Port on a PC
-- Implements DirectCommunication Xtra from
-- http://www.directxtras.com/dcomm_home.asp
-- Instantiate the DirectCommunication Xtra
Trace("--- DirectCommunication -- ")
Device := NewObject("DirectCommunication" ; 0)
-- Show available USB and Serial ports
Trace("--- getDevices -- ")
Devices := CallObject (Device ; "commGetDevices")
Trace (Devices)
-- Connect to Arduino Serial Port
Trace("--- commConnect -- ")
Error := CallObject (Device ; "commConnect"; "\\\\.\\COM17")
if (Error) then
Trace ("Can't connect to the device, error # "^Error)
else
Trace ("A connection was established successfully.")
end if
-- Set the Baud Rate
Trace("--- commSetBaudRate -- ")
Error := CallObject (Device; "commSetBaudRate"; 9600 )
if (Error) then
Trace ("Can't set the baud rate, error # "^Error)
else
Trace ("The baud rate was set successfully.")
end if
-- Send pulse values to arduino
-- Here: Port A, Cool, Power 100%, for 1000ms
NumOfCharsSent := CallObject (Device, "commWrite", "<0,0,100,1000>"^Return)
Trace (NumOfCharsSent^" characters were successfully sent to the device.")
-- trace response
repeat with i := 1 to 10
Trace (CallObject (Device, "commRead"))
end repeat
-- disconnect port and delete the object
Trace (CallObject (Device; "commDisconnect"))
DeleteObject(Device)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment