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.38 date: 2023/09/15 14:57:09
user: stefan
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

copyright

COPYRIGHT (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.

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

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
o  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):

     self listOfSerialPorts


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 containing aString and action aBlock.
aString is the label of the menu item.
aBlock is evaluated when the menu item is selected.

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
(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
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

testing
o  isSerialPort
(comment from inherited method)
return false here; to be redefined in subclass(es)


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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Thu, 21 Nov 2024 18:59:16 GMT