I’ve got an application where I can have up to 4 timers enabled and sending data out a shared serial port once a second.
The data is sent to a display, and we should see four sets of data changing on the display. However, occasionally one or more of the sets of data isn’t getting updated on the display. Obviously, one timer is sending data out the serial port, before another timer has had a chance to grab the serial port to send it’s data.
I assume I’ll need to set up threads/critical sections, etc… I’ve been reading up about critical sections, but can not find any code examples.
Can anyone point me in the right direction?
Seems like it would be easier to set up a queue and have each timer append the data to the queue. Then have a single process, such as a thread, own the serial port and send data as it becomes available.
I’ve tried setting up a semaphore, by following an example in the language docs, but that hasn’t made any difference, which surprised me. I’m not at home at the moment, but I have added “serial1.xmitwait” before each serial1.write in my code during my lunch break, so will see if that works this evening.
I did think about setting up a queue, but I might have the same issue with 4 timers trying to access that queue to append to it?
I’ve tried setting up a semaphore, by following an example in the language docs, but that hasn’t made any difference, which surprised me. I’m not at home at the moment, but I have added “serial1.xmitwait” before each serial1.write in my code during my lunch break, so will see if that works this evening.
I did think about setting up a queue, but I might have the same issue with 4 timers trying to access that queue to append to it?[/quote]
If it’s just an array of objects and you’re calling .Append on it, there should be no problem. Make sure you’re just grabbing element zero and removing it from the array and you should be good to go.
Thanks for all your replies. Looks like I’ve figured out how to implement threading in Real Studio/Xojo.
I’ve created 4 threads, moved the code for each timer into an associated thread’s run routine, and now the semaphore controls are working as well. Now all four separate sets of data are being updated on the display.
Just took me a while to get my head around how to do it in this environment. Hooray, happy!!