#define LOOPBACK
using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
namespace csdb_example
{
class csdb_periodic
{
const int BUFFER_SIZE = 4096;
const int TX_MSG_LABEL = 5;
const int TX_MSG_SI = 0;
const int BLOCKCOUNT = 6;
public static void Main(string[] args)
{
UInt32 rc;
UInt64 server;
UInt64 device = 0;
var module = new UInt64[1];
UInt64 count = 0;
var rxChannel = new UInt64[1];
var txChannel = new UInt64[1];
UInt64 rxBuffer = 0;
var txBuffer = new UInt64[2];
IntPtr recPtr = IntPtr.Zero;
UInt64 dev, mod, port, indexBuffer;
MXF_SYSTEM_INIT_ATTRIBUTE_UINT64_HANDLER _InitCSDBProtocolHandler = InitCSDBProtocolHandler;
{
data = new byte[12]
};
#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;
}
Console.WriteLine();
Console.WriteLine("Starting");
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if ((rc == MAXT_SUCCESS) && (count != 0))
if ((rc == MAXT_SUCCESS) && (count != 0))
if ((rc == MAXT_SUCCESS) && (count == 0))
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
Console.WriteLine("Acquisition Channel (RX) location={0}.{1}.{2}", dev, mod, port);
}
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
Console.WriteLine("Transmitter Channel (TX) location={0}.{1}.{2}", dev, mod, port);
}
#if LOOPBACK
if (rc == MAXT_SUCCESS)
#endif
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
try
{
recPtr = Marshal.AllocHGlobal(BUFFER_SIZE);
}
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)
{
rc = PeriodicScheduling(txChannel[0], txBuffer, recPtr);
if (rc == MAXT_SUCCESS)
{
rc = ReadAcquisitionData(rxBuffer, recPtr);
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("Acquisition stopped");
}
}
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 (recPtr != IntPtr.Zero)
Marshal.FreeHGlobal(recPtr);
Console.WriteLine();
Console.WriteLine("Press enter to terminate");
Console.Read();
return;
}
private static UInt32 ReadAcquisitionData(UInt64 rxBuffer, IntPtr recCsdb)
{
IntPtr recPtr = recCsdb;
UInt64 status, msgsCount, bytesCount;
UInt64 i, j;
UInt32 rc;
{
data = new byte[12]
};
rc =
mxfCSDBRxAcqRead(rxBuffer, 0, BUFFER_SIZE, out status, out msgsCount, out bytesCount, recCsdb);
for (j = 0; (j < msgsCount) && (rc == MAXT_SUCCESS); j++)
{
Console.Write(
"{0:D2}: Timetag={1:D16}: CSDB data=[ ", j, rec.
timeTag);
for (i = 0; i < BLOCKCOUNT; i++)
Console.Write(
"0x{0:X2} ", rec.
data[i]);
Console.Write("]\n\r");
}
return rc;
}
private static UInt32 PeriodicScheduling(UInt64 txChannel, UInt64[] txBuffer, IntPtr recPtr)
{
UInt64 schedule;
UInt64 msg = 0;
UInt32 rc;
UInt64 i;
{
data = new byte[12]
};
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
for (i = 0; i < BLOCKCOUNT; i++)
Marshal.StructureToPtr(recCsdb, recPtr, false);
}
if (rc == MAXT_SUCCESS)
{
recCsdb.
data[0] = TX_MSG_LABEL;
recCsdb.
data[1] = TX_MSG_SI;
for (i = 2; i < BLOCKCOUNT; i++)
recCsdb.
data[i] = (byte)i;
Marshal.StructureToPtr(recCsdb, recPtr, false);
}
if (rc == MAXT_SUCCESS)
{
Console.WriteLine("Running periodic transmission, please wait...");
}
if (rc == MAXT_SUCCESS)
{
}
if (rc == MAXT_SUCCESS)
{
Console.WriteLine();
Console.WriteLine("Transmission stopped");
}
return rc;
}
private static UInt32 InitCSDBProtocolHandler(UInt64 server, UInt64 deviceIndex, UInt64 moduleIndex, UInt64 channelIndex, UInt64 attrib, ref UInt64 value)
{
if (attrib == KMXF_CHANNEL_CLASS)
{
value = MXF_CLASS_CSDB;
return Convert.ToUInt32(true);
}
return Convert.ToUInt32(false);
}
}
}