#define TTL
using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
namespace ar629_example
{
class ar629_dual_xpp
{
const int MAX_RX_RECORDS_TO_RECEIVE = 1000;
const int MAX_TX_RECORDS_TO_TRANSMIT = 1;
static void Main(string[] args)
{
int RX_BUFFER_SIZE = MAX_RX_RECORDS_TO_RECEIVE * Marshal.SizeOf(typeof(
MXF_A629_DATAREC));
int TX_BUFFER_SIZE = MAX_TX_RECORDS_TO_TRANSMIT * Marshal.SizeOf(typeof(
MXF_A629_DATAREC));
var ahChn = new UInt64[120];
var ahBM = new UInt64[1];
int iMsg, iCnt;
IntPtr p = IntPtr.Zero;
IntPtr hostBuffer = IntPtr.Zero;
IntPtr txHostBuffer = IntPtr.Zero;
UInt64 server = 0;
var txBuffer = new UInt64[14];
UInt64 rxBuffer = 0;
UInt32 rc = 0;
UInt64 device = 0;
UInt64 count = 0, NbCh, NbBM, index, iTI = 0;
var module = new UInt64[1];
UInt64 status, msgsCount, bytesCount, indexBuffer;
#if LOCAL
#else
rc =
mxfServerConnect(
"192.168.0.1",
"admin",
"admin", Convert.ToUInt64(
false), out server);
#endif
if (rc == MAXT_SUCCESS)
{
Console.WriteLine("Starting ...");
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
#if TTL
if (rc == MAXT_SUCCESS)
#else
if (rc == MAXT_SUCCESS)
#endif
if (rc == MAXT_SUCCESS)
for (index = 0; (index < 8) && (rc == MAXT_SUCCESS); index++)
for (index = 8; (index < 14) && (rc == MAXT_SUCCESS); index++)
if (rc == MAXT_SUCCESS)
{
try
{
hostBuffer = Marshal.AllocHGlobal(Math.Max(RX_BUFFER_SIZE, TX_BUFFER_SIZE));
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
try
{
txHostBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(Rec629) * 10);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("Acquisition started");
}
}
while (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.Write("Press ENTER to switch to RT #0, or 'Q' to Quit! ");
if (Console.ReadKey().Key == ConsoleKey.Q)
rc = uint.MaxValue;
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
iMsg = 0;
aMsg629[iMsg].buffer = txBuffer[0];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x100;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[1];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x200;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 2;
aMsg629[iMsg].buffer = txBuffer[2];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x300;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
}
if (rc == MAXT_SUCCESS)
{
iMsg = 0;
aMsg629[iMsg].buffer = txBuffer[3];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x101;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[4];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x201;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
}
if (rc == MAXT_SUCCESS)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].length = 0;
aMsg629[iMsg].cid = 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[5];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x202;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
}
if (rc == MAXT_SUCCESS)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].length = 0;
aMsg629[iMsg].cid = 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[6];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x203;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
}
if (rc == MAXT_SUCCESS)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].length = 0;
aMsg629[iMsg].cid = 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[7];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x204;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
}
if (rc == MAXT_SUCCESS)
{
{
data = new UInt16[258]
};
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
p = txHostBuffer;
for (iCnt = 0; (iCnt < 10) && (rc == MAXT_SUCCESS); iCnt++)
{
Rec629.
data[1] = (UInt16)iCnt;
Marshal.StructureToPtr(Rec629, p, false);
}
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
iTI = 25000000;
if (rc == MAXT_SUCCESS)
}
if (rc == MAXT_SUCCESS)
{
majorProperties.
mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_INDEPENDENT;
}
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("RT #0 started.");
Console.WriteLine();
Console.Write("Press ENTER to switch to RT #60, or 'Q' to Quit! ");
if (Console.ReadKey().Key == ConsoleKey.Q)
rc = uint.MaxValue;
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
iMsg = 0;
aMsg629[iMsg].buffer = txBuffer[8];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x100;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[9];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x200;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 2;
aMsg629[iMsg].buffer = txBuffer[10];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x300;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
}
if (rc == MAXT_SUCCESS)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[11];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x201;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 2;
aMsg629[iMsg].buffer = txBuffer[12];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x301;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
}
if (rc == MAXT_SUCCESS)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[13];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x202;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
}
if (rc == MAXT_SUCCESS)
{
{
data = new UInt16[258]
};
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
p = txHostBuffer;
for (iCnt = 0; (iCnt < 10) && (rc == MAXT_SUCCESS); iCnt++)
{
Rec629.
data[1] = (UInt16)(220 + iCnt);
Marshal.StructureToPtr(Rec629, p, false);
}
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
iTI = 25000000;
if (rc == MAXT_SUCCESS)
}
if (rc == MAXT_SUCCESS)
{
majorProperties.
mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_INDEPENDENT;
}
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("RT #60 started.");
}
}
if (rc == uint.MaxValue)
rc = MAXT_SUCCESS;
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
rc =
mxfA629RxAcqRead(rxBuffer, 0, (UInt64)RX_BUFFER_SIZE, out status, out msgsCount, out bytesCount, hostBuffer);
DisplayDataArray(msgsCount, hostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("Test done.");
}
else
{
StringBuilder buffer = new StringBuilder(256);
buffer.Append(string.Format("ERROR # 0x{0:x8}", rc));
Console.WriteLine(buffer);
}
if (rxBuffer != 0)
for (indexBuffer = 0; indexBuffer < 14; indexBuffer++)
{
if (txBuffer[indexBuffer] != 0)
}
Console.WriteLine();
Console.WriteLine("Press ENTER to terminate ");
Console.Read();
return;
}
private static void DisplayDataArray(UInt64 recNum, IntPtr rec)
{
UInt64 iRec,
iData;
IntPtr p = rec;
{
data = new UInt16[258]
};
UInt32 rc = MAXT_SUCCESS;
Console.WriteLine();
for (iRec = 0; (iRec < recNum) && (rc == MAXT_SUCCESS); iRec++)
{
Console.Write(
"{0:D3} {1:D10} {2:D2} ", iRec, rec629.
timeTag, rec629.
dataSize);
if ((rec629.
control & MXF_A629_RX_REC_CTRL_STRING_CRC_ERROR) == MXF_A629_RX_REC_CTRL_STRING_CRC_ERROR)
Console.Write(" CRC error");
if ((rec629.
control & MXF_A629_RX_REC_CTRL_STRING_DATA_SYNC_ERROR) == MXF_A629_RX_REC_CTRL_STRING_DATA_SYNC_ERROR)
Console.Write(" Data sync error");
if (((rec629.
control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_MANCHESTER_ERROR)) == (MXF_A629_RX_REC_CTRL_STRING_LABEL_MANCHESTER_ERROR)) ||
((rec629.
control & (MXF_A629_RX_REC_CTRL_STRING_DATA_MANCHESTER_ERROR)) == (MXF_A629_RX_REC_CTRL_STRING_DATA_MANCHESTER_ERROR)))
Console.Write(" Manchester error ");
if (((rec629.
control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_PARITY_ERROR)) == (MXF_A629_RX_REC_CTRL_STRING_LABEL_PARITY_ERROR)) ||
((rec629.
control & (MXF_A629_RX_REC_CTRL_STRING_DATA_PARITY_ERROR)) == (MXF_A629_RX_REC_CTRL_STRING_DATA_PARITY_ERROR)))
Console.Write(" Parity error ");
if ((rec629.
control & MXF_A629_RX_REC_CTRL_STRING_EOS_ERROR) == MXF_A629_RX_REC_CTRL_STRING_EOS_ERROR)
Console.Write(" End of String error");
for (iData = 0; iData < rec629.
dataSize / 2; iData++)
{
Console.Write(
"{0:x4} ", rec629.
data[iData]);
if ((((iData + 1) % 8) == 0) && (iData + 1 < rec629.
dataSize / 2))
Console.Write("\n ");
}
Console.WriteLine();
}
}
}
}