RE: problem using OneWireContainer12 with threads

Scott Hughes <Scott.Hughes-6tN4nzCoH/[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.tini
Message-ID <[email protected]>
You could try either writing your own mutexes to protect access to the
DSPortAdapter object, or use the ones included.  Try adding this around all
calls to owc12 methods:

try
{ 
   adapter.beginExclusive(true);
   owc12.setLatchState(channel, on, false, state);
   owc12.writeDevice(state);
catch( ... )
{}
finally
{
   adapter.endExclusive();
}

Scott
--
Scott Hughes - Engineer
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
> 
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.