#!/bin/sh # MetaCard 2.4 stack # The following is not ASCII text, # so now would be a good time to q out of more exec mc $0 "$@"  Serial Test"on openStack if the platform = "Win32" then set the hilite of btn "OS 9" to false set the hilite of btn "OS X" to false set the hilite of btn "Win" to true else put the systemVersion into tOS set the itemDel to "." if item 1 of tOS < 10 then set the hilite of btn "OS 9" to true set the hilite of btn "OS X" to false set the hilite of btn "Win" to false else set the hilite of btn "OS 9" to false set the hilite of btn "OS X" to true set the hilite of btn "Win" to false end if end if set the toolTipDelay to 500 send fillMenu to group "Platform" end openStack on closeStack if the hilite of btn "Port open" = true then send mouseUp to btn "Close Serial Port" end if end closeStack dt revstackfalse Serial Test U Courier New U Courier New @UVerdana ULucida Grande cREVGeneralscriptChecksum7#KeVց debugObjects bookmarks handlerListopenStack closeStackscriptSelectionchar 539 to 538 prevHandler openStack tempScriptscript

on openStack

if the platform = "Win32" then

set the hilite of btn "OS 9" to false

set the hilite of btn "OS X" to false

set the hilite of btn "Win" to true

else

put the systemVersion into tOS

set the itemDel to "."

if item 1 of tOS < 10 then

set the hilite of btn "OS 9" to true

set the hilite of btn "OS X" to false

set the hilite of btn "Win" to false

else

set the hilite of btn "OS 9" to false

set the hilite of btn "OS X" to true

set the hilite of btn "Win" to false

end if

end if

set the toolTipDelay to 500

send fillMenu to group "Platform"

end openStack

on closeStack

if the hilite of btn "Port open" = true then

send mouseUp to btn "Close Serial Port"

end if

end closeStack

 P'local recEOL = empty on resetEOL -- work out the terminator character -- CR in Revolution isn't actually ASCII 13 put word 1 of the selectedText of btn "RecEOL" into recEOL if recEOL = "CR" then put numToChar(13) into recEOL else if recEOL = "LF" then put LF into recEOL else put CRLF into recEOL end resetEOL on readPort if the hilite of btn "Port open" = true then if recEOL is empty then resetEOL put the label of btn "Port" into thePort if the hilite of btn "OS X" then read from driver thePort until recEOL else read from file thePort until recEOL end if if it is not empty then put it after fld "recField" if last char of fld "recField" <> cr then put cr after fld "recField" send readPort to me in 5 ticks end if end readPort revcardfalse cREVGeneralscriptChecksum\}_f= bookmarks breakPoints handlerListresetEOL readPort tempScript prevHandleridlescriptSelectionchar 807 to 806script 0

local recEOL = empty

on resetEOL

-- work out the terminator character

-- CR in Revolution isn't actually ASCII 13

put word 1 of the selectedText of btn "RecEOL" into recEOL

if recEOL = "CR" then put numToChar(13) into recEOL

else if recEOL = "LF" then put LF into recEOL

else put CRLF into recEOL

end resetEOL

on readPort

if the hilite of btn "Port open" = true then

if recEOL is empty then resetEOL

put the label of btn "Port" into thePort

if the hilite of btn "OS X" then

read from driver thePort until recEOL

else

read from file thePort until recEOL

end if

if it is not empty then put it after fld "recField"

if last char of fld "recField" <> cr then put cr after fld "recField"

send readPort to me in 5 ticks

end if

end readPort

  Open Serial PortEpon mouseUp -- check which port is in use put the label of btn "Port" into thePort -- set the port parameters put "BAUD=" & the label of btn "Baud" & \ " PARITY=" & the label of btn "Parity" & \ " DATA=" & the label of btn "Data" & \ " STOP=" & the label of btn "Stop" into serial set the serialControlString to serial -- open the port & show any error set the cursor to watch if the hilite of btn "OS X" then open driver thePort for binary update else open file thePort for binary update end if if the result is not empty then answer the result else set the hilite of btn "Port open" to true -- start reading the port if open send readPort to this card in 10 ticks end if end mouseUp $ l&commandfalseThis opens the serial port. cREVGeneralscriptChecksumZ='+~ revUniqueID 1000174798057 bookmarks handlerListmouseUp tempScript prevHandlermouseUpscriptSelectionchar 330 to 329script

