#define LOOPBACK
using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
namespace ar717_example
{
class ar717
{
const int MAX_TX_SUBFRAMES_TO_TRANSMIT = 4;
public static void Main(string[] args)
{
UInt32 rc;
UInt64 server = 0;
UInt64 device = 0;
var module = new UInt64[1];
var rxChannel = new UInt64[1];
var txChannel = new UInt64[1];
UInt64 rxBuffer = 0;
UInt64 txBuffer = 0;
IntPtr recPtr = IntPtr.Zero;
UInt64 moduleCount = 0;
UInt64 channelCount = 0;
uint txBufferSize = 0;
uint rxBufferSize = 0;
IntPtr rxHostBuffer = IntPtr.Zero;
IntPtr txHostBuffer = IntPtr.Zero;
UInt64 rxAcqStatus = 0;
UInt64 msgCount = 0;
UInt64 byteCount = 0;
UInt64 data;
UInt64 word, subframeSize;
int nbFrames = MAX_TX_SUBFRAMES_TO_TRANSMIT;
MXF_SYSTEM_INIT_ATTRIBUTE_UINT64_HANDLER _initHandler = initHandler;
{
data = new UInt16[8192]
};
#if LOCAL
#else
rc =
mxfServerConnect(
"192.168.0.1",
"admin",
"admin", Convert.ToUInt64(
false), out server);
#endif
if (rc != MAXT_SUCCESS)
{
Console.Write("Failed to connect; rc=0x{0:x8}", rc);
Console.WriteLine();
Console.WriteLine("Press a key to terminate");
Console.Read();
return;
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting ...\n");
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if ((rc == MAXT_SUCCESS) && (moduleCount == 0))
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
rc =
mxfModuleChannelAllGet(module[0], MXF_CLASS_A717, MXF_SCLASS_RX_CHANNEL, 1, out channelCount, rxChannel);
if ((rc == MAXT_SUCCESS) && (channelCount != 0))
rc =
mxfModuleChannelAllGet(module[0], MXF_CLASS_A717, MXF_SCLASS_TX_CHANNEL, 1, out channelCount, txChannel);
if ((rc == MAXT_SUCCESS) && (channelCount == 0))
rc = MAXT_ERROR_NOT_FOUND;
#if LOOPBACK
if (rc == MAXT_SUCCESS)
#endif
if (nbFrames < 4)
{
if (rc == MAXT_SUCCESS)
Console.Write("Number of subframes to transmit less than 4: synchronization will not occur.\n");
}
if (rc == MAXT_SUCCESS)
{
txBufferSize = (uint)(MAX_TX_SUBFRAMES_TO_TRANSMIT * Marshal.SizeOf(typeof(
MXF_A717_DATAREC)));
if (rc == MAXT_SUCCESS)
{
try
{
txHostBuffer = Marshal.AllocHGlobal((int)txBufferSize);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
}
if (rc == MAXT_SUCCESS)
{
rxBufferSize = (uint)(MAX_TX_SUBFRAMES_TO_TRANSMIT * Marshal.SizeOf(typeof(
MXF_A717_DATAREC)));
if (rc == MAXT_SUCCESS)
{
try
{
rxHostBuffer = Marshal.AllocHGlobal((int)rxBufferSize);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
}
if (rc == MAXT_SUCCESS)
subframeSize = 128;
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
rc =
mxfAttributeUint64Set(rxChannel[0], KMXF_A717_ELECTRICAL_SELECTION, VMXF_A717_ELECTRICAL_SELECT_DEFAULT);
if (rc == MAXT_SUCCESS)
rc =
mxfAttributeUint64Set(txChannel[0], KMXF_A717_ELECTRICAL_SELECTION, VMXF_A717_ELECTRICAL_SELECT_DEFAULT);
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
recPtr = txHostBuffer;
for (data = 0; data < MAX_TX_SUBFRAMES_TO_TRANSMIT; data++)
{
rec.
dataSize = 2 * (UInt32)subframeSize;
for (word = 0; word < subframeSize; word++)
{
if (word == 0)
{
switch (data % 4)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
else
rec.
data[word] = (UInt16)(0x11 * word);
}
Marshal.StructureToPtr(rec, recPtr, false);
}
}
if (rc == MAXT_SUCCESS)
{
Console.Write("Transmitting ...\n");
rc =
mxfA717TxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_DEFAULT, 0, MAX_TX_SUBFRAMES_TO_TRANSMIT, txHostBuffer);
}
if (rc == MAXT_SUCCESS)
mxfSleep((MAX_TX_SUBFRAMES_TO_TRANSMIT + 1) * 1000);
if (rc == MAXT_SUCCESS)
{
Console.Write("Receiving ...\n");
rc =
mxfA717RxAcqRead(rxBuffer, 0, rxBufferSize, out rxAcqStatus, out msgCount, out byteCount, rxHostBuffer);
}
if (rc == MAXT_SUCCESS)
Console.Write("String received count = {0} \n", msgCount);
if (rc == MAXT_SUCCESS)
{
recPtr = rxHostBuffer;
for (data = 0; (data < msgCount) && (rc == MAXT_SUCCESS); data++)
{
Console.Write(
"\n{0:D2}: Timetag={1:D12}, Size={2} words\n", data, rec.
timeTag, (rec.
dataSize) / 2);
for (word = 0; word < subframeSize; word++)
Console.Write(
"{0:X3} ", rec.
data[word]);
Console.Write("\n");
}
}
if (rc == MAXT_SUCCESS)
if (rxBuffer != 0)
if (txBuffer != 0)
if (txHostBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(txHostBuffer);
if (rxHostBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(rxHostBuffer);
if (rc != MAXT_SUCCESS)
{
StringBuilder buffer = new StringBuilder(256);
buffer.Append(string.Format("ERROR # 0x{0:x8}", rc));
Console.WriteLine(buffer);
}
Console.Write("Terminating ...\n");
Console.Write("\nPress a key to terminate\n");
Console.Read();
return;
}
private static UInt32 initHandler(UInt64 server, UInt64 deviceIndex, UInt64 moduleIndex, UInt64 channelIndex, UInt64 attrib, ref UInt64 value)
{
UInt64 device = 0;
UInt32 rc;
server = server;
deviceIndex = deviceIndex;
if (attrib == KMXF_CHANNEL_CLASS)
{
if (rc == MAXT_SUCCESS)
if ((rc == MAXT_SUCCESS) && (deviceInfo.modules[moduleIndex].type == MXF_MODULE_MULTI_EH))
{
if ((channelIndex == 0) || (channelIndex == deviceInfo.modules[moduleIndex].txCount))
{
value = MXF_CLASS_A717;
return Convert.ToUInt32(true);
}
}
}
return Convert.ToUInt32(false);
}
}
}