home *** CD-ROM | disk | FTP | other *** search
- property pPrinterPort : "Printer Port USB"
- property pModemPort : "P#2KeyUSB02"
- property kNewline : ASCII character 10
- property pThePort : "" --where the serial IDentifier will be stored
- property pSCScalefactor : 5.96046447753906E-6
-
- to initialise()
- set pThePort to open serial port pPrinterPort input buffer 8192
- return pThePort
- end initialise
-
- to clear()
- --just a wrapper to make clear the purpose of a read event
- set strRead to serial port read pThePort
- end clear
-
- to close {}
- close serial port pThePort with waiting
- return pThePort
- end close
-
-
- to getSCDataList()
- --reads all the data at the port and returns it as a list of SC values
- --nb: to get the raw hex string, just say
- -- set strRead to serial port read pThePort
-
- set oldDelims to AppleScript's text item delimiters
- try
- set AppleScript's text item delimiters to kNewline & return
- set allData to {}
- set strRead to serial port read pThePort
- set theItemlist to every text item of strRead
- repeat with thisitem in theItemlist
- --set end of allData to (decimal equivalent of thisitem)
- set end of allData to (pSCScalefactor * (my hex2Dec(thisitem)))
- end repeat
- set AppleScript's text item delimiters to oldDelims
- on error
- set AppleScript's text item delimiters to oldDelims
- close serial port pThePort with waiting
- end try
- return allData
- end getSCDataList
-
- to getRawSCDataList()
- return serial port read pThePort
- end getRawSCDataList
-
- to SCHexToDec(rawData)
- set oldDelims to AppleScript's text item delimiters
- try
- set AppleScript's text item delimiters to kNewline & return
- set allData to {}
- set theItemlist to every text item of rawData
- repeat with thisitem in theItemlist
- --set end of allData to (decimal equivalent of thisitem)
- set end of allData to my hex2Dec(thisitem)
- end repeat
- set AppleScript's text item delimiters to oldDelims
- on error
- set AppleScript's text item delimiters to oldDelims
- end try
- return allData
- end SCHexToDec
-
- to SCHexTomicroSiemens(rawData)
- set oldDelims to AppleScript's text item delimiters
- try
- set AppleScript's text item delimiters to kNewline & return
- set scaledDecimalData to {}
- set theItemlist to every text item of rawData
- repeat with thisitem in theItemlist
- set end of scaledDecimalData to pSCScalefactor * (my hex2Dec(thisitem))
- end repeat
- set AppleScript's text item delimiters to oldDelims
- on error
- set AppleScript's text item delimiters to oldDelims
- end try
- return scaledDecimalData
- end SCHexTomicroSiemens
-
- --written by Paul Berkowitz, March/01
- on hex2Dec(hexNum)
- set specChars to {"A", "B", "C", "D", "E", "F"}
- set hexChars to characters of hexNum
- set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, tab}
- set subText to "" & hexChars -- back to text, with tabs
- repeat with i from 1 to 6
- set specChar to item i of specChars
- set AppleScript's text item delimiters to {specChar}
- set textClumps to text items of subText
- set AppleScript's text item delimiters to {"" & (i + 10)}
- set subText to "" & textClumps
- end repeat
- set AppleScript's text item delimiters to {tab}
- set subChars to text items of subText
- set theResult to 0
- repeat with theDigit in subChars
- set theResult to 16 * theResult + theDigit
- end repeat
- set AppleScript's text item delimiters to tids
- return theResult
- end hex2Dec