Hi,
I get an error ‘No viable alternative at input’. What does it mean and how can I fix it?
Thanks for help.
Hi,
I get an error ‘No viable alternative at input’. What does it mean and how can I fix it?
Thanks for help.
Jython is case-sensitive. “IF” should be “if”
Hi @grzegorz.kaczmarczyk, case matters. Use if
not IF
.
Edit: Beat me by a hair @Matrix_Engineering
Thanks, it works!
You’re both getting hearts, but there can be only one solution
Now I am encountering a different problem.
I want to write ‘1000’ to a variable, when other variable is equal 1. The code I wrote doesn’t work. Nothing happens.
@grzegorz.kaczmarczyk, I believe system.tag.write()
has been depreciated. You should either be using writeAsync or writeBlocking. Note the parameters for these are passed as lists.
.read has also been deprecated, but bear in mind it returns 3 values, you have to get the .value an example shown here:
but as you are on ignition 80/81 you should use the new functions system.tag.readBlocking - Ignition User Manual 8.0 - Ignition Documentation
Just to clarify a bit on what @Matrix_Engineering is saying.
system.tag.read()
still works and returns a qualified value object, to get the value of the tag you have read you must use the .value
property of the qualified value.
However, both @matthew.ayre and @Matrix_Engineering are correct, system.tag.read()
and system.tag.write()
were depricated with Ignition 8.0.0. You should use the new functions as they have detailed.
Also, you should start now making a habit of only calling a tag read/write function as few times as possible. With that in mind your code should look something like this:
tagValues = system.tag.readBlocking(['[default]SQL/MP_ZMIENNA4','[default]PLC/Zmienna1'])
if tagValues[0].value == 1:
system.tag.writeBlocking(['[default]PLC/Zmienna1'],[1000])
I'm assuming that this isn't your entire script, otherwise it isn't necessary to read Zmienna1 unless you plan to use that read value.
As an aside, you should use the preformatted text option </>
or place three back ticks ``` before and after your code, there are some situations where screenshots are useful but when trying to assist with code it is much better to have something that is readable, we can copy and paste from, and that will keep your formatting.
You're missing the closing quote on "items
in line 21.
Yes. Thanks!!
Is it normal after coding many times I am making this mistakes
And then there's the code that works but really shouldn't, and you have to convince people they should REALLY, REALLY not do this, but hey, it works !
I have some very frustrating memories of trying to explain to someone who was assigning arrays of chars in C without first allocating memory that yes, it does happen to work here and now, but that it WILL segfault sooner or later.
"But look, it works !"
gnnnn
For future reference, that is a syntax error, not an execution error. They can usually be spotted by a red box or squiggle in the right-hand margin.