#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_freshnessCounter_manyCID
{
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));
UInt32 rc;
UInt64 server;
var module = new UInt64[1];
UInt64 count = 0;
UInt64 rxChannel = 0;
var txChannel = new UInt64[2];
UInt64 rxBuffer = 0;
var txBuffer = new UInt64[2];
IntPtr hostBuffer = IntPtr.Zero;
IntPtr txHostBuffer = IntPtr.Zero;
IntPtr rec629 = IntPtr.Zero;
UInt64 dev, mod, port;
UInt64 index, word;
UInt64 status, msgsCount, bytesCount, indexBuffer, fcCounter = 0;
{
data = new UInt16[258]
};
{
data = new UInt16[258]
};
#if LOCAL
#else
rc =
mxfServerConnect(
"192.168.0.1",
"admin",
"admin", Convert.ToUInt64(
false), out server);
#endif
if (rc != MAXT_SUCCESS)
{
Console.WriteLine("Failed to connect; rc=0x{0:x8}", rc);
Console.WriteLine("Press a key to terminate");
Console.Read();
return;
}
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("Starting");
}
if ((rc == MAXT_SUCCESS) && (count != 0))
rc =
mxfChannelGet(server, MXF_CLASS_A629, MXF_SCLASS_BM_CHANNEL, MXF_MODULE_ALL, 0, out rxChannel);
if ((rc == MAXT_SUCCESS) && (count != 0))
rc =
mxfChannelAllGet(server, MXF_CLASS_A629, MXF_SCLASS_RT_CHANNEL, MXF_MODULE_ALL, 2, out count, txChannel);
if ((rc == MAXT_SUCCESS) && (count == 0))
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
Console.WriteLine("Acquisition Channel (RX) location={0}.{1}.{2}", dev, mod, port);
}
for (index = 0; (index < count) && (rc == MAXT_SUCCESS); index++)
{
if (rc == MAXT_SUCCESS)
Console.WriteLine("Transmitter Channel (TX) location={0}.{1}.{2}", dev, mod, port);
}
if (rc == MAXT_SUCCESS)
#if TTL
if (rc == MAXT_SUCCESS)
#else
if (rc == MAXT_SUCCESS)
#endif
if (rc == MAXT_SUCCESS)
for (indexBuffer = 0; (indexBuffer < count) && (rc == MAXT_SUCCESS); indexBuffer++)
{
}
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(txRec629)*10);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("Acquisition started");
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
for (index = 0; (index < count) && (rc == MAXT_SUCCESS); index++)
{
if (rc == MAXT_SUCCESS)
}
if (rc == MAXT_SUCCESS)
{
minorFrame[0].buffer = txBuffer[0];
minorFrame[0].label = 0xA;
minorFrame[0].cid = 0;
minorFrame[0].length = 1;
minorFrame[0].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
if (rc == MAXT_SUCCESS)
{
fc.
enable = Convert.ToUInt64(
true);
}
}
if (rc == MAXT_SUCCESS)
{
minorFrame[0].buffer = txBuffer[1];
minorFrame[0].label = 0xB;
minorFrame[0].cid = 0;
minorFrame[0].length = 1;
minorFrame[0].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
}
if (rc == MAXT_SUCCESS)
{
txRec629.
data[1] = 0x1111;
Marshal.StructureToPtr(txRec629, txHostBuffer, false);
}
if (rc == MAXT_SUCCESS)
{
txRec629.
data[1] = 0x2222;
Marshal.StructureToPtr(txRec629, txHostBuffer, false);
}
for (index = 0; (index < count) && (rc == MAXT_SUCCESS); index++)
{
majorProperties.
mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_BLOCK;
}
if (rc == MAXT_SUCCESS)
for (index = 0; (index < count) && (rc == MAXT_SUCCESS); index++)
{
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
rc =
mxfA629RxAcqRead(rxBuffer, 0, (UInt64)RX_BUFFER_SIZE, out status, out msgsCount, out bytesCount, hostBuffer);
if (rc == MAXT_SUCCESS)
{
string directoryPath = Directory.GetCurrentDirectory();
directoryPath += "/results.txt";
using (StreamWriter w = File.CreateText(directoryPath))
{
}
using (StreamWriter w = File.AppendText(directoryPath))
{
rec629 = hostBuffer;
for (index = 0; (index < msgsCount) && (rc == MAXT_SUCCESS); index++)
{
w.Write(
" {0:D2}: Timetag={1:D12}, Size={2}", index, rxRec629.
timeTag, rxRec629.
dataSize);
if ((rxRec629.
control & MXF_A629_RX_REC_CTRL_STRING_CRC_ERROR) == MXF_A629_RX_REC_CTRL_STRING_CRC_ERROR)
w.Write(" CRC error");
if ((rxRec629.
control & MXF_A629_RX_REC_CTRL_STRING_DATA_SYNC_ERROR) == MXF_A629_RX_REC_CTRL_STRING_DATA_SYNC_ERROR)
w.Write(" Data sync error");
if (((rxRec629.
control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_MANCHESTER_ERROR)) == (MXF_A629_RX_REC_CTRL_STRING_LABEL_MANCHESTER_ERROR)) ||
((rxRec629.
control & (MXF_A629_RX_REC_CTRL_STRING_DATA_MANCHESTER_ERROR)) == (MXF_A629_RX_REC_CTRL_STRING_DATA_MANCHESTER_ERROR)))
w.Write(" Manchester error");
if (((rxRec629.
control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_PARITY_ERROR)) == (MXF_A629_RX_REC_CTRL_STRING_LABEL_PARITY_ERROR)) ||
((rxRec629.
control & (MXF_A629_RX_REC_CTRL_STRING_DATA_PARITY_ERROR)) == (MXF_A629_RX_REC_CTRL_STRING_DATA_PARITY_ERROR)))
w.Write(" Parity error");
if ((rxRec629.
control & MXF_A629_RX_REC_CTRL_STRING_EOS_ERROR) == MXF_A629_RX_REC_CTRL_STRING_EOS_ERROR)
w.Write(" End of String error");
w.Write("\n Data=");
for (word = 0; word < rxRec629.
dataSize / 2; word++)
{
w.Write(
"{0:X4} ", rxRec629.
data[word]);
if (rxRec629.
data[0] == 0xC00A)
{
{
if (fcCounter == ((rxRec629.
data[word] & fc.
mask) >> 4))
{
w.Write("Freshness Counter ok. \n");
fcCounter++;
if (fcCounter == 16)
fcCounter = 0;
}
else
{
w.Write("ERROR Freshness Counter. \n");
}
}
}
}
w.Write("\n");
}
}
}
}
if (rc != MAXT_SUCCESS)
{
StringBuilder buffer = new StringBuilder(256);
buffer.Append(string.Format("ERROR # 0x{0:x8}", rc));
Console.WriteLine(buffer);
}
Console.WriteLine();
Console.WriteLine("Terminating");
if (rxBuffer != 0)
for (indexBuffer = 0; indexBuffer < 2; indexBuffer++)
{
if (txBuffer[indexBuffer] != 0)
}
if (hostBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(hostBuffer);
if (txHostBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(txHostBuffer);
Console.WriteLine();
Console.WriteLine("Press enter to terminate");
Console.Read();
return;
}
}
}