SerialXtra
current version 0.9i
Copyright Geoff Smith 1999-2001
page last updated:20th November 2001

 


and
 

Description

This is a cross platform Xtra for Macromedia Director(TM) to access the serial port on both the Windows and Mac platforms. There are functions to read from and write to the port in various forms, e.g. string. It should work in Director 5, 6 & 7. Although it has only been tested in 6 & 7.
For updates on this and my other XObjects/Xtras check out my web page:

Note Mac G4 USB users. The Xtra will work with USB to serial convertors. It has been tested on the Keyspan single and 4 way USB to serial adaptor (USA-49A)

To assist you to use the SerialXtra in Shockwave I have added a SerialXtra Shockwave section that explains how to and where install files. It includes a set of demo files.

Release and Version history

Compatibility

OS
Version
Yes
No
Untested
Microsoft© Windows 95
   
98
   
2000
   
XP
   
NT 4    
Apple Macintosh Classic (OS9)
   
OSX    
 

Installation

There are two methods to install and use this Xtra for Macromedia Director.

Copy the SerialXtra.x32 (PC) or SerialXtra.xtr (Mac) into the Xtras folder inside the folder with the Director main program. When you start Director it looks inside, and makes available, any xtras inside the Xtras folder.

The other method is to place the xtra in some folder, and use Directors openxlib command before trying to use it. I use this method in my demo movies. If you put the xtra in the Xtras folder you do not need to use the openxlib command. Refer to the Director documentation for further information.

To check that the xtra is loaded enter lingo "showxlib" command into Directors message window, this lists all the available xtras. If the xtra is not named in the list some error has occured. Check the location of the file or use the openxlib command (see above). The figure below shows the presence of the xtra, "-- Xtra: SerialXtra", and because openxlib was used the name of the file that it was read from is shown.
Is the xtra is on the list use "put interface(xtra "SerialXtra")" to list all the messages available in the xtra. It also shows the version of the xtra and if it can be used in a projector.


Example of message window afer openxlib and interface lingo commands have been executed
(Varies with different versions)

Commands

General  
  New
Control  
 

SetProtocol
SetBaudRate
SetParity
SetDatabits
SetStopbits
SetBufferSize
CharsAvailable
FlushInputBuffer
FindPorts
AssertDTR

Writing to the serial port  
 

WriteNumber
WriteString

WriteHex

Reading from the serial port  

 

 

ReadNumber
ReadChar
ReadString
ReadHex
Special  
  AssertRTS- Windows only
SetMidiMode - Mac only

Version release history

New

Command format new string portName
Description Standard command to create a new instance of an object. It requires one parameter that indicates the serial port to use
Parameters

portName: the name of the port to use.
Standard Windows ones are "COM1", "COM2". Standard Mac ports are "Modem" and "Printer". These are converted on the "other" platform so that
"COM1" <=> "Modem" , "COM2" <=>"Printer". If you have additional ports you can get a list of valid names by using the FindPorts command.
The default protocol is 9600, 8 databits, 1 stop bit and no parity.

Notes To discover the name of a port use "put findports()"
Return value instance value or error number. Test with Lingo objectP command


SetProtocol

Command format SetProtocol object me, integer baud, string parity, integer dataBits, integer stopBits
Description This command allows you to set the communication protocol to use, all are set at the same time. The default protocol is 9600, 8 databits, 1 stop bit and no parity.
Parameters

me: the identifier returned from new.
baud: the communication speed - the maximum can be found using the FindPorts command.
parity: a string of one character "e"=even, "o"=odd and "n"=none. Sets the parity.
dataBits: the number of bits in the data word, either 7 or 8
stopBits: the number of stop bits, either 1 or 2

Return value either "Ok" or error message starting with the word "Error :"


SetBaudRate

Command format SetBaudRate object me, integer newBaudRate
Description This command allows you to set the communication baud rate, the maximum can be found using the FindPorts command. Default is 9600
Parameters

