Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Type conversion problem#2375

feketeimre started this conversation inGeneral
May 7, 2024· 2 comments· 1 reply
Discussion options

I am trying to interface with a .NET dll to read stuff from a camera and i have trouble figuring out the types for a function call. Admittedly i have just started using pythonnet so my problem might be trivial.

Here is the truncated version of my program:

importclrfromSystemimport*clr.AddReference('PylonC.NET')fromPylonC.NETimportPylonfromPylonC.NETimportPylonBufferfromPylonC.NETimportPylonGrabResult_thDev=Pylon.CreateDeviceByIndex(0)imgBuf=PylonBuffer[Byte](None)#PylonBuffer<Byte> imgBuf = null; Is None correct here ?grabResult=PylonGrabResult_t()ret=Pylon.DeviceGrabSingleFrame(hDev,Int32(0),imgBuf,grabResult,UInt32(500))# the above raises an exception:# System.ArgumentException: PylonC.NET.PylonBuffer`1[System.Byte] value cannot be converted to PylonC.NET.PylonBuffer`1[T] in method# Boolean DeviceGrabSingleFrame[T](PylonC.NET.PYLON_DEVICE_HANDLE, Int32, PylonC.NET.PylonBuffer`1[T] ByRef, PylonC.NET.PylonGrabResult_t ByRef, UInt32)

I have doubts if the imgBuf = PylonBufferByte is equivalent to the original c: PylonBuffer imgBuf = null;
But mainly the type conversion error is what i have no idea why it doesnt work. I am certain that Byte is a valid type for PylonBuffer.
With dnSpy i looked into the problematic function and found this:
grab 2024-05-07 210235

Also im not sure how to deal with the ref and out keywords.

Any help is welcomed,
Thank you

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

Hi I got the same question. Did you figure it out? Like how to convert imgBuf into the ref type needed in C# function? Thank you!

You must be logged in to vote
1 reply
@feketeimre
Comment options

Hi, unfortunately no, i stopped trying.

Comment options

I spent time on this and managed to figure it out, sort of...
The function expects a generic type [T] but i have [Byte]. When passing Byte to this function it gives the exception as previously mentioned:

# System.ArgumentException: PylonC.NET.PylonBuffer`1[System.Byte] value cannot be converted to PylonC.NET.PylonBuffer`1[T] in method .....

Apparently, you can construct a specific type of the function like:

grabFrame=Pylon.DeviceGrabSingleFrame[Byte]ret=grabFrame(hDev,Int32(0),imgBuf,grabResult,UInt32(500))

In most cases i think this would work, but in my case i need to pass imgBuf and grabResult by reference that cannot be done in pythonnet.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
2 participants
@feketeimre@yezhou2000

[8]ページ先頭

©2009-2025 Movatter.jp