using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
using System.ComponentModel;
namespace csdb_flexsmp_example {
class csdb_flexsmp {
private const int BLOCK_COUNT = 8;
static void Main(string[] args) {
UInt32 rc = MAXT_SUCCESS;
UInt64 server = 0;
UInt64 rxChannel = 0;
UInt64 txChannel = 0;
UInt64 bufferSize = 0;
UInt64 mxfRxBuffer = 0;
UInt64 mxfTxBuffer = 0;
};
};
IntPtr recPtr = IntPtr.Zero;
UInt64 rxAcqStatus = 0;
UInt64 msgCount = 0, byteCount = 0;
UInt64 iData = 0;
#if (LOCAL)
#else
rc =
mxfConnectEthernet(
"192.168.0.1",
"admin",
"admin", Convert.ToUInt64(
false), out server);
#endif
if (rc == MAXT_SUCCESS) {
Console.WriteLine("Initializing ...");
}
if (rc == MAXT_SUCCESS) {
rc =
mxfChannelGet(server, MXF_CLASS_ALL, MXF_SCLASS_RX_CHANNEL, MXF_MODULE_FLEXSMP, 0, out rxChannel);
}
if (rc == MAXT_SUCCESS) {
rc =
mxfChannelGet(server, MXF_CLASS_ALL, MXF_SCLASS_TX_CHANNEL, MXF_MODULE_FLEXSMP, 0, out txChannel);
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
# if LOOPBACK
if (rc == MAXT_SUCCESS) {
}
#endif
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
txRec[0].reserved = 0;
txRec[0].timeTag = 0;
txRec[0].control = 0;
txRec[0].repeatCount = 1;
for (int iByte = 0; iByte < BLOCK_COUNT; iByte++) {
txRec[0].data[iByte] = 0xA5;
}
txRec[1].reserved = 0;
txRec[1].timeTag = 0;
txRec[1].control = 0;
txRec[1].repeatCount = 1;
txRec[1].data[0] = 6;
txRec[1].data[1] = 2;
for (int iByte = 2; iByte < BLOCK_COUNT; iByte++) {
txRec[1].data[iByte] = (byte)(0x11 * iByte);
}
IntPtr txRecBufferPtr = IntPtr.Zero;
try {
txRecBufferPtr = Marshal.AllocHGlobal((int)bufferSize);
}
catch (OutOfMemoryException) {
rc = MAXT_ERROR_MEM;
}
if (rc == MAXT_SUCCESS) {
recPtr = txRecBufferPtr;
Marshal.StructureToPtr(txRec[0], recPtr, false);
if (rc == MAXT_SUCCESS) {
Marshal.StructureToPtr(txRec[1], recPtr, false);
Console.WriteLine("Transmitting ...");
}
}
if (txRecBufferPtr != IntPtr.Zero) {
Marshal.FreeHGlobal(txRecBufferPtr);
}
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
IntPtr rxRecBufferPtr = IntPtr.Zero;
try {
rxRecBufferPtr = Marshal.AllocHGlobal((int)bufferSize);
}
catch (OutOfMemoryException) {
rc = MAXT_ERROR_MEM;
}
if (rc == MAXT_SUCCESS) {
Console.WriteLine("Receiving ...");
rc =
mxfHDLCRxAcqRead(mxfRxBuffer, 2, bufferSize, out rxAcqStatus, out msgCount, out byteCount, rxRecBufferPtr);
if (rc == MAXT_SUCCESS && msgCount == 2) {
Console.WriteLine("Frame received count = {0:D}", msgCount);
recPtr = rxRecBufferPtr;
for (UInt64 i = 0; i < msgCount && rc == MAXT_SUCCESS; i++) {
if (rc == MAXT_SUCCESS) {
}
}
}
}
for (UInt64 i = 0; i < msgCount && rc == MAXT_SUCCESS; i++) {
Console.WriteLine();
Console.WriteLine(" Record #{0}, Timetag: {0} Size: {1}", i, rxRec[i].timeTag, BLOCK_COUNT);
Console.Write(" Data:");
for (iData = 0; iData < BLOCK_COUNT; iData++) {
Console.Write(" {0:X2}", rxRec[i].data[iData]);
}
Console.WriteLine();
}
if (rxRecBufferPtr != IntPtr.Zero) {
Marshal.FreeHGlobal(rxRecBufferPtr);
}
}
if (rc == MAXT_SUCCESS) {
}
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 (mxfRxBuffer != 0) {
}
if (mxfTxBuffer != 0) {
}
Console.WriteLine();
Console.WriteLine("Press enter to exit");
Console.Read();
return;
}
}
}