# HG changeset patch # User Claus Gittinger # Date 1138898772 -3600 # Node ID eb26b0dfa8f6df20f5b3476df44894c2a4296cdc # Parent 8dbfbe7a40a06f01de2f032cea4f1c664094fa34 *** empty log message *** diff -r 8dbfbe7a40a0 -r eb26b0dfa8f6 SerialPort.st --- a/SerialPort.st Thu Feb 02 17:39:10 2006 +0100 +++ b/SerialPort.st Thu Feb 02 17:46:12 2006 +0100 @@ -13,8 +13,8 @@ "{ Package: 'stx:libbasic2' }" NonPositionableExternalStream subclass:#SerialPort - instanceVariableNames:'portName baudRate stopBitsType parityType dataBits - inFlowCtrlType outFlowCtrlType xOnChar xOffChar' + instanceVariableNames:'portName baudRate stopBitsType parityType dataBits inFlowCtrlType + outFlowCtrlType xOnChar xOffChar' classVariableNames:'DefaultPortName' poolDictionaries:'' category:'Streams-External' @@ -118,24 +118,23 @@ examples " example (get help info from an nntp server): - [exBegin] - ... to be added ... - [exEnd] + [exBegin] + |serialPort| + + serialPort := SerialPort new setPortName:(SerialPort defaultPortName). + serialPort open. + serialPort close. + [exEnd] " ! ! -!SerialPort class methodsFor:'defaults'! - -defaultPortName - DefaultPortName notNil ifTrue:[^ DefaultPortName ]. +!SerialPort class methodsFor:'instance creation'! - OperatingSystem isMSDOSlike ifTrue:[ - ^ 'COM1' - ]. - ^ '/dev/cua0' -! ! +new + "create a serial port" -!SerialPort class methodsFor:'instance creation'! + ^ super new buffered:false +! portName:portName baudRate:baudRateOrNil stopBitsType:stopBitsTypeOrNil @@ -151,12 +150,6 @@ parityType:parityTypeOrNil dataBits:dataBitsOrNil inFlowCtrlType:inFlowCtrlTypeOrNil outFlowCtrlType:outFlowCtrlTypeOrNil xOnChar:xOnCharOrNil xOffChar:xOffCharOrNil) open -! - -new - "create a serial port" - - ^ super new buffered:false ! ! !SerialPort class methodsFor:'debugging'! @@ -176,8 +169,27 @@ " ! ! +!SerialPort class methodsFor:'defaults'! + +defaultPortName + DefaultPortName notNil ifTrue:[^ DefaultPortName ]. + + OperatingSystem isMSDOSlike ifTrue:[ + ^ 'COM0' + ]. + ^ '/dev/cua0' +! ! + !SerialPort methodsFor:'accessing'! +setBaudRate:baudRateOrNil + baudRate := baudRateOrNil. +! + +setPortName:portNameArg + portName := portNameArg. +! + setPortName:portNameArg baudRate:baudRateOrNil stopBitsType:stopBitsTypeOrNil parityType:parityTypeOrNil dataBits:dataBitsOrNil @@ -195,6 +207,41 @@ xOffChar := xOffCharOrNil. ! ! +!SerialPort methodsFor:'low level'! + +baudRate:newRate +%{ + OBJ fp; + + fp = __INST(filePointer); + if ((fp != nil) && __isSmallInteger(newRate)) { + SERIALPORT port; + int ret; + + port = PORT_FROM_FILE_OBJECT(fp); +#ifdef WIN32 + { + DCB dcb; + + ZeroMemory(&dcb, sizeof(dcb)); + dcb.DCBlength = sizeof(dcb); + GetCommState(port, &dcb); + + dcb.BaudRate = __intVal(newRate); + + if (! SetCommState(port, &dcb)) { + RETURN(false); + } + RETURN(true); + } +# else /* ! WIN32 */ + /* add code for unix ioctl here ... */ +# endif /* WIN32 */ + } +%}. + self primitiveFailed. +! ! + !SerialPort protectedMethodsFor:'low level'! closeFile @@ -240,57 +287,6 @@ %} ! ! -!SerialPort methodsFor:'low level'! - -baudRate:newRate -%{ - OBJ fp; - - fp = __INST(filePointer); - if ((fp != nil) && __isSmallInteger(newRate)) { - SERIALPORT port; - int ret; - - port = PORT_FROM_FILE_OBJECT(fp); -#ifdef WIN32 - { - DCB dcb; - - ZeroMemory(&dcb, sizeof(dcb)); - dcb.DCBlength = sizeof(dcb); - GetCommState(port, &dcb); - - dcb.BaudRate = __intVal(newRate); - - if (! SetCommState(port, &dcb)) { - RETURN(false); - } - RETURN(true); - } -# else /* ! WIN32 */ - /* add code for unix ioctl here ... */ -# endif /* WIN32 */ - } -%}. - self primitiveFailed. -! ! - -!SerialPort methodsFor:'printing & storing'! - -printOn:aStream - aStream nextPutAll:'SerialPort(baudRate='. - baudRate printOn:aStream. - aStream nextPutAll:')'. -! ! - -!SerialPort methodsFor:'queries'! - -getName - "return the name; here, we return the devices name" - - ^ portName -! ! - !SerialPort methodsFor:'opening'! open @@ -537,8 +533,24 @@ ]. ! ! +!SerialPort methodsFor:'printing & storing'! + +printOn:aStream + aStream nextPutAll:'SerialPort(baudRate='. + baudRate printOn:aStream. + aStream nextPutAll:')'. +! ! + +!SerialPort methodsFor:'queries'! + +getName + "return the name; here, we return the devices name" + + ^ portName +! ! + !SerialPort class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic2/SerialPort.st,v 1.1 2006-02-02 16:22:51 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic2/SerialPort.st,v 1.2 2006-02-02 16:46:12 cg Exp $' ! !