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