I have a number that I wish to test against a lower value and an upper number.
theTime = system.tag.read('[System]Gateway/CurrentDateTime')
system.tag.write('[default]Events/ALARMS/CurrentHour',int(system.db.dateFormat(theTime.value, 'HH')))
system.tag.write('[default]Events/ALARMS/CurrentMinute',int(system.db.dateFormat(theTime.value, 'mm')))
system.tag.write('[default]Events/ALARMS/CurrentSecond',int(system.db.dateFormat(theTime.value, 'sif qv.value >= 8 and qv.value <= 19:
system.tag.ws')))
event_time_hour = system.tag.read('[default]Events/ALARMS/CurrentHour')
event_time_minute = system.tag.read('[default]Events/ALARMS/CurrentMinute')
event_time_second = system.tag.read('[default]Events/ALARMS/CurrentSecond')
sftreport = system.tag.read('[default]Events/ALARMS/CurrentHour')
if sftreport.value >= 8 and sftreport.value <= 19:
system.tag.write('Events/ALARMS/Shift', 'Day')
My current Hour is 9
When I run the script in the Console, it returns a ‘2’, but the ‘Events/ALARMS/Shift’ tag does not change.
Weirdness: This works.
if sftreport.value >= 8 :
system.tag.write(‘Events/ALARMS/Shift’, ‘Day’)
This does not work.
if sftreport.value <= 19 :
system.tag.write(‘Events/ALARMS/Shift’, ‘Day’)
Help???
Change those write calls to writeSynchronous or writeBlocking depending on what version of Ignition you are on and then add some print statements before the comparison for debugging.
OKAY
theTime = system.tag.read('[System]Gateway/CurrentDateTime')
print theTime
system.tag.writeSynchronous('[default]Events/ALARMS/CurrentHour',int(system.db.dateFormat(theTime.value, 'HH')))
print system.tag.writeSynchronous
system.tag.writeSynchronous('[default]Events/ALARMS/CurrentMinute',int(system.db.dateFormat(theTime.value, 'mm')))
print system.tag.writeSynchronous
system.tag.writeSynchronous('[default]Events/ALARMS/CurrentSecond',int(system.db.dateFormat(theTime.value, 'ss')))
print system.tag.writeSynchronous
event_time_hour = system.tag.read('[default]Events/ALARMS/CurrentHour')
print event_time_hour
event_time_minute = system.tag.read('[default]Events/ALARMS/CurrentMinute')
event_time_second = system.tag.read('[default]Events/ALARMS/CurrentSecond')
sftreport = system.tag.read('[default]Events/ALARMS/CurrentHour')
print sftreport
if sftreport.value >= 8 and sftreport.value <= 19:
print 'Day'
system.tag.write('[default]Events/ALARMS/Shift', 'Day')
The Response is:
>>>
[Tue Jul 07 11:01:12 EDT 2020, Good, Tue Jul 07 11:01:12 EDT 2020 (1594134072446)]
<java function writeSynchronous 0x2>
<java function writeSynchronous 0x2>
<java function writeSynchronous 0x2>
[11, Good, Tue Jul 07 11:00:27 EDT 2020 (1594134027287)]
[11, Good, Tue Jul 07 11:00:27 EDT 2020 (1594134027287)]
>>>
I do not get an error.
Can you add one like this:
print type(sftreport.value)
Sure Thing
Event_Time = system.tag.read('[System]Gateway/CurrentDateTime')
print Event_Time
system.tag.writeSynchronous('[default]Event/ALARMS/CurrentHour',int(system.db.dateFormat(Event_Time.value, 'HH')))
print system.tag.writeSynchronous
system.tag.writeSynchronous('[default]Event/ALARMS/CurrentMinute',int(system.db.dateFormat(Event_Time.value, 'mm')))
print system.tag.writeSynchronous
system.tag.writeSynchronous('[default]Event/ALARMS/CurrentSecond',int(system.db.dateFormat(Event_Time.value, 'ss')))
print system.tag.writeSynchronous
event_time_hour = system.tag.read('[default]Event/ALARMS/CurrentHour')
print event_time_hour
event_time_minute = system.tag.read('[default]Event/ALARMS/CurrentMinute')
event_time_second = system.tag.read('[default]Event/ALARMS/CurrentSecond')
sftreport = system.tag.read('[default]Event/ALARMS/CurrentHour')
print sftreport
print sftreport.value
if sftreport.value >= 8 and sftreport.value <= 19:
print 'Day'
system.tag.write('[default]Event/ALARMS/Shift', 'Day')
And the reply:
[Tue Jul 07 11:49:50 EDT 2020, Good, Tue Jul 07 11:49:50 EDT 2020 (1594136990038)]
<java function writeSynchronous 0x2>
<java function writeSynchronous 0x2>
<java function writeSynchronous 0x2>
[11, Good, Tue Jul 07 11:00:27 EDT 2020 (1594134027287)]
[11, Good, Tue Jul 07 11:00:27 EDT 2020 (1594134027287)]
11
That’s not what I asked for…
1 Like
Kevin is attempting to check the type of the tag you are reading/writing to because he suspects it is a String tag. I can’t explain why you found that one comparison works, but Kevin’s theory would explain the general issue:
Because:
Python 2.7.16 (default, Apr 17 2020, 18:29:03)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print '11' >= 8
True
>>> print '11' <= 19
False
>>> print int('11') >= 8
True
>>> print int('11') <= 19
True
>>>
Thank You.
Very odd that the compare works one way but not the other.
That’s because it’s looking at the ordinal values in the string
print(ord('1'))
>>> 49
I would verify that the tags you’re using are Integer tags. If they must be String tags, then change your comparison to:
if 8 <= int(sftreport.value) <= 19: