Can two handlers access a variable at the same time?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Can two handlers access a variable at the same time?

Post by Simon Knight » Thu Feb 04, 2010 1:50 pm

The Background : I am attempting to read and process data received on a serial port at 4800 baud. I can read the port o.k. and display the lines of data in a field but when I attempt to process the data in someway the time it takes to process means that I either miss messages or start to lag behind.

My attempt at a solution involves writing the line of data to a local variable and then accessing the variable from inside a second handler. Both my port reading handler and the variable reading handler recall themselves after 10 ticks. The only processing I have attempted so far is to display the line of data in a field. The problem is that the lines seem to get corrupted and I was wondering if my variable is being worked on by both the handlers at the same time and that this is causing the corruption.

I have posted similar questions under a couple of serial port threads but as yet no one has offered any answers. I'm hoping that by rephrasing the question some one may notice it.

Thanks for reading
best wishes
Skids

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Can two handlers access a variable at the same time?

Post by Mark » Sun Mar 07, 2010 10:31 am

Hi Simon,

I believe you should post your scripts. What you describe should be possible.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Can two handlers access a variable at the same time?

Post by Simon Knight » Sun Mar 07, 2010 1:14 pm

Hi Mark,

Thanks for your reply. I (with much help from the forum) solved the initial problem by changing how I read data from the port. My project has changed from reading data from a GPS to reading data from a hall sensor. It is now nearing completion and when finished I propose to write it up as a demonstration of what is possible for a new user to achieve using RunRev and an interface card like Arduino.

best wishes

Simon
best wishes
Skids

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Can two handlers access a variable at the same time?

Post by bn » Sun Mar 07, 2010 2:34 pm

Simon,
as Mark pointed out it is difficult to tell what is going on without more detail. The relevant parts of the script would be helpful. What if you'd copy the variable after the reading is done to another variable for access by the second routine. If the two routines interleave and act on the data some sort of confusion seems possible.
regards
Bernd

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Can two handlers access a variable at the same time?

Post by Simon Knight » Mon Mar 08, 2010 9:10 am

20100217-P1000257.jpg
Inside the box
20100217-P1000257.jpg (82.42 KiB) Viewed 4707 times
20100306-P1000391.jpg
Approximator V2
20100306-P1000391.jpg (183.63 KiB) Viewed 4707 times
Hi Bernd,

Thanks for your help. My original post is quite old (beginning of Feb) and you have already helped me solve the problem which was covered in another series of posts. I do intend publishing my code but in the form of a report that describes the creation of my "approximator" which involves interfacing with an Arduino card and driving a home brew display of 7 LEDs based on reading obtained from a magnetic speed sensor fitted to a speedo cable. My device is being fielded next weekend in a historic car rally taking place in Spain next weekend, which is where I will find out if my soldering will hold up to the vibration. The two pictures show the device and its contents in prototype form. The pencil is pointing at the hall effect sensor.

I would like to thank you and the other members of the forum for all the help and encouragement that I have had since joining last Autumn .

best wishes

Simon
best wishes
Skids

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Can two handlers access a variable at the same time?

Post by Mark » Mon Mar 08, 2010 10:45 am

Hi Simon,

That looks very cool and I am realy curious about what you can tell us about your hardware interfacing adventure.

I like your mug, btw.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply