C# Access Array from Pointer from Primera Ptrobot Sdk

I'm trying to integrate the PTRobot API into my C# .NET program and am running into an issue that I can't figure out. I'm trying to perform the following commands:

PTRobot_Initialize()
PTRobot_EnumRobots(HANDLE * phRobots, DWORD * pdwNumRobots)
PTRobot_GetRobotInfo(HANDLE hRobot, PTRobotInfo *pRobotInfo)
PTRobot_EnumDrives(HANDLE hRobot, HANDLE * phDrives, DWORD * pdwNumDrives)
PTRobot_GetDriveInfo(HANDLE hDrive, PTDriveInfo* pDrvInfo)

This comes from the API documentation. Primera has also developed a .NET wrapper for C# around the DLL. The updated functions are:

PTRobot_Initialize()
PTRobot_EnumRobots(ref UInt32 nRobots, ref UInt32 pnNumRobots)
PTRobot_GetRobotInfo(UInt32 nRobotID, [In, Out] RobotInfo myRobotInfo)
PTRobot_EnumDrives(UInt32 nRobotID, ref UInt32 nDriveIDs, ref UInt32 nNumDrives)
PTRobot_GetDriveInfo(UInt32 nDriveID, [In, Out] DriveInfo myDriveInfo)

I'm trying to integrate the .NET functions in my program but I'm having an issue. EnumRobots's parameter, nRobots, "points to an array of HANDLEs to store the Robots found" while EnumDrives parameter, nDriveIDs, "points to an array of DWORDS to store the Drives found". My question is how do I go about getting an array from this uint?

1 Answer

Found the answer. For all those wondering, you do the following:

uint numRobots = 5;
uint numDrives = 5;
uint[] robotArray = new uint[numRobots];
uint[] driveArray = new uint[numDrives];


DriveInfo arr = new DriveInfo();
PTRobotReturn rtn;
RobotInfo rI = new RobotInfo();
rtn = PTRobot.Initialize();

rtn = PTRobot.EnumRobots(ref robotArray[0], ref numRobots);

rtn = PTRobot.GetRobotInfo(robotArray[0], ref rI);

rtn = PTRobot.EnumDrives(robotArray[0], ref driveArray[0], ref numDrives);

rtn = PTRobot.LoadDrive(robotArray[0], driveArray[0], PrimeraTechnology.DiscLocation.Right_Bin, PrimeraTechnology.ClearDrive.Yes);

Your Answer

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

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest