Navigation script not executing, ideas?

This script looks like it should be executing the navigation, but its not. It is executing everything up to that point. It will even execute the navigation outside of the “if”, any ideas would be great.

import time
	if origin == 'Browser':
		
		wand_num = self.getSibling("TextField").props.text
		scanner_id = self.session.custom.scanner_id
		
		system.tag.writeBlocking('[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Machine_ID', wand_num)
		time.sleep(2)
		status_word = system.tag.readBlocking('[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Status_Word')
		
		
		if status_word == 1:
			self.session.custom.scanner_id = wand_num
			self.getSibling("Label_1").meta.visible = 'true'
			time.sleep(1)
			system.perspective.navigate('/wandscan')
			
			
			
		else:
			self.getSibling("BadMachine").meta.visible = 'true'
			self.getSibling("TextField").props.text = ''
			self.getSibling("Label_1").meta.visible = 'false'

The tab position isn’t correct, but I’m assuming it just pasted into the forum that way.

a couple of ideas off the top of my head:
Try: if str(origin) == 'Browser'

also try temporarily displaying origin somewhere [ie a label], just to make sure it is returning the expected value

Is there any error being logged to the Gateway? Is any of the code within the if statement being executed? Actually, which if is the problem?

Also, meta.visible expects a boolean True/False instead of string "true"/"false".

You need to put .value on the end of that.
system.tag.readBlocking returns a QualifiedValue

A list of qualified values. So, add [0].value.

Also, writing to a tag, waiting a bit and hope something happens during the sleep time, reading something back and acting on that seems a bit fragile.

I would separate the tag write and the rest of the script. Maybe a change script on bound custom property?

Okay, so here’s a list of the problems identified so far:

  1. meta.visible expects a boolean True /False instead of string "true" /"false" .
  2. system.tag.readBlocking EXPECTS a list of tagPaths and RETURNS a list of values from those tagPaths.
  3. system.tag.writeBlocking likewise expects a list of tagPaths and a list of values.

Changes to make:

system.tag.writeBlocking(['[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Machine_ID'], [wand_num])
status_word = system.tag.readBlocking(['[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Status_Word'])[0].value. # [0] to get the 0th index returned QualifiedValue, and .value to obtain the value of the QV
self.getSibling("Label_1").meta.visible = True
self.getSibling("BadMachine").meta.visible = True
self.getSibling("Label_1").meta.visible = False

The system.tag.writeBlocking line is almost certainly where your code is failing, but you should have seen logging in the Gateway that this code was failing on that line.

I was under the same impression, that system.tag.[read|write]Blocking expected a list of tagPaths, but in reality it does work if you pass a string. I was shocked when I saw it, but an Integrator did that very same thing all over one project and it was working.

Also time.sleep() might break in some cases where the computer’s Locale is not English, I’d recommend using java.lang.Thread.sleep() instead.

Interesting information

See here.

Not sure if it was fixed in Jython 2.7.2, but why risk it when java.lang.Thread.sleep() does what I wanted.

1 Like

These are incorrect. A single tag path and value work as well outside of a list. In earlier versions of 8 they didn’t, but a feature request added this back in to mimick the v7 function. However the return is still an array of qualifiedValues

Hmmm. The docs would suggest otherwise. I’ll talk to the Docs team to get them updated.

1 Like

Thanks alot guys! lots of great suggestions. I totally forgot that the readBlocking does in fact return an array. after fixing that issue, it navigated liked it should have. thanks again for help.

For future reference, it’s also super handy especially for Perspective, to add try/except blocks around your code to capture and report any errors to the operators. Make sure you have two excepts, one to catch java.lang.Throwable errors and the other a catch all (which doesn’t catch java).

E.g.

from java.lang import Throwable
try:
	# do stuff
except Throwable:
	shared.perspective.errors.displayError()
except:
	shared.perspective.errors.displayError()

I use a shared library function to display an error to keep it in one spot. For simplicity’s sake, you could just write the error to the console:

def displayError():
	import traceback
	system.perspective.print(traceback.format_exc())
1 Like

@thecesrom.git , @nminchin :
After speaking with the Dev behind the change here, we don’t officially support single tag paths - allowing for only a single tag path (and value) was only added to resolve some other issue. The documentation is the supported usage, and so you should always be wrapping your tag paths and values as lists.

1 Like

Hmm, bummer… will do from now on, but there are lots of places I haven’t! (and not because I’m being dumb and reading single tags when I should be reading multiple together, just to clarify :slight_smile: )