# Script speed per machine from machineid and speed

**URL:** <https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214>\
**Category:** Ignition\
**Created:** [May 31, 2022, 3:05pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214 "2022-05-31T15:05:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 31, 2022, 3:05pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214/1 "2022-05-31T15:05:10Z")

</div>

Two tags are being updated as many machines change speeds.

I want to parse these changes into the respective machine speeds.

example the inputs:

```auto
ID tag: 1000054
speed tag: 1001

```

Then after a few seconds, it might read:

```auto
ID tag: 100054
speed tag: 0

```

```auto
ID tag: 100067
speed tag: 0

```

My machines are like BR1, BR2, PK-5 for a few examples.

I can get the same speed consecutively.  
I can get the same machine consecutively.

So my first question is, how do I detect the change correctly for when to run my script?  
I don’t want a race condition that leads to reading the wrong speed for an extended period of time.

---

<div class="post-metadata">

**Author:** ![dustin.cooper](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dustin.cooper/32/29963_2.png) [@dustin.cooper](https://forum.inductiveautomation.com/u/dustin.cooper)\
**Post date:** [May 31, 2022, 3:16pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214/2 "2022-05-31T15:16:01Z")

</div>

Let me see if I understand your intention correctly: are you wanting to use the ID tag value as a pointer to which machine’s speed you want to update with the value found in “speed tag”?

Another question that comes to mind is, do the ID tag and speed tag values always update simultaneously? If so, you could create an expression tag that is a concatenation of ID and speed, and run a tag change event script on the expression tag, since its value will change if either source value changes.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [May 31, 2022, 3:26pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214/3 "2022-05-31T15:26:50Z")

</div>

Tag change Script?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 31, 2022, 4:40pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214/4 "2022-05-31T16:40:46Z")

</div>

yes, and I want to avoid a race condition.

If the speed tag is the same, I don’t think an on-change for speed is triggered as the value is the same.

Scenario 1  
Speed comes in the same value, for a different machine.  
I don’t think the speec tag will detect a change to trigger a script.

scenario 2  
Same machine gets a speed update.  
I don’t think the machineid tag will detect a change to trigger a script

I have a hard time describing this. Sorry

Is there a way to have a tag that will indicate if either of those two tags changed?  
Or am I worried about a race condition that is not a conflict of concern?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 31, 2022, 5:04pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214/5 "2022-05-31T17:04:34Z")

</div>

> [@zacharyw.larson](#):
>
> Or am I worried about a race condition that is not a conflict of concern?

You cannot get rid of the race condition. Any time you read these, in any order, you cannot be sure the fresh value goes with other read just before it.

This is a terrible design for multiplexing. Don't do it. You _ **will** _ get speeds allocated to the wrong machine, randomly.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 31, 2022, 5:05pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214/6 "2022-05-31T17:05:26Z")

</div>

edit: I pretty much have to find some trigger in the plc that doesn’t have the condition or write one basically.

Thanks again.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 31, 2022, 5:08pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214/7 "2022-05-31T17:08:48Z")

</div>

Have separate speed tags for each machine, ideally.

Otherwise, you need a trigger tag and echo tag for a proper handshake, and use a scripted OPC read to pull in the speed & machine after the trigger. The PLC must increment the trigger after setting both speed and machine, then absolutely not touch them until Ignition echoes the trigger.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [May 31, 2022, 5:13pm UTC](https://forum.inductiveautomation.com/t/script-speed-per-machine-from-machineid-and-speed/60214/8 "2022-05-31T17:13:57Z")

</div>

It has a datetime short array of integers. (year, month, day, minutes, seconds all integers)  
Rs logix  
If I try to make that a tag though, the path doesn’t save.  
Seems to not like trying to collect that information.

edit: found a post where a guy used 3 UDTs to get the array. I am going to see if my plc has a trigger I can use for when it captures the date time.

edit: found a tag to use as a trigger to read both ID and speed, to write the speed.
