Page 1 of 1

Form freezes x secs when reading multiple sensors.

Posted: Wed Nov 12, 2008 1:57 pm
by de.lesse
Not really a 1-wire topic, more programming...

When reading 7 1-wire devices in a row, my main form freezes for 7 seconds.
I know that reading a device take 750ms. It doesn't take cpu usage to read a device.

How can i change my code to 'multithread' my application, so i can do something else while reading the devices?
What kind of threading should i use. I don't want to try all possibilities to spend time...

vb.net2005 owapi written app.

timer is running, sub starts after every x time
read all active enabled devices in a row
some checks (doesn't make a difference when disabling this line)
write after every read to sql
back to timer...

Form freezes x secs when reading multiple sensors.

Posted: Fri Nov 14, 2008 1:55 am
by Digit
Threading is not one of the most easy things to explain. I think you can write a complete book about it. All i can say is my knowledge about threading in VB is very very limited, but i do threading quite a lot in my own application using semaphore mailboxes. Before you start using threads, i think the best is to know what you're dealing with and know how they work before you begin using them. Although the following describes threading in another language, you might want to read it since it gives a good impression on how it all works 'under the hood'. It helped me a lot.
http://www.eonclash.com/Tutorials/Multi ... 1/ToC.html

Form freezes x secs when reading multiple sensors.

Posted: Fri Nov 14, 2008 1:48 pm
by Stevexyz
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I know that reading a device take 750ms. It doesn't take cpu usage to read a device<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">Yes and yes! However, if the CPU is used for timing the 1-wire bus then it can get tied up and be unavailable for anything else. My devices also take about 1s second each to read (but I don't read them all at the same time). One solution would be to use an intelligent 1-wire controller (a PIC or something) to do the timing.
Cheers,Steve

Form freezes x secs when reading multiple sensors.

Posted: Sat Nov 15, 2008 1:28 am
by DMB
Hello de.lesse,

I read 3 1 wiredevices with one timer tick and I've got the same problem. I use a separate vb task for reading and write the values in a mysql database and directly in a homeseer device.
Freezing of the form is a not a problem for me.
The interface is a DS9097U.

Here is the code I use.

<b>Download Attachment:</b> [img]images/icon_paperclip.gif[/img] code.txt<br />5.49KB

It's a .vb file (VB .net 2005), but I could not upload a .vb file.

DMB