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]> |
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