Script for DirectComm serial port extra
Down load the extra from:
www.directextras.com/dcomm_home.asp?UUID=1116861 
 

OR   Download the wirecross example and extra

Frame 1 Behavior Script
on exitFrame me
put
readline(1)   --digital in port 1
put a2d(1)   --A/D port 1
go to the frame
end
 

Start/Stop Movie Script    (Must be a movie script)
-- Vers. 1.3 for Director, 2 May 2000
-- requires DirectComm Xtra from http://www.directxtras.com
-- Do not delete! Movie Script! Nothing will work!!
-- Director for Macintosh or Windows EZ I/O movie script
-- ===========================================================================
-- (c) 1997 The Regents of the University of Michigan All rights reserved.
-- Developed at the University of Michigan School of Art and Design
-- by Michael Rodemer and Ed Bennett
-- ===========================================================================
-- the following gets Director ready to do serial communication with the microcontroller
-- on the interface board. It MUST be called before any of the other scripts associated
-- with the board will work!
-- modem port recommended; otherwise, turn off appleTalk on printer port
-- Version 1.2 fixes the problem of Director not waiting for the serial port to return a value
-- Version 1.3 fixes a problem with the DirectComm xtra needing more parameters to be set in Windows

on startMovie
  global port
 
-- init serial port
  set port = New ( Xtra "DirectCommunication", 0, "com1", 1600,1600) -- "COM1" selects modem port, "LPT1" selects printer port
  -- if you decided to use the printer port, make sure AppleTalk isn't using it
  SetCommBaudRate (port, 57600 ) -- sets port to 57600 baud
  SetCommStopBits (port, 0 ) -- sets port to 1 stop bit
  setCommDataBits(port, 8)
  setCommParity(port,
0)
  setCommFlowControl(port,
0)
  put port -- this is a bit of optional feedback
end
-- ===========================================================================
-- "numtochar()" is used often: it changes a number into a character,
-- which is a convenient way to represent a number between 0 and 255,
-- for transmitting it to the board

-- ===========================================================================
-- A2D will read a voltage and return its value,
-- expressed as a number between 0 and 255

on A2D lineNo --valid line numbers are 1-8
  global port
  FlushComm(port)
-- this clears out the receive buffer
  put numtochar((lineNo-1)) into lineNo -- internally, the chip starts numbering lines at zero
  WriteComm(port, "A" & lineNo) -- sends command to board
  put void into state
  startTimer
  repeat while (the length of state <> 1)
    put ReadComm(port)into state
    if the timer>300 then
      alert "There is a problem with the serial communication!"
      exit
repeat
    end if
  end repeat
-- this causes the program to wait for serial transmission to complete
  return chartonum(state) -- returns result from board
end

-- ===========================================================================
-- writePort will cause a pattern of ons and offs on lines Digital Out 1 through 8 on the board
-- depending on the value of the variable "state"

on writePort state -- valid values for state are 0-255
  global port
  put numtochar(state) into state
  WriteComm(port,
"W" & state)
end

-- =============================================================================
-- writeLine turns a single line on or off, "1" being "on," "0" being "off"
-- EZ I/O offers ten lines of digital output
on writeLine lineNo, onOff  -- valid line numbers are 1 through 10
  global port
  put numtochar((lineNo-1)) into lineNo -- internally, the chip starts numbering lines at zero
  put numtochar(onOff) into onOff
  WriteComm(port,
"w" & lineNo & onOff)
end

-- ===========================================================================
-- readLine returns a _ or 1 to indicate the state of a single line,
-- with "1" being "high" and "0" being "low"
-- the default state, when a line has nothing switched, is "1"
-- (see instructions for using digital input)

on readLine lineNo  -- valid line numbers are 1 through 10
  global port
  FlushComm(port)
-- this clears out the receive buffer
  put numtochar((lineNo-1)) into lineNo
  WriteComm(port,
"r" & lineNo)
  put void into state
  startTimer
  repeat while (the length of state <> 1)
    put ReadComm(port)into state
    if the timer>300 then
      alert "There is a problem with the serial communication!"
      exit
repeat
    end if
  end repeat
-- this causes the program to wait for serial transmission to complete
  return chartonum(state) -- returns result from board
end

-- ===========================================================================
-- readPort returns a value between 0 and 255 for the 8-line port
-- comprised of lines Digital Input 1 through 8 on the board
-- the default state, when no lines are switched, is "255"
-- (see instructions for using digital input)

on readPort     
  global port
  FlushComm(port)
-- this clears out the receive buffer
  WriteComm(port, "R")
  put void into state
  startTimer
  repeat while (the length of state <> 1)
    put ReadComm(port)into state
    if the timer>300 then
      alert "There is a problem with the serial communication!"
      exit
repeat
    end if
  end repeat
-- this causes the program to wait for serial transmission to complete
  return chartonum(state) -- returns result from board
end

-- ===========================================================================
-- PWM turns a line on and off rapidly (more than 18,000 times a second),
-- varying the ratio of the time the line is off to the time it is on.
-- Valid input values are from 0 (always off) to 1023 (always on)

on PWM lineNo, onTime -- valid line numbers are 1 or 2
  global port
  put numtochar(lineNo) into lineNo
 
-- the following code makes two 8-bit numbers
  -- out of the 10-bit number (0-1023) passed to PWM as an argument,
  -- passing two characters to the board one after the other
 
  put 0 into temp
  if (onTime-512>=0) then
    put
(temp+2) into temp
    put (onTime-512) into onTime
  end if
  if
(onTime-256>=0) then
    put
(temp+1) into temp
    put (onTime-256) into onTime
  end if
  put
temp into hiBite
  put onTime into loBite
  put numtochar(hibite) into hibite
  put numtochar(lobite) into lobite
  WriteComm(port,
"P" & lineNo & hiBite & loBite)
end

-- ===========================================================================
-- this frees up the serial link from the desktop computer before quitting Director

on stopMovie
  global port
  set port = void
end
-- ===========================================================================