eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SerialPort':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SerialPort


Inheritance:

   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

Description:


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


Class protocol:

debugging
o  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
o  defaultPortName

o  defaultPortName: aString

instance creation
o  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


Instance protocol:

accessing
o  pathName
answer the port name - compatibilty with FileStream

o  setBaudRate: baudRateOrNil
baudrate is a number i.e. 9600, 19200....
Must be set before opening.

o  setDataBits: dataBitsOrNil
dataBits must be 5, 6, 7 or 8.
Must be set before opening.

o  setInFlowCtrlType: inFlowCtrlTypeOrNil
inFlowCtrlType must be one of: #xOnOff, #hardware or #none (or nil)
Must be set before opening.

o  setOutFlowCtrlType: outFlowCtrlTypeOrNil
outFlowCtrlType must be one of: #xOnOff, #hardware or #none (or nil)
Must be set before opening.

o  setParityType: parityTypeOrNil
parityType must be one of: #odd, #even or #none.
Must be set before opening.

o  setPortName: portNameArg
Must be set before opening.

o  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

o  setStopBitsType: stopBitsTypeOrNil
stopBitsType must be one of: #stop1, #stop1_5 or #stop2.
Must be set before opening.

o  setXOffChar: xOffCharOrNil
xOffChar must be nil or a character or a small byte valued integer.
Must be set before opening.

o  setXOnChar: xOnCharOrNil
xOnChar must be nil or a character or a small byte valued integer.
Must be set before opening.

initialization
o  initialize
transparent

inspecting
o  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
o  baudRate: newRate
allows change of the baudrate while being open.
Currently, only works for windows.
Unix users should close, reconfigure and reopen.

o  protected closeFile
low level close

opening
o  open
open the OS-port.
Notice: all parameters (baudrate, stopbits, etc.) must have been set before

printing & storing
o  printOn: aStream

queries
o  getBaudrate
return the baudRate

o  getDataBits
return the nr. of dataBits

o  getInFlowCtrlType
return the inFlowCtrlType

o  getName
return the name; here, we return the devices name

o  getOutFlowCtrlType
return the outFlowCtrlType

o  getParityType
return the parityType

o  getStopBitsType
return the stopBitsType

o  getXOffChar
return the xOffChar

o  getXOnChar
return the xOnChar


Examples:


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.


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 25 Apr 2024 12:06:33 GMT