I am running sikuli script on a computer that automates data acquisition for some of my instruments. I have recently installed PyVisa and i am able to connect and communicate with my instruments using python without any issues. Is there a way i can import the Visa module in sikuli and use it to communicate with my instruments the same way as i would in python ?
Import Python Pyvisa Module in Sikuli
1.1k Views Asked by lilgulpa At
2
There are 2 best solutions below
0

I was trying to import a Python Library: jenkinsapi into the Jython Sikuli environment. After several attempts to combine the two the best solution I came up with involved the following:
From within your Sikuli Editor import os, and define a function to run the code you cant import into Jython.
import os
def installBuild():
os.system("C:\\Users\\time\\Desktop\\FDSmokeTest\\fdoc_build.py")
Python is able to access the jenkinsapi but Jython is unable, creating a simple python file then having your Sikuli Jython code execute a system call to run the Python.
from jenkinsapi.jenkins import *
import os
import unittest
import sys
from subprocess import call
def getSCMInfroFromLatestGoodBuild(url, jobName, username=None, password=None):
print "Getting Latest Good Build: http://addresstoourjenkins.com:9087 Job: Daily_Windows"
J = Jenkins(url, username, password)
job = J[jobName]
lgb = job.get_last_good_build()
print "Latest Good Daily Windows Build: " + str(lgb)
return lgb
def installBuild(buildnum):
print "Installing " + buildnum + " wait a few minutes while installation completes"
os.system("C:\Users\time\Desktop\FDSmokeTest\install.bat " + buildnum)
if __name__ == '__main__':
temp = getSCMInfroFromLatestGoodBuild('http://addresstoourjenkins.com:9087', 'Daily_Windows')
buildnum=str(temp).replace('Daily_Windows ', '')
installBuild(buildnum)
Sikuli uses Jython to run. Pure-Python code will (almost always) work normally, but Python code with native C code will not work. I'm not familiar with PyVISA, but it looks like pure Python, so I'd give it a try.
You'll need to put PyVISA somewhere that Jython looks. Take a look at the Jython documentation.