|
Class: SerialPort
Object
|
+--Stream
|
+--PeekableStream
|
+--PositionableStream
|
+--WriteStream
|
+--ReadWriteStream
|
+--ExternalStream
|
+--NonPositionableExternalStream
|
+--SerialPort
- Package:
- stx:libbasic2
- Category:
- Streams-External
- Version:
- rev:
1.31
date: 2016/08/31 16:47:38
- user: cg
- file: SerialPort.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
This class provides access to serial ports.
Before opening, the port should be configured, unless the default settings
are not correct.
i.e.
port := SerialPort new.
port setBaudrate:19200
port open.
Arguments/Parameters/Instvars:
portName String device name
WIN32: COM0, COM1, ...
Unix: /dev/ttyS0, ...
/dev/cua0, ...
baudRate Integer 9600, 19200, ...
stopBitsType Symbol #stop1, #stop1_5 or #stop2
parityType Symbol #odd, #even or #none
dataBits Integer 5, 6, 7, 8
inFlowCtrlType Symbol #xOnOff, #hardware or #none
outFlowCtrlType Symbol #xOnOff, #hardware or #none
xOnChar Integer | Character
xOffChar' Integer | Character
debugging
-
debug: aBoolean
-
turn on/off internal debugprints.
This method is for ST/X debugging only and
may be removed in later versions
usage example(s):
SerialPort debug:true
SerialPort debug:false
|
defaults
-
defaultPortName
-
-
defaultPortName: aString
-
instance creation
-
portName: portName baudRate: baudRateOrNil stopBitsType: stopBitsTypeOrNil parityType: parityTypeOrNil dataBits: dataBitsOrNil inFlowCtrlType: inFlowCtrlTypeOrNil outFlowCtrlType: outFlowCtrlTypeOrNil xOnChar: xOnCharOrNil xOffChar: xOffCharOrNil
-
arguments are self describing; nil values mean: leave setting as is.
baudrate is a number i.e. 9600, 19200...
stopBitsType must be one of: #stop1, #stop1_5 or #stop2
parityType must be one of: #odd, #even or #none
dataBits must be 5, 6, 7 or 8
inFlowCtrlType must be one of: #xOnOff, #hardware or #none (or nil)
outFlowCtrlType must be one of: #xOnOff, #hardware or #none (or nil)
xOnChar must be nil or a character or a small byte valued integer
xOffChar must be nil or a character or a small byte valued integer
accessing
-
pathName
-
answer the port name - compatibilty with FileStream
-
setBaudRate: baudRateOrNil
-
baudrate is a number i.e. 9600, 19200....
Must be set before opening.
-
setDataBits: dataBitsOrNil
-
dataBits must be 5, 6, 7 or 8.
Must be set before opening.
-
setInFlowCtrlType: inFlowCtrlTypeOrNil
-
inFlowCtrlType must be one of: #xOnOff, #hardware or #none (or nil)
Must be set before opening.
-
setOutFlowCtrlType: outFlowCtrlTypeOrNil
-
outFlowCtrlType must be one of: #xOnOff, #hardware or #none (or nil)
Must be set before opening.
-
setParityType: parityTypeOrNil
-
parityType must be one of: #odd, #even or #none.
Must be set before opening.
-
setPortName: portNameArg
-
Must be set before opening.
-
setPortName: portNameArg baudRate: baudRateOrNil stopBitsType: stopBitsTypeOrNil parityType: parityTypeOrNil dataBits: dataBitsOrNil inFlowCtrlType: inFlowCtrlTypeOrNil outFlowCtrlType: outFlowCtrlTypeOrNil xOnChar: xOnCharOrNil xOffChar: xOffCharOrNil
-
these must be set before opening.
baudrate is a number i.e. 9600, 19200...
stopBitsType must be one of: #stop1, #stop1_5 or #stop2
parityType must be one of: #odd, #even or #none
dataBits must be 5, 6, 7 or 8
inFlowCtrlType must be one of: #xOnOff, #hardware or #none (or nil)
outFlowCtrlType must be one of: #xOnOff, #hardware or #none (or nil)
xOnChar must be nil or a character or a small byte valued integer
xOffChar must be nil or a character or a small byte valued integer
-
setStopBitsType: stopBitsTypeOrNil
-
stopBitsType must be one of: #stop1, #stop1_5 or #stop2.
Must be set before opening.
-
setXOffChar: xOffCharOrNil
-
xOffChar must be nil or a character or a small byte valued integer.
Must be set before opening.
-
setXOnChar: xOnCharOrNil
-
xOnChar must be nil or a character or a small byte valued integer.
Must be set before opening.
initialization
-
initialize
-
transparent
inspecting
-
inspectorExtraMenuOperations
-
extra operation-menu entries to be shown in an inspector.
Answers a collection of pairs contining aString and action aBlock.
aString is the label of the menu item.
aBlock is evaluated when the menu item is selected.
To be redefined in objects which think that it makes sense to offer
often used operations in an inspector.
See SerialPort as an example.
low level
-
baudRate: newRate
-
allows change of the baudrate while being open.
Currently, only works for windows.
Unix users should close, reconfigure and reopen.
-
protected closeFile
-
low level close
opening
-
open
-
open the OS-port.
Notice: all parameters (baudrate, stopbits, etc.) must have been set before
printing & storing
-
printOn: aStream
-
queries
-
getBaudrate
-
return the baudRate
-
getDataBits
-
return the nr. of dataBits
-
getInFlowCtrlType
-
return the inFlowCtrlType
-
getName
-
return the name; here, we return the devices name
-
getOutFlowCtrlType
-
return the outFlowCtrlType
-
getParityType
-
return the parityType
-
getStopBitsType
-
return the stopBitsType
-
getXOffChar
-
return the xOffChar
-
getXOnChar
-
return the xOnChar
example (get help info from an nntp server):
|serialPort|
serialPort := SerialPort new setPortName:(SerialPort defaultPortName).
serialPort open.
serialPort close.
|
|serialPort|
serialPort := SerialPort new setPortName:'COM5'.
serialPort open.
serialPort nextPutAll:'hello world'.
serialPort cr.
serialPort close.
|
|serialPort|
serialPort := SerialPort new setPortName:'COM5'.
serialPort open.
Transcript showCR:(serialPort nextAvailable:100).
serialPort close.
|
|