on mouseUp

-- check which port is in use

put the label of btn "Port" into thePort

-- set the port parameters

put "BAUD=" & the label of btn "Baud" & \

" PARITY=" & the label of btn "Parity" & \

" DATA=" & the label of btn "Data" & \

" STOP=" & the label of btn "Stop" into serial

set the serialControlString to serial

-- open the port & show any error

set the cursor to watch

if the hilite of btn "OS X" then

open driver thePort for binary update

else

open file thePort for binary update

end if

if the result is not empty then

answer the result

else

set the hilite of btn "Port open" to true

-- start reading the port if open

send readPort to this card in 10 ticks

end if

end mouseUp

Baud eL5JcommandfalseSelect your baud rate.9600 300 1200 9600 19200 38400 57600  cREVGeneral revUniqueID 1000174860001  New Field 1 8> cREVGeneral revUniqueID 1000174973688 Baud rate:  New Field 1 V> cREVGeneral revUniqueID 1000174973688 Data bits: Data eLSJcommandfalse Select the number of data bits.87 8   cREVGeneral revUniqueID 1000174860001 Stop eLqJcommandfalse Select the number of stop bits.11 2   cREVGeneral revUniqueID 1000174860001  New Field 1 t> cREVGeneral revUniqueID 1000174973688 Stop bits: Parity eLJcommandfalse'Select the parity - none, odd or even.NN O E  cREVGeneral revUniqueID 1000174860001  New Field 1 > cREVGeneral revUniqueID 1000174973688 Parity: Port eLJcommandfalseSelect your serial port./dev/cu.modem:/dev/cu.USA28X23P1.1 /dev/cu.USA28X23P2.2 - /dev/cu.modem cREVGeneral revUniqueID 1000174860001 bookmarks handlerList tempScript prevHandlerscriptSelection  New Field 1 > cREVGeneral revUniqueID 1000174973688 Port : Close Serial PortEpon mouseUp put the label of btn "Port" into thePort if the hilite of btn "OS X" then close driver thePort else close file thePort end if if the result is not empty then answer the result set the hilite of btn "Port open" to false end mouseUp $Dl&commandfalseThis closes the serial port. cREVGeneralscriptChecksumຘa600L m bookmarks revUniqueID 1000175680812 handlerListmouseUpscriptSelectionchar 205 to 204 prevHandlermouseUp tempScriptscript{

on mouseUp

put the label of btn "Port" into thePort

if the hilite of btn "OS X" then

close driver thePort

else

close file thePort

end if

if the result is not empty then answer the result

set the hilite of btn "Port open" to false