me: the identifier returned from new.
newBaudRate: the new speed. Only certain speeds are valid, normally 300, 1200, 2400, 4800, 9600, 19200, 38400,57600,115200,230400. Not all machines/cards support all speeds.

Return value either "OK" or error message starting with the word "Error :"

 

SetParity

Command format SetParity object me, string parity
Description This command allows you to set the communication parity. Default is none.
Parameters

me: the identifier returned from new.
Parity: a string of one character "e"=even, "o"=odd and "n"=none. Sets the parity.

Return value either "OK" or error message starting with the word "Error :"


SetDatabits

Command format SetDataBits object me, integer dataBits
Description This command allows you to set the number of databits is each word. The default is 8
Parameters

me: the identifier returned from new.
dataBits: the number of bits in the data word, either 7 or 8

Return value either "OK" or error message starting with the word "Error :"


SetStopbits

Command format SetStopBits object me, integer numStopBits
Description This command allows you to set the number of stop bits to use with each data word. Default is 1
Parameters

me: the identifier returned from new.
stopBits: the number of stop bits, either 1 or 2

Return value either "OK" or error message starting with the word "Error :"


SetBufferSize

Command format SetBufferSize object me, integer newBufferSize
Description Sets the size of the buffer for receiving characters. The default is 1024, but if you are receiving lots of data or are only occasionally going to read the information into Director, then increase this size.
Parameters

me: the identifier returned from new.
newBufferSize: a number that is the new size for the buffer.

Return value either "OK" or error message starting with the word "Error :"


WriteNumber

Command format WriteNumber object me, integer data
Description Writes a number to the open serial port. This number has to be in the range 0-255
Parameters

me: the identifier returned from new.
data: a number between 0 and 255

Return value either "OK" or error message starting with the word "Error :"


WriteString

Command format WriteString object me, string data
Description Writes a string to the open serial port.
Parameters

me: the identifier returned from new.
Data: a string of any length.

Return value either "OK" or error message starting with the word "Error :"

 

WriteHex

Command format WriteHex object me, string data
Description Writes a 1 or more numbers supplied as a "hex string" to the open serial port
Parameters

me: the identifier returned from new.
Data: a string of "hex" numbers. The string is composed of sets/pairs of hex digits. eg "3A 4D 06". There may be 1 or more sets - the space between them is optional, but if left out the digits must occur in pairs. eg "3A4D06".

Return value either "OK" or error message starting with the word "Error :"


ReadNumber

Command format ReadNumber object me
Description Read the next single byte waiting in the serial port buffer, returns 0-255 or void. If the expected data will have any '0's in it, use this command. If you try to read a string and there is a '0' Director will have problems.
Parameters

me: the identifier returned from new.

Return value Returns the number, range 0-255, or 'void' if no data waiting in the buffer.


ReadChar

Command format ReadChar object me
Description Read the next single byte waiting in the serial port buffer and return it as a single character string.
Parameters

me: the identifier returned from new.

Return value Returns a single character string or "" if no data waiting in the buffer.


ReadString

Command format ReadString object me
Description Reads all the characters currently waiting in the serial port buffer and returns then as a string. Beware, if there are any 0's in the data incorrect data will be returned.
Parameters

me: the identifier returned from new.

Return value Returns all the characters in the serial buffer as a string or "" if no data waiting in the buffer.


ReadHex

Command format ReadHex object me
Description Reads all the characters currently waiting in the serial port buffer and returns then as a string of hex digits each separated by a space.
Parameters

me: the identifier returned from new.

Return value Returns all the characters in the serial buffer as a hex string or "" if no data waiting in the buffer. E.g. "4A 56 8F"

 


CharsAvailable

Command format CharsAvailable object me
Description Returns the number of characters currently waiting in the serial port input buffer to be read
Parameters

me: the identifier returned from new.

Return value Returns the number of characters currently waiting in the serial port input buffer to be read.


FlushInputBuffer

Command format FlushInputBuffer object me
Description Discards any characters waiting in the input buffer
Parameters

me: the identifier returned from new.

Return value either "OK" or error message starting with the word "Error :"


