VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic Example for VS with Python

Hello.  Anyone got a basic script for non-deterministically reading an writing to a channel in Python using the verion 2.0.x?

 

Even opening a simple channel reference like in the example documentation errors out with "Python.Runtime.PythonException: 'str' value cannot be converted to NationalInstruments.VeriStand.Data.DoubleValue" which is weird because if you go the ChannelReference function they specifically give an example that you pass it a str.

from niveristand import nivs_rt_sequence, realtimesequencetools
from niveristand.clientapi import ChannelReference


def readchannel():
mdlcount = ChannelReference('Targets/Controller/System Channels/Model Count')
print("This is the end")


if __name__ == '__main__':
readchannel()

The State Machine exmaple int he doc pretty much does the exact same thing when it does '

output = ChannelReference('Aliases/DesiredRPM')

Do I need to use the 

@nivs_rt_sequence

decorator even if I am not doing an RT sequence?

A small example of read from and writing to a channel non-deterministically would be nice.

0 Kudos
Message 1 of 6
(3,225 Views)

I suspect this is a bug regarding version compatibility that we are currently investigating. What versions of python, pythonnet, niveristand, and VeriStand are you using? I assume you installed python 3.7 or newer and niveristand 2.0.x, which likely installed pythonnet 3.0.0.post1. If you run py -m pip list, you should be able to confirm. I would then recommend that you downgrade pythonnet to 2.5.2 as preliminary testing in our investigation appears to show that resolves the issue.

Brian.D
NI Product Owner
VeriStand
0 Kudos
Message 2 of 6
(3,187 Views)

virtual environment for reference

ActiveFrontEnd_0-1667233889292.png

These were all defaults.

I rolled back to 3.0.0 and retested and still got the error.  Then I tried to go back to 2.5.2 except when i try to install I get

-----------------------

Installed:
4 package(s) to packages.config projects
error: [WinError 2] The system cannot find the file specified
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pythonnet
error: subprocess-exited-with-error

Running setup.py install for pythonnet did not run successfully.
exit code: 1

[6 lines of output]
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help

error: option --single-version-externally-managed not recognized
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

Encountered error while trying to install package.

-----------------------
Updated pip, wheel, and setuptools.  Had no impact.  How were you able to install it?  Started looking into the error, but it very quickly got into a lot of tools I have never used.

0 Kudos
Message 3 of 6
(3,178 Views)

Bump.  Anyone got ideas.

0 Kudos
Message 4 of 6
(3,127 Views)

Apologies for the delayed response, we have released a new version of niveristand-python that now pins the pythonnet support to 2.5.2. Unfortunately, I suspect you are using a newer version of python that only supports pythonnet 3.0.0 (i.e. python 3.10 or 3.11). If you are using 3.7-3.8, the new version should install properly. We do intend to update our package to support the latest versions of python and pythonnet.

Brian.D
NI Product Owner
VeriStand
0 Kudos
Message 5 of 6
(3,080 Views)

Following up on this post, we just released a new version of niveristand that adds compatibility with pythonnet 3.0.1 and python 3.9+ https://github.com/ni/niveristand-python/releases/tag/v2.1.0

Brian.D
NI Product Owner
VeriStand
0 Kudos
Message 6 of 6
(2,739 Views)