Primitive error handling

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Primitive error handling

Garret Raziel
Hello,
I have another "problem". In windows, my microchip is connected on port 7 (COM7) but I dunno which port number it is in Linux. It is connected in location /dev/ttyUSB0 but I dunno what is its number. I have tried this code to discover it:

|n|
n := SerialPort new.
1 to: 20 do: [:port | n openPort: port. (n isNil) ifFalse: [Transcript show: port]. n close]

but it told me that no port after opening is nil (strange, I thought that on Windows when I tried to open non-existing port, it returned nil). So I have tried another code, reading string from this port by n readString and watching when it does primitiveFailed and when doesn't. But I want only this kind of code (but I dunno how is it named): (n readString isPrimitiveFail) ifFalse: [Transcript show: ...]. How can I do it? Thanks for response.

Garret Raziel


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Primitive error handling

Yoshiki Ohshima-2
At Sun, 7 Feb 2010 13:45:00 +0100,
Garret Raziel wrote:

>
> Hello,
> I have another "problem". In windows, my microchip is connected on port 7 (COM7) but I dunno which port number it is in
> Linux. It is connected in location /dev/ttyUSB0 but I dunno what is its number. I have tried this code to discover it:
>
> |n|
> n := SerialPort new.
> 1 to: 20 do: [:port | n openPort: port. (n isNil) ifFalse: [Transcript show: port]. n close]
>
> but it told me that no port after opening is nil (strange, I thought that on Windows when I tried to open non-existing port,
> it returned nil). So I have tried another code, reading string from this port by n readString and watching when it does
> primitiveFailed and when doesn't. But I want only this kind of code (but I dunno how is it named): (n readString
> isPrimitiveFail) ifFalse: [Transcript show: ...]. How can I do it? Thanks for response.

  The method #on:do: is usable here.  you can say:

  [n readString] on: Error do: [:exception | Transcript show: port; cr].

or such in the loop and effectively skip the ports that cause errors.

-- Yoshiki
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners