У меня было два стада птичьего датчика, и я имею в виду пример кода № 8 в руководстве, код с ++ работает для меня.
Но я получаю только один датчик данных из проекта c sharp. Проблема в том, что в примере C # bird_data [1] и bird_data [2], по-видимому, имеют одинаковые данные позиции. В примере C ++ и bird_data [1], и bird_data [2] имеют правильные данные. Я получаю одинаковые выходные данные позиции из кода ниже.
вывод текста в LBird1X - тот же LBird2X, LBird1Y - тот же LBird2Y, а LBird1Z - тот же LBird2Z.
Может ли это быть связано с отсутствием наведения? Или я сделал что-то не так в импорте данных структуры bird.dll?
C ++ код:
birdStartFrameStream(GROUP_ID);
do // Until Keypress
{
if(birdFrameReady(GROUP_ID)) // Check if there's data available
{
birdGetMostRecentFrame(GROUP_ID,&frame);//Get data from bird BIRDREADING *bird_data; // Transfers data into structure
BIRDREADING *bird_data;
for(int i=1; i<DEVCOUNT+1; i++ ) // Loop to get data from birds
{
// Change pointer to index of first bird (1)
bird_data = &frame.reading[i]; // Convert data into inches and degrees and scale
pos[0] = bird_data->position.nX * 36 / 32767.;
pos[1] = bird_data->position.nY * 36 / 32767.;
pos[2] = bird_data->position.nZ * 36 / 32767.;
ang[0] = bird_data->angles.nAzimuth * 180. / 32767.;
ang[1] = bird_data->angles.nElevation * 180. / 32767.;
ang[2] = bird_data->angles.nRoll * 180. / 32767.;
// print data
printf("%i> %+6.1f %+6.1f %+6.1f ", i,pos[0], pos[1],pos[2]);
// printf("%+6.1f %+6.1f %+6.1f \n",ang[0], ang[1], ang[2]);
} // end move data from structure to screen loop
} // end if frame ready loop
} while(!kbhit()); // loop until any key is pressed
С резким, которые имеют те же данные
if (birdFrameReady(GROUP_ID))
{
birdGetMostRecentFrame(GROUP_ID, ref frame);
BIRDREADING bird_data = new BIRDREADING();
bird_data = frame.readings[i];
for (i = 1; i < DEVCOUNT + 1; i++)
{
bird_data = frame.readings[i];
string x, y, z;
x = (bird_data.position.nX * 36 / 32767.0).ToString();
y = (bird_data.position.nY * 36 / 32767.0).ToString();
z = (bird_data.position.nZ * 36 / 32767.0).ToString();
switch (i)
{
case 1:
LBird1X.Text = i.ToString() + ": " + x;
LBird1Y.Text = i.ToString() + ": " + y;
LBird1Z.Text = i.ToString() + ": " + z;
break;
case 2:
LBird2X.Text = i.ToString() + ": " + x;
LBird2Y.Text = i.ToString() + ": " + y;
LBird2Z.Text = i.ToString() + ": " + z;
break;
default:
LBird2X.Text = "error";
LBird2Y.Text = "error";
LBird2Z.Text = "error";
break;
}
}
C ++ Struct
#pragma pack(1) // pack the following structures on one-byte boundaries
// Bird position structure
typedef struct tagBIRDPOSITION
{
short nX; // x-coordinate
short nY; // y-coordinate
short nZ; // z-coordinate
}
BIRDPOSITION;
// Bird angles structure
typedef struct tagBIRDANGLES
{
short nAzimuth; // azimuth angle
short nElevation; // elevation angle
short nRoll; // roll angle
}
BIRDANGLES;
// Bird matrix structure
typedef struct tagBIRDMATRIX
{
short n[3][3]; // array of matrix elements
}
BIRDMATRIX;
// Bird quaternion structure
typedef struct tagBIRDQUATERNION
{
short nQ0; // q0
short nQ1; // q1
short nQ2; // q2
short nQ3; // q3
}
BIRDQUATERNION;
#pragma pack() // resume normal packing of structures
// Bird reading structure
typedef struct tagBIRDREADING
{
BIRDPOSITION position; // position of receiver
BIRDANGLES angles; // orientation of receiver, as angles
BIRDMATRIX matrix; // orientation of receiver, as matrix
BIRDQUATERNION quaternion; // orientation of receiver, as quaternion
WORD wButtons; // button states
}
BIRDREADING;
// Bird frame structure
//
// NOTE: In stand-alone mode, the bird reading is stored in reading[0], and
// all other array elements are unused. In master/slave mode, the "reading"
// array is indexed by bird number - for example, bird #1 is at reading[1],
// bird #2 is at reading[2], etc., and reading[0] is unused.
typedef struct tagBIRDFRAME
{
DWORD dwTime; // time at which readings were taken, in msecs
BIRDREADING reading[BIRD_MAX_DEVICE_NUM + 1]; // reading from each bird
}
BIRDFRAME;
// Bird system configuration structure
//
// NOTE: In TCP/IP mode, the following fields are NOT used:
// byXtalSpeed
//
// NOTE: In RS232 and ISA modes, the following fields are NOT used:
// bits BSS_FBB_ERROR, BSS_LOCAL_ERROR, BSS_LOCAL_POWER, and BSS_MASTER of bySystemStatus
// byNumServers
// byChassisNum
// byNumChassisDevices
// byFirstDeviceNum
C Sharp Stuct
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct BIRDPOSITION
{
public short nX; // x-coordinate
public short nY; // y-coordinate
public short nZ; // z-coordinate
}
// Bird angles structure
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct BIRDANGLES
{
public short nAzimuth; // azimuth angle
public short nElevation; // elevation angle
public short nRoll; // roll angle
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct BIRDMATRIX
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
public short[,] n;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct BIRDQUATERNION
{
public short nQ0; // q0
public short nQ1; // q1
public short nQ2; // q2
public short nQ3; // q3
}
[StructLayout(LayoutKind.Sequential, Pack = 0)]
public struct BIRDREADING
{
public BIRDPOSITION position; // position of receiver
public BIRDANGLES angles; // orientation of receiver, as angles
public BIRDMATRIX matrix; // orientation of receiver, as matrix
public BIRDQUATERNION quaternion; // orientation of receiver, as quaternion
public ushort wButtons; // button states
}
[StructLayout(LayoutKind.Sequential, Pack = 0)]
public struct BIRDFRAME
{
public uint dwTime; // time at which readings were taken, in msecs
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 127)]
public BIRDREADING[] readings; // reading from each bird
}