FindPorts

Command format FindPorts
Description Returns the number and name of the serial ports installed on the machine. It returns a list of lists, the count is the number of ports. Each item in the list is a list of the name of the port, used in the new message and the maximum speed of the port. If the max speed is -1 then the port is in use and the maximum speed cannot be determined.
E.g. [ ["COM1",19200] , ["COM2",9600] ]
Parameters

None

Return value A list of lists as described above or error message starting with the word "Error :"


AssertDTR

Command format AssertDTR object me, integer trueOrFalse
Description The DTR line is a pin on the serial connector. When set the device on the other end of the serial cable knows that it can send information. Originally a form of speed control for slow computers. Today it is rarely used, but some devices require this to be set.
Parameters

me: the identifier returned from new.
trueOrFalse: 1=set it on, 0=set it off

Return value either "OK" or error message starting with the word "Error :"


AssertRTS- Windows only

Command format AssertRTS object me, integer trueOrFalse
Description The RTS line is a pin on the serial connector. This informs any device on the other end of the cable that you want to send some information. Rarely used these days. Not setable on a Mac.
Parameters

me: the identifier returned from new.
trueOrFalse: 1=set it on, 0=set it off

Return value either "OK" or error message starting with the word "Error :"


SetMidiMode - Mac only

Command format SetMidiMode object me
Description Puts the serial port into midi mode. Attach a standard Mac midi interface and you can receive the raw midi data using the ReadNumber command.
This will most probably only work with "true" Mac RS422 serial ports - the USB to serial apadtors will not support this.
Parameters

me: the identifier returned from new.

Return value either "OK" or error message starting with the word "Error :"

 

Version History

Version Date Notes
0.9i 11/18/01 Added support for Mac 115200 and 230400 baud rate setings
0.9h    
0.9g 1/6/01 Re-fixed the SetProtocol bug
0.9f 10/00 Fixed SetProtocol bug
0.9e 4/00 Marked shockwave safe
0.9d 3/28 Added ReadHex and WriteHex
0.9c 3/00 Bug fix: \0 not sent by WriteNumber
0.9b 1/99

Bug fixes
Added RTS/CTS control
Added Mac midi mode

0.9a 12/99 Initial

 


 

Using SerialXtra in Shockwave

Using the SerialXtra in Shockwave requires no additonal commands. Note that the xtra is NOT autodownloadable. Get the user to download it and put it in the correct place. If you require a downloadable version I will assist and produce a packaged version that can be certified, but you will have to obtain your own Verisign(TM) certificate and host it on a server.

The user manual describes the placement of the xtra to be used in Shockwave.

Windows 95/98 = \windows\system\Macromed\Shockwave 8\Xtras
Windows NT = \Winnt\system32\Macromed\Shockwave 8\Xtras
Mac = System folder:Extensions:Macromedia:Shockwave:Xtras

Use the publish command to create the dcr that runs under Shockwave. I produced a set of demo files to assist in exploring using the xtra in Shockwave. Download the zip for Windows or for Macintosh (coming soon).

Filename  
SerialXtraShock.dir A Director movie so that you can examine all the required lingo.
SerialXtraShock.dcr The Director movie saved as a Shockwave dcr
SerialXtraShock.htm A html file with the embed command.

Once you have the Xtra in the correct place (when you start the html document a message diplays if it has found the xtra) you can read and write to the serial port.

 

Contact details

Email: support@physicalBits.com

 

Conditions of use

In this document Xtra refers to this Xtra, and me refers to Geoff Smith. All rights to the XObject/Xtra are retained by me. The XObject may be used in any MacroMedia Director document for personal use and given to your friends. All documentation must be included when passing on the XObject/Xtra. Unless licensed you may NOT do the following ·distribute for profit without prior permission. ·distribute for profit within a Director presentation without prior permission ·distribute by CD-ROM without prior permission. ·distribute as part of a collection without prior permission ·be used in a public presentation without prior permission.
These conditions may be modified at any time. Please refer to the PhysicalBits website for the latest conditions.