Re: Re: problem using OneWireContainer12 with threads
Richard Wettel <rwettel-M8/[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Organization | ETA Automatizari Industriale |
| Message-ID | <[email protected]> |
Thank you Scott,
It helped a lot. Now I can go further with my project.
The problem was that in the main thread there was a beginExclusive
call which didn't permit access to the bus from within other threads.
Thanks one more time. Problem solved.
Richard Wettel
Software Developer
ETA AI
Timisoara/Romania
Wednesday, February 18, 2004, 6:25:59 PM, you wrote:
SH> You could try either writing your own mutexes to protect access to the
SH> DSPortAdapter object, or use the ones included. Try adding this around all
SH> calls to owc12 methods:
SH> try
SH> {
SH> adapter.beginExclusive(true);
SH> owc12.setLatchState(channel, on, false, state);
SH> owc12.writeDevice(state);
SH> catch( ... )
SH> {}
SH> finally
SH> {
SH> adapter.endExclusive();
SH> }
SH> Scott
SH> --
SH> Scott Hughes - Engineer
SH> shughes aht dalsemi daut com
>> -----Original Message-----
>> From: tini-admin-6tN4nzCoH/[email protected]
>> [mailto:tini-admin-6tN4nzCoH/[email protected]]On Behalf Of
>> Richard Wettel
>> Sent: Wednesday, February 18, 2004 6:35 AM
>> To: tini-6tN4nzCoH/[email protected]
>> Cc: claudiu.suma-M8/[email protected]
>> Subject: [TINI]problem using OneWireContainer12 with threads
>>
>>
>> Hi everyone,
>>
>> I've been experiencing some problems related with using the
>> OneWireContainer12 class with threads.
>> I have a method that opens or closes one of the two switches that this
>> relay has (I'm talking about the DS2406).
>>
>> >From the main thread I can call this method to open one of
>> the switch,
>> then wait for a while and then call the same parametrised method now
>> to close the switch that I previously opened.
>>
>> The application specifications don't allow me to wait that time in the
>> main thread and I tried a solution in which I open the switch and then
>> I start a timer (running in another thread), and when its time
>> expires, it will call a method of the main thread, which will actually
>> call the method to close the switch. The problem is that I manage to
>> open the switch, start the timer thread and go on in the main thread,
>> and when the time expires, the timer calls the method in the main
>> thread which calls the setLatchState method of the OneWireContainer12
>> object succesfully, and then calls the writeDevice method of the same
>> object... and this is the moment I get an OneWireException...
>> The API javadocs don't give me any clue on the problem... it's not an
>> OneWireIOException, so it doesn't handle on communication problems. I
>> suppose it's all about how TINI goes with the threads and the
>> communication between them.
>> I tried about 3 variations to this solution, getting the same result.
>>
>>
>> Here is part of the code...
>>
>> <Relay class - that has among others an OneWireContainer12
>> object, called owc12>
>>
>> class Relay{
>> ...
>> public boolean setChannelState(int channel, boolean on)
>> {
>> try {
>> owc12.setLatchState(channel, on, false, state);
>> owc12.writeDevice(state);
>>
>> ...
>> }
>> ...
>> }
>>
>>
>>
>> <App class - main application thread>
>>
>> public static void main(String[] args){
>>
>> ...
>> while(true){
>> ...
>> int channel = 0;
>> setChannelState(channel, true);
>> Timer timer = new Timer(channel, time);
>> timer.start();
>> //continue with the regulations
>> ...
>> }
>> ...
>>
>> public static closeRelay(indexRelay, channel){
>> relays[indexRelay].setChannelState(channel, false);
>> }
>>
>>
>>
>> <Timer class>
>>
>> public class Timer extends Thread{
>> private long time;
>> private int indexRelay;
>> private int channel;
>>
>> public Alarm(long time, int indexRelay, int channel){
>> this.indexRelay = indexRelay;
>> this.time = time;
>> this.channel = channel;
>> }
>>
>> public void run(){
>> try{
>> sleep(time);
>> }
>> catch(InterruptedException e){}
>> App.closeRelay(indexRelay, channel);
>> }
>> }
>>
>>
>>
>> If any of you has expoerienced similar problems, please post an answer
>> on the group or send me an e-mail. Any advices would be appreciated.
>>
>>
>> Richard WETTEL,
>> Software Developer
>> ETA AI
>> Timisoara/Romania
>>
>> _______________________________________________
>> TINI mailing list
>> TINI-6tN4nzCoH/[email protected]
>> To UNSUBSCRIBE, edit your profile, or see list archives:
>> http://lists.dalsemi.com/mailman/listinfo/tini
>>
SH> _______________________________________________
SH> TINI mailing list
SH> TINI-6tN4nzCoH/[email protected]
SH> To UNSUBSCRIBE, edit your profile, or see list archives:
SH> http://lists.dalsemi.com/mailman/listinfo/tini
--
Best regards,
Richard mailto:rwettel-M8/[email protected]
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini