#define LOOPBACK
#define LOCAL
using System;
using System.Text;
using System.Runtime.InteropServices;
using static MAXT.MXFoundation.mxf;
namespace mil1553_example
{
public class mil1553_bm
{
static void Main(string[] args)
{
UInt32 rc;
UInt64 deviceCount = 0;
UInt64 moduleCount = 0;
UInt64 channelCount = 0;
UInt64 server;
var device = new UInt64[1];
var module = new UInt64[1];
var bm = new UInt64[1];
UInt64 rx = 0;
IntPtr recPtr = IntPtr.Zero;
IntPtr rxBuffer = IntPtr.Zero;
UInt32 rxBufferSize = 20 * 1024;
UInt64 rxAcqStatus;
UInt64 msgCount;
UInt64 byteCount;
UInt64 rxRec;
UInt64 loop = 0;
UInt64 address, subAddress, dir, wordCount;
UInt64 card = 0, mod = 0, port = 0;
UInt32 data;
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)
{
if (rc == MAXT_ERROR_ANOTHER_PROCESS_RUNNING)
{
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS && deviceCount > 0)
{
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("BM location is Device:{0} Module:{1} Port:{2}\n", card, mod, port);
if (rc == MAXT_SUCCESS)
{
rxBufferSize = 100 * 1024;
if (rc == MAXT_ERROR_BUFFER_ALLOCATED)
if (rc == MAXT_SUCCESS)
{
try
{
rxBuffer = Marshal.AllocHGlobal((int)rxBufferSize);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting BM\n\r");
}
if (rc == MAXT_SUCCESS)
{
do
{
rc =
mxfMIL1553RxAcqRead(rx, 0, rxBufferSize, out rxAcqStatus, out msgCount, out byteCount, rxBuffer);
if (rc > MAXT_SUCCESS)
break;
recPtr = rxBuffer;
for (rxRec = 0; rxRec < msgCount && rc == MAXT_SUCCESS; rxRec++)
{
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
{
Console.Write("\n\r{0}:\t", rxRec1553[0].timeTag);
switch (msgInfo[0].msgType)
{
case MXF_MIL1553_MSGINFO_TYPE_BCRT:
Console.Write("BC to RT{0} SA{1} WC{2} (0x{3:x4})\n\r", address, subAddress, wordCount, rxRec1553[0].data[0]);
Console.Write("\t\tBC data:");
for (data = 0; data < msgInfo[0].dataWordCount; data++)
{
if (data > 0 && (data % 4) == 0)
Console.Write("\n\r\t\t\t");
Console.Write(" 0x{0:x4}", rxRec1553[0].data[msgInfo[0].dataIndex + data]);
}
Console.Write("\n\r");
if (msgInfo[0].statusIndex[0] != 0xffff)
Console.Write("\t\tRT status: 0x{0:x4}\n\r", rxRec1553[0].data[msgInfo[0].statusIndex[0]]);
break;
case MXF_MIL1553_MSGINFO_TYPE_RTBC:
Console.Write("RT{0} SA{1} WC{2} to BC (0x{3:x4})\n\r", address, subAddress, wordCount, rxRec1553[0].data[0]);
if (msgInfo[0].statusIndex[0] != 0xffff)
{
Console.Write("\t\tRT status: 0x{0:x4}\n\r", rxRec1553[0].data[msgInfo[0].statusIndex[0]]);
Console.Write("\t\tRT data:");
for (data = 0; data < msgInfo[0].dataWordCount; data++)
{
if (data > 0 && (data % 4) == 0)
Console.Write("\n\r\t\t\t");
Console.Write(" 0x{0:x4}", rxRec1553[0].data[msgInfo[0].dataIndex + data]);
}
Console.Write("\n\r");
}
break;
case MXF_MIL1553_MSGINFO_TYPE_MODECODE_TXDATA:
Console.Write("BC Mode Command {0} to RT{1} SA{2} (0x{3:x4})\n\r", wordCount, address, subAddress, rxRec1553[0].data[0]);
if (msgInfo[0].statusIndex[0] != 0xffff)
{
Console.Write("\t\tRT status: 0x{0:x4}\n\r", rxRec1553[0].data[msgInfo[0].statusIndex[0]]);
Console.Write("\t\tRT data: 0x{0:x4}\n\r", rxRec1553[0].data[msgInfo[0].dataIndex]);
}
break;
}
}
}
}
loop++;
} while (loop < 200);
}
if (rc == MAXT_SUCCESS)
{
Console.Write("Stopping BM\n\r");
}
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 (rx > 0)
{
if (rc != MAXT_SUCCESS)
Console.Write("Free buffer failed !\n\r");
}
if (rc == MAXT_ERROR_ANOTHER_PROCESS_RUNNING)
{
}
Console.Write("\n\rPress enter to terminate\n\r");
Console.ReadKey();
return;
}
}
}