1

I want to get some 10 values of type short from a .NET function.

In C# it works like this:

Int16[] values = new Int16[10];
Control1.ReadValues(values);

The C# syntax is ReadValues(short[] values).

I tried something like this:

$Control1.ReadValues([array][int16]$Result)

But there are only zeroes in the array.

5
  • What do you mean by "But only zeroes in the array."? What is the value of $Result? Commented May 3, 2016 at 9:22
  • I'm also wondering how does it work in C# without return value, ref or out? Commented May 3, 2016 at 9:27
  • The ReadValues function returns 10 non zero values but the $Result array contain only zeroes. I guess that I do it totally wrong or maybe it is not possible? Commented May 3, 2016 at 9:28
  • Can you show us the definition of ReadValues() or tell us which type Control1 is? Commented May 3, 2016 at 9:31
  • I believe that the C# function have a ref Commented May 3, 2016 at 9:32

1 Answer 1

2

In the comments you mention:

I believe that the C# function have a ref

So, the method signature is really:

ReadValues(ref short[] values)

Luckily, PowerShell has a [ref] type accelerator for this sort of situation

# Start by creating an array of Int16, length 10
$Result = [int16[]]@( ,0 * 10 )

# Pass the variable reference with the [ref] keyword
$Control1.ReadValues([ref]$Result)

For more inforation, see the about_Ref help file

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.