end mouseUp

 sendFieldipon enterInField send mouseUp to btn "Send" end enterInField on returnInField send mouseUp to btn "Send" end returnInField `Selection DescriptionfalseEnter the text to send here. cREVGeneralscriptChecksum2kr5K revUniqueID 1000175777805 bookmarks handlerListenterInField returnInField tempScript prevHandlerscriptSelectionchar 112 to 111script

on enterInField

send mouseUp to btn "Send"

end enterInField

on returnInField

send mouseUp to btn "Send"

end returnInField

 SendMpon mouseUp -- check that the port is open and open it if not if the hilite of btn "Port open" <> true then send mouseUp to btn "Open Serial Port" end if -- work out the terminator character -- CR in Revolution isn't actually ASCII 13 put word 1 of the selectedText of btn "SendEOL" into eol if eol = "CR" then put numToChar(13) into eol else if eol = "LF" then put LF into eol else put CRLF into eol -- send the data and record it in the display field put the label of btn "Port" into thePort put fld "sendField" into theData if the hilite of btn "OS X" then write theData & eol to driver thePort else write theData & eol to file thePort end if put "-> " & theData & return after fld "recField" end mouseUp ^Fcommandfalse9Click to send the data from the small field on the left. cREVGeneralscriptChecksum#⼢@ revUniqueID 1000175783733 bookmarks handlerListmouseUp tempScript prevHandlermouseUpscriptSelectionchar 616 to 615script

on mouseUp

-- check that the port is open and open it if not

if the hilite of btn "Port open" <> true then

send mouseUp to btn "Open Serial Port"

end if

-- work out the terminator character

-- CR in Revolution isn't actually ASCII 13

put word 1 of the selectedText of btn "SendEOL" into eol

if eol = "CR" then put numToChar(13) into eol

else if eol = "LF" then put LF into eol

else put CRLF into eol

-- send the data and record it in the display field

put the label of btn "Port" into thePort

put fld "sendField" into theData

if the hilite of btn "OS X" then

write theData & eol to driver thePort

else

write theData & eol to file thePort

end if

put "-> " & theData & return after fld "recField"

end mouseUp

 recField)`H+This field shows all sent & received data. cREVGeneral revUniqueID 1000175908156 bookmarks handlerList tempScript prevHandlerscriptSelection char 1 to 0  `I Port openhE &pdcommandfalseEThis button just gives a visual indication of the state of the port. cREVGeneral revUniqueID 1000176474351 bookmarks handlerList tempScript prevHandlerscriptSelection ClearEpSon mouseUp put "" into fld "sendField" put "" into fld "recField" end mouseUp Hr^4Click here to clear the sent & received data field. cREVGeneralscriptChecksumjdxJxp&w revUniqueID 1000181590949 bookmarks handlerListmouseUp tempScript prevHandlermouseUpscriptSelection char 72 to 71script

on mouseUp

put "" into fld "sendField"

put "" into fld "recField"

end mouseUp

 Platform ion fillMenu if the hilite of btn "OS 9" then put "modem:" & cr & "printer:" into btn "Port" else if the hilite of btn "Win" then put "COM1:" & cr & "COM2:" & cr & "COM3:" & cr & "COM4:" into btn "Port" else -- OS X - list driverNames & get 3rd item of each line put the driverNames into tList put empty into tPorts repeat for each line L in tList put item 3 of L & cr after tPorts end repeat delete last char of tPorts -- internal modem doesn't show up in deviceNames (Rev 2.1) put "/dev/cu.modem" into modemPort if tPorts contains modemPort is false then put cr & "-" & cr & modemPort after tPorts end if put tPorts into btn "Port" end if end fillMenu BNSelection DescriptionfalseCChoose your platform to allow chosing an appropriate serial ports. cREVGeneralscriptChecksumf~o bookmarks revUniqueID 1007436913161 handlerListfillMenuscriptSelectionchar 682 to 681 prevHandlerfillMenu tempScriptscript

on fillMenu

if the hilite of btn "OS 9" then

put "modem:" & cr & "printer:" into btn "Port"

else if the hilite of btn "Win" then

put "COM1:" & cr & "COM2:" & cr & "COM3:" & cr & "COM4:" into btn "Port"

else

-- OS X - list driverNames & get 3rd item of each line

put the driverNames into tList

put empty into tPorts

repeat for each line L in tList

put item 3 of L & cr after tPorts

end repeat

delete last char of tPorts

-- internal modem doesn't show up in deviceNames (Rev 2.1)

put "/dev/cu.modem" into modemPort

if tPorts contains modemPort is false then

put cr & "-" & cr & modemPort after tPorts

end if

put tPorts into btn "Port"

end if

end fillMenu

OS 9`D#on mouseUp fillMenu end mouseUp !:Selection DescriptionfalseBChoose your platform to allow chosing an appropriate serial port. cREVGeneralscriptChecksumw(XR6T bookmarks revUniqueID 1007436864361 handlerListmouseUpscriptSelection char 22 to 21 prevHandlermouseUp tempScriptscriptS

on mouseUp

fillMenu

end mouseUp

