1

I'm not a Python programmer, but I'm trying to get a simple script working using IronPython and VB.Net. I've gotten pretty far, but now I'm stuck on passing arguments by reference. I need to be able to get data back from the VB side into the Python side in the argument list (since Python returns tuples, but .Net doesn't). However, this code doesn't work, and I don't know why not.

Here is the python code:

def GetVoltages(voltages):
    fixture.StartScan()
    done=False
    counter=0
    while done == False:
        fixture.GetNumDataPoints(num)
        if num>=15:
            done=True
        else:
            counter=counter+1
        if counter>1000000:
            break
    if done == True:
        fixture.GetDataPoints(num, voltages)
    else:
        log.WriteLine("Failed to read voltages.")
    return done

buff = Array.CreateInstance(System.Double, 0)
if GetVoltages(buff):
    log.WriteLine("Checking voltages.")
    CheckVoltage(buff, 3, 22)
# do other stuff

fixture is a defined variable, and the function is called correctly, but num and voltages on the python side never change. Here is the function declarations on the VB side:

Public Function GetDataPoints(ByVal num As Integer, ByRef vals() As Double) As Boolean
Public Function GetNumDataPoints(ByRef num As Integer) As Boolean

I've found a couple old pages that give some hints, but I'm not seeing what the right answer is.

1 Answer 1

0

Basically, IronPython bundles ref and out parameters into the result as a tuple. That means you want something like:

success, num = fixture.GetNumDataPoints(num)
success, voltages = fixture.GetDataPoints(num, voltages)

There may be some interaction between ref and arrays, but this should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.