|
Class: SerialPort
Object
|
+--Stream
|
+--PeekableStream
|
+--PositionableStream
|
+--WriteStream
|
+--ReadWriteStream
|
+--ExternalStream
|
+--NonPositionableExternalStream
|
+--SerialPort
- Package:
- stx:libbasic2
- Category:
- Streams-External
- Version:
- rev:
1.38
date: 2023/09/15 14:57:09
- user: stefan
- 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
copyrightCOPYRIGHT (c) 2006 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
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
Usage example(s):
(self portName:'/dev/ttyS0'
baudRate:9600 stopBitsType:#stop1
parityType:nil dataBits:8
inFlowCtrlType:nil outFlowCtrlType:nil
xOnChar:nil xOffChar:nil
) open
|
utilities
-
listOfSerialPorts
-
for windows: a list of COM ports is returned (which are present);
for unix, a list of devices found in /dev is returned
Usage example(s):
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 containing aString and action aBlock.
aString is the label of the menu item.
aBlock is evaluated when the menu item is selected.
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
-
(comment from inherited method)
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.
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
testing
-
isSerialPort
-
(comment from inherited method)
return false here; to be redefined in subclass(es)
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.
|
|