MX Foundation 4
ar629_dual_xpp.cs
/*****************************************************************************
//
// File:
// ar629_dual_xpp.cs
//
// Copyright (c) MAX Technologies Inc. 1988-2019, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the use of the dual XPP feature.
//
// **** RT XPP #0 (RT0) schedule ********
//
// Label = 0x0100 | Label = 0x0200 | Label = 0x0300
// Label = 0x0101 | Label = 0x0201 |
// | Label = 0x0202 |
// | Label = 0x0203 |
// | Label = 0x0204 |
//
// **** RT XPP #1 (RT60) schedule ********
//
// Label = 0x0100 | Label = 0x0200 | Label = 0x0300
// | Label = 0x0201 | Label = 0x0301
// | Label = 0x0202 |
//
// It demonstrates how to:
//
// - Get handle to all 120 RTs channel with mxfModuleChannelAllGet().
// - Enable dual XPP with mxfAttributeUint64Set().
// - Configure TG and CID on RT #0 and RT #60 with mxfAttributeUint64Set().
// - Configure major frame on RT #0 and RT #60 with mxfA629TxPeriodicMajorFrameSet().
// - Start major frame on RT #0 and RT #60 with mxfA629TxPeriodicMajorFrameStart().
// - Stop major frame on RT #0 and RT #60 with mxfTxPeriodicMajorFrameStop().
//
// Hardware requirements:
// - MAXT FlexMulti-629.
//
*****************************************************************************/
#define TTL
//#define LOCAL
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];
var aMsg629 = new MXF_A629_TXPERIODIC_MJRFRAME_MSG[32];
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;
// Connects to services and initialize environment
#if LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", Convert.ToUInt64(false), out server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", Convert.ToUInt64(false), out server);
#endif
// Initializes MX Foundation library
if (rc == MAXT_SUCCESS)
{
Console.WriteLine("Starting ...");
rc = mxfSystemInit(server);
}
// Gets the first device handle
if (rc == MAXT_SUCCESS)
rc = mxfSystemDeviceGet(server, 0, out device);
if (rc == MAXT_SUCCESS)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_A629MRT_EH, 1, out count, module);
// Detects first BM
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_A629, MXF_SCLASS_BM_CHANNEL, 1, out NbBM, ahBM);
// Detects all RT channels
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_A629, MXF_SCLASS_RT_CHANNEL, 120, out NbCh, ahChn);
// Sets timebase to 64-bit nanoseconds
if (rc == MAXT_SUCCESS)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_NSEC);
// Sets interface to SIM or TTL
#if TTL
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(module[0], KMXF_A629_MODULE_INTERFACE, VMXF_A629_MODULE_INTERFACE_TTL);
#else
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(module[0], KMXF_A629_MODULE_INTERFACE, VMXF_A629_MODULE_INTERFACE_SIM);
#endif
// Allocates RX acquisition buffer
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqBufferAlloc(ahBM[0], (UInt64)RX_BUFFER_SIZE, out rxBuffer, IntPtr.Zero);
// Allocates TX Periodic Update Message buffer
for (index = 0; (index < 8) && (rc == MAXT_SUCCESS); index++)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(ahChn[0], index, (UInt64)TX_BUFFER_SIZE, out txBuffer[index], IntPtr.Zero);
for (index = 8; (index < 14) && (rc == MAXT_SUCCESS); index++)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(ahChn[60], index, (UInt64)TX_BUFFER_SIZE, out txBuffer[index], IntPtr.Zero);
// Allocates host buffer
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;
}
}
//Enable the DUAL XPP feature (global to IPack module)
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(module[0], KMXF_A629_MODULE_XPP_DUAL_ENABLE, VMXF_ENABLE);
// Start the acquisition process
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqModeSet(rxBuffer, MXF_RXACQ_MODE_LINEAR);
if (rc == MAXT_SUCCESS)
{
rc = mxfRxAcqStart(rxBuffer, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
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;
//------------------------------------------------------------------------------//
//------------------- INITIALIZE RT #0 -----------------------------------------//
//------------------------------------------------------------------------------//
// Stop and clear major frame on RT #0
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicMajorFrameStop(ahChn[0], 0, 0);
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicMajorFrameClear(ahChn[0], 0);
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(ahChn[0], KMXF_A629_RT_TG, 5);
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(ahChn[0], KMXF_A629_RT_CID, 5);
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;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 0, 3, aMsg629);
}
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;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 1, 2, aMsg629);
}
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;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 2, 2, aMsg629);
}
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;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 3, 2, aMsg629);
}
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;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 4, 2, aMsg629);
}
//------------------------------------------------------------------------------//
//------------------- INITIALIZE RT #0 DATA ------------------------------------//
//------------------------------------------------------------------------------//
if (rc == MAXT_SUCCESS)
{
Rec629 = new MXF_A629_DATAREC()
{
data = new UInt16[258]
};
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x1108;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[0], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x2208;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[3], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x3308;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[1], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
p = txHostBuffer;
for (iCnt = 0; (iCnt < 10) && (rc == MAXT_SUCCESS); iCnt++)
{
Rec629.repeatCount = 10;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = (UInt16)iCnt; // Data = 0, 1, 2, etc
Marshal.StructureToPtr(Rec629, p, false);
}
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[4], 10, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x5508;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[5], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x6608;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[6], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x7708;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[7], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x8808;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[2], 1, txHostBuffer);
}
//--------------------------------------------------------------------//
//------------------------ START RT #0 -------------------------------//
//--------------------------------------------------------------------//
if (rc == MAXT_SUCCESS)
{
// *** START RT #0 ***
iTI = 25000000;
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(module[0], KMXF_A629_MODULE_TI, iTI);
}
if (rc == MAXT_SUCCESS)
{
majorProperties.mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_INDEPENDENT;
majorProperties.reserved = 0;
rc = mxfA629TxPeriodicMajorFrameStart(ahChn[0], 0, ref majorProperties);
}
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;
}
// Stop and clear major frame on RT #60
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicMajorFrameStop(ahChn[60], 0, 0);
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicMajorFrameClear(ahChn[60], 0);
//------------------------------------------------------------------------------//
//------------------- INITIALIZE RT #60 ----------------------------------------//
//------------------------------------------------------------------------------//
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(ahChn[60], KMXF_A629_RT_TG, 5);
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(ahChn[60], KMXF_A629_RT_CID, 6);
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;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[60], 0, 0, 3, aMsg629);
}
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;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[60], 0, 1, 3, aMsg629);
}
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;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[60], 0, 2, 2, aMsg629);
}
//------------------------------------------------------------------------------//
//------------------- INITIALIZE RT #60 DATA -----------------------------------//
//------------------------------------------------------------------------------//
if (rc == MAXT_SUCCESS)
{
Rec629 = new MXF_A629_DATAREC()
{
data = new UInt16[258]
};
//memset((char*)aRec629, 0, 10 * sizeof(MXF_A629_DATAREC));
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x1108;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[8], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x3308;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[9], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
p = txHostBuffer;
for (iCnt = 0; (iCnt < 10) && (rc == MAXT_SUCCESS); iCnt++)
{
Rec629.repeatCount = 10;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = (UInt16)(220 + iCnt); // Data = 220, 221, 222, etc
Marshal.StructureToPtr(Rec629, p, false);
}
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[11], 10, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x5508;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[13], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x8808;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[10], 1, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x9908;
Marshal.StructureToPtr(Rec629, txHostBuffer, false);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[12], 1, txHostBuffer);
}
//--------------------------------------------------------------------//
//------------------------ START RT #60 ------------------------------//
//--------------------------------------------------------------------//
if (rc == MAXT_SUCCESS)
{
// With the DualXPP mode enabled, calling fct mxfA629TxPeriodicMajorFrameStart()
// on a "mirror channel" will change XPP scheduling for that
// "same Rt" without stopping or altering the ongoing scheduling.
iTI = 25000000;
if (rc == MAXT_SUCCESS)
rc = mxfAttributeUint64Set(module[0], KMXF_A629_MODULE_TI, iTI);
}
if (rc == MAXT_SUCCESS)
{
majorProperties.mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_INDEPENDENT;
majorProperties.reserved = 0;
rc = mxfA629TxPeriodicMajorFrameStart(ahChn[60], 0, ref majorProperties);
}
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("RT #60 started.");
}
}
if (rc == uint.MaxValue)
rc = MAXT_SUCCESS;
//Stop RT's
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicMajorFrameStop(ahChn[0], 0, 0);
if (rc == MAXT_SUCCESS)
rc = mxfTxPeriodicMajorFrameStop(ahChn[60], 0, 0);
// Stop acquisition and read data
if (rc == MAXT_SUCCESS)
rc = mxfRxAcqStop(rxBuffer);
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);
if (mxfSystemErrorStringGet(server, rc, 256, buffer) != MAXT_SUCCESS)
buffer.Append(string.Format("ERROR # 0x{0:x8}", rc));
Console.WriteLine(buffer);
}
// Free all buffers and terminate
if (rxBuffer != 0)
mxfRxAcqBufferFree(rxBuffer);
for (indexBuffer = 0; indexBuffer < 14; indexBuffer++)
{
if (txBuffer[indexBuffer] != 0)
mxfTxPeriodicUpdateMsgBufferFree(txBuffer[indexBuffer]);
}
// Unloads MX Foundation library
// Disconnects from MX Foundation library
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++)
{
rec629 = (MXF_A629_DATAREC)Marshal.PtrToStructure(p, typeof(MXF_A629_DATAREC));
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();
}
}
}
}
Updated 10/23/2023