OS X`D#on mouseUp fillMenu end mouseUp :Selection DescriptionfalseBChoose your platform to allow chosing an appropriate serial port. cREVGeneralscriptChecksumw(XR6T bookmarks revUniqueID 1007436864361 handlerListmouseUpscriptSelection char 22 to 21 prevHandlermouseUp tempScriptscriptS

on mouseUp

fillMenu

end mouseUp

Win`D#on mouseUp fillMenu end mouseUp 6:Selection DescriptionfalseBChoose your platform to allow chosing an appropriate serial port. cREVGeneralscriptChecksumw(XR6T revUniqueID 1063670761023 bookmarks handlerListmouseUp tempScript prevHandlermouseUpscriptSelection char 22 to 21scriptS

on mouseUp

fillMenu

end mouseUp

 About...EpYon mouseUp set the visible of fld "Info" to not the visible of fld "Info" end mouseUp vd.Click here to see some info about this stack. cREVGeneralscriptChecksum^!3w/Wl4~ revUniqueID 1007520438369 bookmarks handlerListmouseUp tempScript prevHandlerscriptSelection char 76 to 75script

on mouseUp

set the visible of fld "Info" to not the visible of fld "Info"

end mouseUp

SendEOL ellcommandfalse/Select the characters to use to finish a send.CR [ASCII 13]!CR [ASCII 13] LF [ASCII 10] CRLF cREVGeneral revUniqueID 1063675518416  New Field 1 ` cREVGeneral revUniqueID 1063675518191 Send end of line:  New Field 1 ` cREVGeneral revUniqueID 1063675521742 Rec end-of-line:  RecEOL u5on mouseUp send resetEOL to this card end mouseUp llcommandfalse2Select the characters to use to finish a receive.CR [ASCII 13]!CR [ASCII 13] LF [ASCII 10] CRLF cREVGeneralscriptChecksume3Ź:B Y bookmarks revUniqueID 1063675645034 handlerListmouseUpscriptSelection char 40 to 39 prevHandler tempScriptscript

on mouseUp

send resetEOL to this card

end mouseUp

InfoP"on mouseUp hide me end mouseUp  cREVGeneralscriptChecksum]Rs˕,{)UTY revUniqueID 1007519921454 bookmarks handlerListmouseUp tempScript prevHandlerscriptSelection char 21 to 20script

on mouseUp

hide me

end mouseUp

 XThis is a simple Revolution stack to demonstrate sending & receiving over serial ports. New features - September 2003: @ - support for Mac OS X @ D- allows you to choose the termination character for send & receive @C W Choose your settings from the popup mens, then click on "Open Serial Port" to start. X Send your data, by typing it into the field and clicking "Send" or pressing "Return". B Data is received automatically by a handler in the card script. oThe port is automatically opened on Send and closed on closeStack if you forget to click the relevant buttons. An easy way to test this stack is to set up a connection to any port with a modem, and send "AT". You should get back an echo of your "AT", a blank line and an "OK". serialControlString settings: "BAUD=number: the ports baud rate 9PARITY=N, O, or E: no parity, odd parity, or even parity DATA=numberOfDataBits STOP=numberOfStopBits to=on or off: use timeouts $xon=on or off: software handshaking (odsr=on or off: (output) data set ready 'octs=on or off: (output) clear to send #dtr=on or off: data terminal ready rts=on or off: ready to sent 'isdr=on or off: (input) data set ready I have only allowed setting the first 4 in this stack, but the others can easily be added. The string is constructed in the "Open Serial Port" button. This has been tested on a Mac running Rev 1.1 and Mac OS 9.2 and it should work fine with Windows. As of Rev 2.1, it now works under OS X as well although there are problems with the internal modem. Under OS X, the internal modem doesn't show up on the list of deviceNames (so I add it manually) and opening the port talks several seconds, although reading & writing seems OK. Hopefully future versions of Revolution will fix this. @ ]Feel free to use or modify this stack in any way but I am not responsible for any errors :-) Sarah Reichelt sarah@troz.net $Last modified: 18th September, 2003 `