Ciao,
> Try adding (Smalltalk garbageCollect) after the #close.
I add it, but after the SerialPort allInstances return an array with
aSerialPort.
Strange it's close.
I found what "generate" the problem it's in the openPort: method.
----------------------------------------------------------------
openPort: portId
"Open the given serial port, using the settings specified by my
instance variables."
| result |
self close.
"8-10 - wks - this has to tell us if it fails: step 1, save the
primitive result"
result := portId isString
ifTrue: [self
primOpenPortByName: portId
baudRate: baudRate
stopBitsType: stopBitsType
parityType: parityType
dataBits: dataBits
inFlowControlType: inputFlowControlType
outFlowControlType: outputFlowControlType
xOnByte: xOnByte
xOffByte: xOffByte]
ifFalse: [self
primOpenPort: portId
baudRate: baudRate
stopBitsType: stopBitsType
parityType: parityType
dataBits: dataBits
inFlowControlType: inputFlowControlType
outFlowControlType: outputFlowControlType
xOnByte: xOnByte
xOffByte: xOffByte].
"wks - raise an error if there was a failure."
result isNil ifTrue:[ self error:'Cannot open ', portId printString. ].
port := portId
_------------------------------------------------
The result isNotNil the thirst time i call the
openPort: it's set at aSerialPort
isNil the last time i
call the openPort
But if i remove the test : result isNil ifTrue:[ self
error:'Cannot open ', portId printString. ].
all works fine the first and the following call.
There is something wrong in the primitive call answer.
Anyone is expert in this ?
Thanks,
Dario
>
> Now a question of my own for the list. Why does it seem common to do three
> #garbageCollects in a row.
>
> cheers -ben
>
>
> Sven Van Caekenberghe wrote:
>>
>> Dario,
>>
>> On 17 Feb 2014, at 12:55, Dario Trussardi <[email protected]> wrote:
>>
>>
>>> Thanks Sven,
>>>
>>>
>>>> You should #close the port when you are done, else it remains in use, I
>>>> would guess.
>>>>
>>> Of course, i used :
>>>
>>>
>>> | srl |
>>> srl := SerialPort new.
>>> srl openPort: 'COM1'.
>>>
>>> srl nextPutAll: #[ 27 66 2 2 ] .
>>>
>>> srl close.
>>>
>>> But after the first time, when submit the same code the system answer:
>>>
>>> Error: Cannot open 'COM1'
>>>
>>> I don't unterstand because.
>>>
>>
>> Me neither. I have no experience working with serial ports (but I know some
>> people on the list do), let alone on Windows, but from looking at the code
>> #close should be enough.
>>
>>
>>> I note what the sometimes SerialPort allInstances answer
>>> instance after the close method.
>>>
>>> Perhaps remain occupied some resources?
>>>
>>
>> They are still there because they are not yet garbage collected. If they are
>> properly closed (check the printString in the inspector), the external
>> resource should have been released.
>>
>> Sorry, but I can't help you any further.
>>
>> Sven
>>
>>
>>> Ciao,
>>>
>>> Dario
>>>
>>>
>>>> Also, why do you #close before you start, seems strange to me ?
>>>>
>>>> On 17 Feb 2014, at 12:05, Dario Trussardi <[email protected]>
>>>> wrote:
>>>>
>>>>
>>>>> Ciao,
>>>>>
>>>>>
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'm also interested by an answer to that question. So far, what I have
>>>>>> as status is: you need a plugin to handle communications with the serial
>>>>>> port (either for direct RS232 or USB-to-Serial) and compiling the serial
>>>>>> port plugin with the Pharo VM makes it unstable.
>>>>>>
>>>>> I dont know " compiling " plugin area. ( i work with Windows 7 )
>>>>>
>>>>>
>>>>>> The solution we used was: to compile the serial plugin for the squeak VM
>>>>>> and work in Squeak (4.3) instead of Pharo.
>>>>>>
>>>>> Can you explain more detail about it?
>>>>>
>>>>>
>>>>> My test is :
>>>>>
>>>>>
>>>>> I download the Pharo 2.0 #20628 and i use the
>>>>> SerialPort class.
>>>>>
>>>>> The first time i do the code:
>>>>>
>>>>> | srl |
>>>>>
>>>>> srl := SerialPort new.
>>>>> srl close.
>>>>>
>>>>> srl openPort: 'COM1'.
>>>>>
>>>>> srl nextPutAll: #[ 27 66 2 2 ] .
>>>>>
>>>>> The RS232 device work fine.
>>>>>
>>>>> After the first time, when submit the same code the system answer:
>>>>>
>>>>> Error: Cannot open 'COM1'
>>>>>
>>>>> A this time i need to restart the Pharo environment.
>>>>>
>>>>>
>>>>> Any considerations, suggestions ?
>>>>>
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Dario
>>>>>
>>>>>
>>>>>
>>>>>> Thierry
>>>>>>
>>>>>> Le 16/02/2014 16:28, Dario Trussardi a écrit :
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>>
>>>>>>> i work with: Pharo1.Latest update: #14445
>>>>>>> ( or with: Pharo2.0 Latest update: #20628 ).
>>>>>>>
>>>>>>>
>>>>>>> I'm interested to manage communications with USB or
>>>>>>> RS232 device.
>>>>>>>
>>>>>>>
>>>>>>> I can find package which support this protocol?
>>>>>>>
>>>>>>> Thank for any considerations ?
>>>>>>>
>>>>>>> Dario
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> --
>>>>>> Thierry Goubier
>>>>>> CEA list
>>>>>> Laboratoire des Fondations des Systèmes Temps Réel Embarqués
>>>>>> 91191 Gif sur Yvette Cedex
>>>>>> France
>>>>>> Phone/Fax: +33 (0) 1 69 08 32 92 / 83 95
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>>
>>
>>
>