10/29/2024 3:37 PM | |
Joined: 2/27/2024 Last visit: 3/13/2025 Posts: 14 Rating:
|
How do I get an array of 0-5 bool to a script so I can read and write to each of them. It needs to be kept as an array and not individual tags because I need to find the first array that is false, use that number for a different function and then turn that tag to true, unless there's a different way to search through the tags without them being in an array. This is one way I have tried, but I get nothing on Index tag0 = Tags('arraytag[0]'); tag1= Tags('arraytag[1]'); tag2 = Tags('arraytag[2]'); tag3= Tags('arraytag[3'); tag4= Tags('arraytag[4]'); tag5= Tags('arraytag[5]'); let Array = [tag0,tag1,tag2,tag3,tag4,tag5]; let index = array.indexOf('0'); |
10/29/2024 5:04 PM | |
Joined: 12/14/2022 Last visit: 1/16/2025 Posts: 78 Rating:
|
if I understand what you need, this might help
I am assuming you are running it on a Unified.. |
Last edited by: Igor_Coraine_ at: 10/29/2024 17:12:19Last edited by: Igor_Coraine_ at: 10/30/2024 10:54:19igorcoraine.github.io |
|
10/29/2024 6:17 PM | |
Joined: 11/28/2023 Last visit: 2/26/2025 Posts: 21 Rating:
|
He, i think you have to read the tags before. e.g. tag0 = Tags('arraytag[0]').Read(); Best regards, Timm |
10/30/2024 10:46 AM | |
Joined: 2/27/2024 Last visit: 3/13/2025 Posts: 14 Rating:
|
If I do like this, "Index" will become 2. But instead of putting numbers in my array I need to put HMI tags. let array = ["1","1","1","0","0","0"] let index = array.indexOf('0'); I have tried; let array = [0,0,0,0,0,0] array[0] = Tags("Arraytest[0]").Read(); array[1] = Tags("Arraytest[1]").Read(); array[2] = Tags("Arraytest[2]").Read(); array[3] = Tags("Arraytest[3]").Read(); array[4] = Tags("Arraytest[4]").Read(); array[5] = Tags("Arraytest[5]").Read(); let index = array.indexOf('0'); and also tag0 = Tags("Arraytest[0]").Read(); tag1 = Tags("Arraytest[1]").Read(); tag2 = Tags("Arraytest[2]").Read(); tag3 = Tags("Arraytest[3]").Read(); tag4 = Tags("Arraytest[4]").Read(); tag5 = Tags("Arraytest[5]").Read(); let array = [tag0,tag1,tag2,tag3,tag4,tag5] let index = array.indexOf('0');
|
10/30/2024 10:54 AM | |
Joined: 11/28/2023 Last visit: 2/26/2025 Posts: 21 Rating:
|
Not sure if i understand correctly - to get the value you want to use .Read() - to get the name of the tag itself you can use .Name Example: tag0 = Tags("Arraytest[0]"); tag0.Read(); // Read value tag0.Name; // Get name as string |
Last edited by: Timm H. at: 10/30/2024 10:56:59 |
|
10/30/2024 11:01 AM | |
Joined: 12/14/2022 Last visit: 1/16/2025 Posts: 78 Rating:
|
your Arraytest is already a list. I don´t get why you want to convert your plc array into a js list. Did you check the script I´ve sent? You will find the first false value in the array.
|
igorcoraine.github.io |
|
10/30/2024 12:53 PM | |
Joined: 2/27/2024 Last visit: 3/13/2025 Posts: 14 Rating:
|
Yes I want an array of bool and not strings, I have and array of bool in HMI tags that I need to use. So I thought that I hade to use the Tags("xxx").Read() function to get that tag into my script? I can't understand the code you send, I can't find a good explanation on the For..In-loop snippet. If you can explain it a bit more step by step I would love to try it out. |
10/30/2024 1:36 PM | |
Joined: 12/14/2022 Last visit: 1/16/2025 Posts: 78 Rating:
|
Sorry, I missed the read tag first, but you can read the whole array directly. Then you can read it and use it as an array.
--------- For in loop will run throw the itens of a list. For example if you have a list
it you can create
then value will end with value 3, because the for will run the list and number (you can name the way you want) will have the values of the list according to the index each time it loops. --------- If you prefer you can use the first part of your code, but instead of using the indexOf(), you need to do a for to find the false. If it is a fixed size array, you could also use a regular for
|
Last edited by: Igor_Coraine_ at: 10/30/2024 14:02:53igorcoraine.github.io |
|
10/31/2024 10:46 AM | |
Joined: 2/27/2024 Last visit: 3/13/2025 Posts: 14 Rating:
|
I still get very strange results, the script is on a button so the first I click it works well except for that it will not put true in my array. But I will get a number back in foundindex, if the first one which is false is 2 the foundindex will be 2. If I then go and change number two to true manually, the second time I click it will still return the value 2 to me instead of looking for the next one. let Array = Tags("Arraytest").Read(); let foundIndex = -1; for(let i = 0; i < 5; i++){ if (!Array[i]){ foundIndex = i; Array[i] = true; break; } }
|
10/31/2024 11:05 AM | |
Joined: 11/13/2018 Last visit: 3/12/2025 Posts: 84 Rating:
|
Hello AutoGen_6988694, Do you write the values to the HMI tag? Hopefully, this bit of code will work:
|
Like it? Rate it! |
|