10-24-2016 07:06 PM
In this topic:
I found that it's possible to use ctypes of python to call the functions from niusrp.dll to control NI USRP devices directly. So I just tried it and of course, met a problem.
My test file is attached here.
My problem is that I don't know how to pass the variable 'sessionHandle' in the function ''niUSRP_OpenRxSession'' to the function ''niUSRP_ConfigureSignal''. I get the error code: 0xbffa4010 which means the niUSRP_Error_InvalidSessionHandle.
In the file niUSRPTypes.h, I found that the data type of the 'sessionHandle' is unsigned int. So I set 4 bytes pointer to the variable sessionhandle in my code and return 0 from the function ''niUSRP_OpenRxSession''. The value of this pointer is changed to '0x01000000' after the ''niUSRP_OpenRxSession''. It looks like that the bytes of the pointer is only one byte. And I tried one byte as well which gets the same error code.
Besides, another question is that, in the labview communications, the sequence of the receving data is that: open session, properties, configuration, initial, fetch, abort and close session. It's obviously to find the coresponding C functions in the niusrp.dll, except for the properties. Are the functions like 'niUSRP_SetAttributeString' assigned to the properties module in the labview communications?
Is there any information or examples about how to program NI USRP device in python like this?
Thanks a lot for any help.
10-25-2016 01:06 PM
I am definitely not a Python user, so I apologize if this sounds like a silly question. It sounds like you are on the right track by trying to pass a uint variable to the USRP_OpenRxSession sessionhandle, but I don't understand why you use create_string_buffer for this.
c_uintbe the corresponding data type for the sessionhandle then?
This ctype reference seems to indicate that you would get an array of
c_char data from it.
10-25-2016 07:05 PM
Thanks a lot for your suggestions. The tried few ways to assign sessionHandle variable. Only 'c_char_p()', 'create_string_buffer()' and 'sessionHandle = (c_byte * 4)()
sessionHandle = cast(sessionHandle, POINTER(c_uint32))' works. I think the last one make the most sense. However all of them shows the same error.
Based on the C language view, does my idea of using these function correct?
10-26-2016 07:29 PM
I see... If the issue is actually being caused by the data type that we pass to store the sessionhandle, then it would probably make sense that the next function is the one that errors out.
May I ask what hapenned when you tried to store the sessionhandle in an uint data type? You mentioned that it has only worked with those options, but what hapenned when "it didn't work"? Any errors from the OpenRxSession?
I would like to have some more documentation to back us up, but as you probably know the USRP driver was not designed to be used from a text based environment (and definitely not for Python) so there is no more documentation than what you already checked.