Testing ExtendedSerialPort on Linux
John M McIntosh
johnmci at smalltalkconsulting.com
Thu Jun 9 16:41:57 UTC 2005
Well you need the Linux port, anyone have one?
Only one platform specific primitive or method exists
serialPortFindNamesPlusKeysstorage which on os-x invokes the
IOServiceGetMatchingServices() call to get path names to devices
that support the serial protocols. This primitive call a common
Linux box could be replaced by smalltalk code to iterate over /dev or
read some sort of control file etc to figure out the path names to
the serial devices. For mac os-9 this functionality was already part
of the VM. I'm hoping that no platform specific C code will be
required for unix boxes. Alas windows users require someone to do the
dirty work if you want windows specific serial calls? Or will unix
emulation somewhere/how etc work? Couldn't speak for parallel ports,
never even occurred to me to investigate till now.
As for the other primitives, you'll note there is no further C code,
that is because everything is generated by SLANG.
so for tcgetattr, this was tested and worked for OSX. Mind I noted
GCC 4.x is more picky about casting, so lets look further.
primitiveSerialPortUnixTcgetattr: fd attributes: atermios
| error |
self var: #atermios declareC: 'struct termios *atermios'.
self primitive: 'primitiveSerialPortUnixTcgetattr'
parameters: #(SmallInteger ByteArray).
self sizeOftermios = atermios size ifFalse: [^interpreterProxy
primitiveFail].
self cCode: 'error = tcgetattr(fd,atermios)' inSmalltalk: [error
_ 0].
error = -1 ifTrue: [error _ self getError].
^ error asSmallIntegerObj
turns into this, I will note the SLANG
self var: #atermios declareC: 'struct termios *atermios'.
did not turn the atermios into the proper C declare, not sure why.
However it turn it into a 'char *'
But if this results in just a compiler warning it still should be ok,
since the structure is pasted in from the smalltalk side.
Lastly the primitive call should return an error code (actually
errno), what is the value?
Inserting some printf might tell you if the failure occurs when the
input data is checked.
Lastly of course are you sure the plugin is loaded and called?
I'll note
Upon successful completion, the functions tcgetattr() and
tcsetattr()
return a value of 0. Otherwise, they return -1 and the global
variable
errno is set to indicate the error, as follows:
[EBADF] The fd argument to tcgetattr() or tcsetattr
() was not
a valid file descriptor.
[EINTR] The tcsetattr() function was interrupted by
a signal.
[EINVAL] The action argument to the tcsetattr()
function was
not valid, or an attempt was made to change an
attribute represented in the termios
structure to an
unsupported value.
[ENOTTY] The file associated with the fd argument to
tcgetattr() or tcsetattr() is not a terminal.
EXPORT(sqInt) primitiveSerialPortUnixTcgetattr(void) {
sqInt error;
sqInt fd;
char *atermios;
sqInt _return_value;
fd = interpreterProxy->stackIntegerValue(1);
interpreterProxy->success(interpreterProxy->isBytes
(interpreterProxy->stackValue(0)));
atermios = ((char *) (interpreterProxy->firstIndexableField
(interpreterProxy->stackValue(0))));
if (interpreterProxy->failed()) {
return null;
}
if (!((sizeOftermios()) == (interpreterProxy-
>sizeOfSTArrayFromCPrimitive(atermios)))) {
interpreterProxy->primitiveFail();
return null;
}
error = tcgetattr(fd,atermios);
if (error == -1) {
error = getError();
}
_return_value = interpreterProxy->integerObjectOf(error);
if (interpreterProxy->failed()) {
return null;
}
interpreterProxy->popthenPush(3, _return_value);
return null;
}
On Jun 9, 2005, at 6:49 AM, Samir Saidani wrote:
> Hi John,
>
> I encountered some problems while trying to install ExtendedSerialPort
> on Linux... - latest vm 3.7-7
>
> Compile error:
>
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> In function `primitiveSerialPortUnixCfgetispeed':
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> 127: warning: passing arg 1 of `cfgetispeed' from incompatible
> pointer type
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> In function `primitiveSerialPortUnixCfgetospeed':
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> 150: warning: passing arg 1 of `cfgetospeed' from incompatible
> pointer type
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> In function `primitiveSerialPortUnixCfmakeraw':
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> 171: warning: passing arg 1 of `cfmakeraw' from incompatible
> pointer type
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> In function `primitiveSerialPortUnixCfsetispeed':
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> 197: warning: passing arg 1 of `cfsetispeed' from incompatible
> pointer type
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> In function `primitiveSerialPortUnixCfsetospeed':
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> 227: warning: passing arg 1 of `cfsetospeed' from incompatible
> pointer type
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> In function `primitiveSerialPortUnixTcgetattr':
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> 422: warning: passing arg 2 of `tcgetattr' from incompatible
> pointer type
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> In function `primitiveSerialPortUnixTcsetattr':
> /src/plugins/SerialExtendedUnixPlugin/SerialExtendedUnixPlugin.c:
> 475: warning: passing arg 3 of `tcsetattr' from incompatible
> pointer type
>
> Moreover there is a problem about undefined function : int
> serialPortFindNamesPlusKeysstorage(int aUpperNumber, char
> *aByteArray);
>
> Two primitives used this function, I deleted it to see what will
> happen. I added quickly a SerialPortTermiosUnix and then this
> primitive failed :
>
> primitiveSerialPortUnixTcgetattr: afd attributes: aByteString
> <primitive: 'primitiveSerialPortUnixTcgetattr'
> module:'SerialExtendedUnixPlugin'>
>
> So I think maybe the problem is with tcgetattr(fd,atermios) : I saw in
> the appropriate .h that this function eats a structure, and we give it
> a char* (atermios) ? Tried to compare with MacOS version (in
> squeak.hpl.hp.com) but there is sometimes no plain code
> (SerialExtendedPlugin.pbproj.sit and don't know what is this beast).
>
> Since I'm not a C-pecialist, I'm stuck ! :-)
>
>
> John M McIntosh <johnmci at smalltalkconsulting.com> writes:
>
>
>> I've sent you a copy of the header file.
>> I believe Ned worked on it for linux, the original work was done
>> under OpenBSD.
>> If someone can put together a unix version we'll see about putting it
>> into the SVN tree
>>
>> That of course includes fiddling with the Smalltalk side since *all*
>> of the logic is in Smalltalk.
>>
>>
>> On Jun 8, 2005, at 7:21 AM, Samir Saidani wrote:
>>
>>
>>> Hi John,
>>>
>>> I'm playing with your work on Extended Serial Port. I looked onto
>>> the
>>> code, and think that it should be possible to open a file like
>>> '/dev/tty0' and write and read into it, is it right ? It's should be
>>> more interesting than SerialPort since '/dev/ttyS0' is
>>> hard-coded... But when I produce the plugin with VMMaker, it asks
>>> for
>>> SerialExtendedUnixPlugin.h Can you tell me the first step to get it
>>> working on linux ?
>>>
>>> Thanks !
>>> Samir
>>>
>>> --
>>> Samir SAIDANI
>>> PhD Student in CS / Doctorant en informatique web : http://
>>> www.info.unicaen.fr/~saidani
>>> Universite de Caen - Laboratoire GREYC tel : 02-31-56-74-30
>>> Equipe MAD - Campus II - 14032 Caen Cedex fax : 02-31-56-76-30
>>>
>>>
>>>
>>>
>>
>> --
>> =====================================================================
>> ===
>> ===
>> John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
>> Corporate Smalltalk Consulting Ltd. http://
>> www.smalltalkconsulting.com
>> =====================================================================
>> ===
>> ===
>>
>>
>>
>>
>
> --
> Samir SAIDANI
> PhD Student in CS / Doctorant en informatique web : http://
> www.info.unicaen.fr/~saidani
> Universite de Caen - Laboratoire GREYC tel : 02-31-56-74-30
> Equipe MAD - Campus II - 14032 Caen Cedex fax : 02-31-56-76-30
>
>
>
--
========================================================================
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
========================================================================
===
More information about the Squeak-dev
mailing list
|