[squeak-dev] Named serial ports

Markus Lampert markuslampert at yahoo.com
Sat Sep 19 01:29:15 UTC 2009


Sorry for the post here, I subscribed to vm-dev but cannot post (yet).

I looked into it and there are 2 issues, one in the image and one in the vm.

In SerialPort>>openPort:

    self close.
    (self primClosePort: portNumber) isNil ifTrue: [
        ^ nil ].
  ...

'self close' calls primClosePort: if no port is assigned. So calling primClosePort: explicitely will always call into the vm, although the port should already be closed. Maybe the intent is to safeguard agains 2 instances of SerialPort, but then the openPort: call to the second instance would invalidate the first anyway (which would still have port assigned).

This is what happens: On calling openPort: a call into the vm is performed to close the port. That call (initially) bails out at line 180 in sqUnixSerial.c:
 ...
  if (sp == NULL || sp->spDescriptor < 0)
    {
      success(true);
      return 0;
    }
 ...
because the the serial port was never used and no entry exists in the 'previousSerialFiles' table.

Once the port was opened an entry is created but not destroyed on close. So when primClosePort is called by SerialPort>>openPort: an entry is found in previousSerialFiles and the vm actually tries to close that one (again). Which fails in line 186:
 ...
 if (tcsetattr(sp->spDescriptor, TCSAFLUSH, &sp->spTermios))
...
because the file descriptor is not open anymore.

adding
 ....
 sp->spName[0] = '\0';
 ...
at the end of serialPortCloseByName fixes the problem (and doesn't require a change to SerialPort>>openPort:).

Ha, that was fun,
Markus


----- Original Message ----
> From: Markus Lampert
> >
> >From: Ricardo Moran
> > ....
> >2) The first time I open a port, it works fine. Then, if I close it and open it 
> again, everytime I try #nextPutAll: I get a primitive fail. This happens with 
> port numbers and with port names. The only workaround that I found is closing 
> the Squeak image and open it again. Could it be a bug in the serial plugin?
> 
> Same here, except that SerialPort>>openPort: already fails. I checked with lsof 
> and the file does get closed by the vm but any further opening attempt fails 
> (Debian i586).
> 
> Have fun,
> Markus



      



More information about the Squeak-dev mailing list