Importing python packages

Everything OAD-related that won't fit in the other categories: share general aspects of macro programming and discuss the OAD environment
Post Reply
user-18
Posts: 4
Joined: Thu Jan 01, 1970 1:00 am

Importing python packages

Post by user-18 »

Hi,

I am having difficulty importing python modules into Zen 2012 for the macro environment. I am getting 'ArgumentOutOfRangeException: Value must be between 1 and ...
Parameter name: number
Actual value was ...

I am able to import simple modules, but once the packages I import require other modules, a problem occurs. One example of a module I would like to be able to use is pySerial.

I start by adding the Python27\lib and \lib\site -packages directories to sys.path, and then import the module.

Am I incorrectly loading the python modules into Zen's ironPython ? Please advise.

Thank you
user-8
Posts: 63
Joined: Thu Jan 01, 1970 1:00 am

Post by user-8 »

Hi,

can you post the macro code, because for me this works fine in an OAD macro.

Code: Select all

import sys
sys.path.append(r'C:\Python27\Lib\site-packages')
# check where Zen is looking for stuff
print sys.path

import serial as ps

print 'OK'
user-18
Posts: 4
Joined: Thu Jan 01, 1970 1:00 am

Post by user-18 »

Code: Select all


import sys
import serial
from time import sleep
sys.path.append(r'C:\Python27\Lib\site-packages')

ser = serial.Serial(2)
print ser.portstr
print ser

ser.write("/1V300000R\r\n")
sleep(1)
ser.write("/1z4550000R\r\n")
sleep(1)
ser.write("/1P4550000R\r\n")
ser.close()

Code: Select all

COM4
Serial<id=0x2f, open=True>(port='COM4', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
Error Popup at ser = serial.Serial(2) during debugging

Code: Select all

ArgumentOutOfRangeException: Value must be between 1 and 16
Parameter name: number
Actual value was 44

This code works fine in the python shell for the device on COM4
user-18
Posts: 4
Joined: Thu Jan 01, 1970 1:00 am

Post by user-18 »

Hi,

Is there any update on this issue?
Carl Zeiss Microscopy 6 wrote:Hi,

can you post the macro code, because for me this works fine in an OAD macro.

Code: Select all

import sys
sys.path.append(r'C:\Python27\Lib\site-packages')
# check where Zen is looking for stuff
print sys.path

import serial as ps

print 'OK'
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

Hello,

It is very difficult for us to verify your question as we do not have your environment.
Please assure that you compare the very same versions of IronPython.
Sorry, but it seems that we cannot offer more help.

Maybe this theme is related to your problem
http://stackoverflow.com/questions/3024760/pyserial-and-ironpython-get-strange-error
user-18
Posts: 4
Joined: Thu Jan 01, 1970 1:00 am

Post by user-18 »

Carl Zeiss Microscopy 3 wrote:Hello,

It is very difficult for us to verify your question as we do not have your environment.
Please assure that you compare the very same versions of IronPython.
Sorry, but it seems that we cannot offer more help.

Maybe this theme is related to your problem
http://stackoverflow.com/questions/3024760/pyserial-and-ironpython-get-strange-error
Thank you for your response. However, I have looked at that link before and it does not apply to my situation.

It looks like you installed the module in the previous response, so were you able to load the python module and write() commands to any serial device? (Rather than just import the module and not actually use the most important part Seria.write() ! )

I ended up using system.io.ports.serialport (from System import *) and will not likely need any other python modules for my project, but it is worth nothing that I was getting a similar error from other imported python Modules in zen.
user-3622
Posts: 10
Joined: Thu Jan 01, 1970 1:00 am

No module named serial

Post by user-3622 »

Hi, I tried to import the serial module into the ZEN2.3 Macor Editor.

------------------------------
# import serial
import sys
sys.path.append(r'C:\Python27\Lib\site-packages')
# check where Zen is looking for stuff
print sys.path

import serial as ps

print 'OK'
-------------------------------

However I get the error message: No module named serial.

I have Python2.7 installed with the pyserial package in the specified path.
Any suggestions?
Christian
Post Reply