Testing ExtendedSerialPort on Linux

Samir Saidani saidani at info.unicaen.fr
Fri Jun 10 13:29:53 UTC 2005


John M McIntosh <johnmci at smalltalkconsulting.com> writes:

> 22?
> #define EINVAL          22              /* Invalid argument */
>
> These can be found in the errno.h file on your system, or in a man
> page (which is?)

In fact, you have to dig a little to find the correspondance
errno<->number (tried strerror in a fprintf but seems not to work),
there is nothing in errno.h and man errno, but I found it for linux in
/usr/include/asm-generic/errno-base.h


> Ssince the termios has a different structure, you must review the
> SerialPortTermios class and create a subclass for Linux.
>
> So for example
> cispeed: aUnsignedLong
>      ^self putLong: aUnsignedLong at: self cispeedOffset.
>
> cispeedOffset   "Which is 4 * 4 bytes given the BSD structure "
>      ^16+self nccs
>
> but nccs is only defined in
> SerialPortTermiosOSX as 20

I have in bits/termios.h

#define NCCS 32
struct termios
  {
    tcflag_t c_iflag;           /* input mode flags */
    tcflag_t c_oflag;           /* output mode flags */
    tcflag_t c_cflag;           /* control mode flags */
    tcflag_t c_lflag;           /* local mode flags */
    cc_t c_line;                        /* line discipline */
    cc_t c_cc[NCCS];            /* control characters */
    speed_t c_ispeed;           /* input speed */
    speed_t c_ospeed;           /* output speed */
#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
  };


I created a SerialPortTermiosUnix with the following methods :
nccs
	^ 32

structureSize
	^ 4 + 4 + 4 + 4 + 4 + 32 + 4 + 4"struct termios{  
	tcflag_t c_iflag; /* input mode flags */  
	tcflag_t c_oflag; /* output mode flags */  
	tcflag_t c_cflag; /* control mode flags */  
	tcflag_t c_lflag; /* local mode flags */  
	cc_t c_line; /* line discipline */  
	cc_t c_cc[NCCS]; /* control characters */  
	speed_t c_ispeed; /* input speed */  
	speed_t c_ospeed; /* output speed */  
	};"

What stuck me is that ncss for SerialPortTermiosOSX is 20 (hex) which
is 32, and structureSize is 4 + 4 + 4 + 4 + 20 + 4 + 4, but if I kept
the hex form for SerialPortTermiosUnix, it doesn't work, which seems
to mean that the value are in decimal and not hex. But anyway, with
ncss at 20 or 32, it doesn't work, same 22 error. But if I replace 32
by 20 in structureSize, the primitive failed due to the problem we
discussed earlier (60 vs 48)...

John, the problem of warning error for the compiler worries me, don't
like such errors which could have some unknown side effects, and I
don't understand how it could be possible that functions eating a
structure could accept a pointer to char, (a kind of implicit cast
???) but I must confess that I'm not really fluent with C, and
probably this remark is revealing some misunderstanding about this
language.

Cheers,
Samir

> This is the BSD structure
> struct termios {
>          tcflag_t        c_iflag;        /* input flags */
>          tcflag_t        c_oflag;        /* output flags */
>          tcflag_t        c_cflag;        /* control flags */
>          tcflag_t        c_lflag;        /* local flags */
>          cc_t            c_cc[NCCS];     /* control chars */
>          speed_t         c_ispeed;       /* input speed */
>          speed_t         c_ospeed;       /* output speed */
> };
>
> Since Linux has the extra  cc_t c_line;     /* line discipline */
> unless you've already changed the offset you will poke/extract data
> incorrectly into the
> termios structure.
>
> I'll note someone in the past suggested recoding the logic to make
> primitives to return the offsets, and the constants, thus ensuring
> this will work
> on other unix systems with less effort. Also that would support
> perhaps 64bit unix systems with less effort.



More information about the Squeak-dev mailing list