I am using Ignition version 8.1.3 and a Cognex 7200 camera that does not have HMI view/http capabilities.
I’ve scoured the forums for ways to get Ignition to show the most recent picture from the cognex camera. The best thing I think I found was on this thread: Updating Image component based off of newest image in a directory
I have tried a few things from that thread and from others and can not get a picture to show on the paintable canvas, let alone update pictures to the newest one. The code I’m currently using is:
g = event.graphics filename = r"C:Users/User/Desktop/XXXXX Camera Images" cachedName = event.source.getClientProperty("img-bytes-cached-name") bytes = event.source.getClientProperty("img-bytes-cached") if filename!=cachedName or not bytes: #Image not cached - Load from database #bytes = system.db.runScalarQuery("SELECT data FROM image_test WHERE imgname='%s'"%name bytes = system.file.readFileAsBytes(filename) event.source.putClientProperty("img-bytes-cached", bytes) event.source.putClientProperty("img-bytes-cached-name",filename) if bytes: from javax.imageio import ImageIO from java.io import ByteArrayInputStream #from java.awt.geom import AffineTransform #scale = AffineTransform() image = ImageIO.read(ByteArrayInputStream(bytes)) g.drawImage(image, 0, 0, event.width, event.height, event.source)
I’ve also recently tried:
from java.net import URL from javax.imageio import ImageIO url = URL("C:Users/User/Desktop/XXXXX Camera Images").value # Use this for a Local File url2 = URL("C:Users/User/Desktop/XXXXX Camera Images") #url2 = globals()['url'] icon = ImageIO.read(url2) event.graphics.drawImage(icon, 0, 0, event.source)
I have put these on the Paintable canvas as Paint → Repaint script.
The pictures are being saved to the Ignition computer a .jpg.
I have a feeling I’m not getting my code right and there may be another issue as well. Such as maybe I need to be doing something with the pictures to make this work.
Can anyone help me figure this out please?