#define LOOPBACK
#define LOCAL
using System;
using System.Text;
using System.Runtime.InteropServices;
using static MAXT.MXFoundation.mxf;
namespace mil1553_example
{
public class mil1553_aperiodic
{
const UInt32 NUM_REC_TX = 10;
static void Main(string[] args)
{
UInt32 rc;
UInt64 deviceCount;
UInt64 moduleCount = 0;
UInt64 channelCount = 0;
UInt64 server;
var device = new UInt64[1];
var module = new UInt64[1];
var bc = new UInt64[1];
UInt64 bcBufferTx = 0;
UInt64 bcBufferRx = 0;
IntPtr recPtr = IntPtr.Zero;
UInt32 txBufferSize;
IntPtr txBuffer = IntPtr.Zero;
txRec1553.
data =
new UInt16[36];
UInt32 rxBufferSize = 0;
IntPtr rxBuffer = IntPtr.Zero;
UInt64 card, mod, port;
UInt64 cmd;
UInt64 rxAcqStatus;
UInt64 msgCount = 0;
UInt64 byteCount;
UInt64 rxRec;
UInt32 data;
UInt64 options;
var errorString = new StringBuilder(200);
#if (LOCAL)
#else
rc =
mxfServerConnect(
"192.168.0.1",
"admin",
"admin", Convert.ToUInt64(
false), out server);
#endif
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting ...\n");
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS && moduleCount == 0)
}
if (rc == MAXT_SUCCESS && moduleCount > 0)
if (rc == MAXT_SUCCESS && moduleCount > 0)
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
Console.Write("BC location is Device:{0} Module:{1} Port:{2}\n", card, mod, port);
if (rc == MAXT_SUCCESS)
{
if ((rc == MAXT_SUCCESS) && ((options & VMXF_MIL1553_MODULE_OPTIONS_HYBRID_MODE) == VMXF_MIL1553_MODULE_OPTIONS_HYBRID_MODE))
{
if (rc == MAXT_SUCCESS)
}
}
#if (LOOPBACK)
if (rc == MAXT_SUCCESS)
#endif
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
{
try
{
txBuffer = Marshal.AllocHGlobal((int)txBufferSize);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
}
if (rc == MAXT_SUCCESS)
{
rxBufferSize = 10 * 1024;
if (rc == MAXT_SUCCESS)
{
try
{
rxBuffer = Marshal.AllocHGlobal((int)rxBufferSize);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
recPtr = txBuffer;
for (cmd = 0; cmd < NUM_REC_TX && rc == MAXT_SUCCESS; cmd++)
{
if (cmd % 2 > 0)
{
txRec1553.
data[1] = 0x0000;
txRec1553.
data[2] = 0x1111;
txRec1553.
data[3] = 0x2222;
txRec1553.
data[4] = 0x3333;
}
else
{
txRec1553.
data[1] = 0x3333;
txRec1553.
data[2] = 0x2222;
txRec1553.
data[3] = 0x1111;
txRec1553.
data[4] = 0x0000;
}
Marshal.StructureToPtr(txRec1553, recPtr, false);
}
if (rc == MAXT_SUCCESS)
}
if (rc == MAXT_SUCCESS)
{
rc =
mxfMIL1553RxAcqRead(bcBufferRx, 0, rxBufferSize, out rxAcqStatus, out msgCount, out byteCount, rxBuffer);
recPtr = rxBuffer;
for (rxRec = 0; rxRec < msgCount && rc == MAXT_SUCCESS; rxRec++)
{
Console.Write(
"\n\r{0}\t", rxRec1553.
timeTag);
Console.Write(
"Control: 0x{0:x8}", rxRec1553.
control);
for (data = 0; data < rxRec1553.
dataSize / 2; data++)
{
if (data > 0 && ((data % 5) == 0))
Console.Write("\n\r\t\t\t");
Console.Write(
" 0x{0:x4}", rxRec1553.
data[data]);
}
Console.Write("\n\r");
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (txBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(txBuffer);
if (rxBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(rxBuffer);
if (rc != MAXT_SUCCESS)
{
{
errorString.Clear();
errorString.Append(string.Format("ERROR # 0x{0:x8}", rc));
}
Console.Write(errorString + "\n\r");
}
if (device[0] != 0)
Console.Write("\n\rPress enter to terminate\n\r");
Console.ReadKey();
return;
}
}
}