Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Thread Plugin

Author
Message
mgilioli
15
Years of Service
User Offline
Joined: 10th Apr 2008
Location:
Posted: 10th Apr 2008 15:20
Hi th everyone,
I am developing a simple plugin which reads from a device attached to the com port. If the received package is good then all the fields of a structure are filled up. Then I added some functions in the DLL in order to access these fields. In order to start the sampling process i use a function called i.e. INIT DEVICE(1), which starts a thread. I have found the following problem: if I add a Sleep(35) inside the thread loop everything seem to work fine, with a lower delay Dark Basic stops to work. Can anyone help me?
Thank you
Marco

Marco
jinzai
17
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 10th Apr 2008 17:02
You should not do that type of thing in a thread (sleep). It kind of goes opposite to the reason for threads in the first place. Are you waiting for all of the data to arrive while sitting in the thread? You should just check to see how much data is in the buffer in the thread, and only take action if there's enough there for you to do something with. It should be a state machine, and not a typical polling routine.
mgilioli
15
Years of Service
User Offline
Joined: 10th Apr 2008
Location:
Posted: 9th Jun 2008 16:06
Hi Jinzai,
thank you for your post. I was trying to implement what you explained me but I still have a doubt: do you think it is better to implement a n "interrupt routine", i.e. once I got a data from the serial port check if I got the full package from the device and then process it and fill all the field up, or still use the thread and check inside for the buffer lenght?

Thank you anyway.
Marco

Marco

Login to post a reply

Server time is: 2024-02-28 20:35:49
Your offset time is: 2024-02-28 20:35:49