#define LOOPBACK
#define LOCAL
using System;
using System.Text;
using System.Runtime.InteropServices;
using static MAXT.MXFoundation.mxf;
namespace mil1553_example
{
public class mil1553_rt_rt
{
const UInt32 NUM_REC_TX = 10;
static void Main(string[] args)
{
UInt32 rc;
UInt64 server;
UInt64 bc = 0, rt5 = 0, rt7 = 0, bm = 0;
UInt64 bcBufferTx = 0;
UInt64 bmBufferRx = 0;
UInt64 rt5Buffer = 0, rt7Buffer = 0;
IntPtr recPtr = IntPtr.Zero;
UInt32 txBufferSize;
IntPtr txBuffer = IntPtr.Zero;
UInt32 rxBufferSize = 0;
IntPtr rxBuffer = IntPtr.Zero;
UInt64 cmd;
UInt64 rxAcqStatus;
UInt64 msgCount;
UInt64 byteCount;
UInt64 rxRec;
UInt64 address1 = 0, subAddress1 = 0, dir1 = 0, wordCount1 = 0;
UInt64 address2 = 0, subAddress2 = 0, dir2 = 0, wordCount2 = 0;
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)
rc =
mxfChannelGet(server, MXF_CLASS_MIL1553, MXF_SCLASS_BM_CHANNEL, MXF_MODULE_ALL, 0, out bm);
if (rc == MAXT_SUCCESS)
rc =
mxfChannelGet(server, MXF_CLASS_MIL1553, MXF_SCLASS_BC_CHANNEL, MXF_MODULE_ALL, 0, out bc);
if (rc == MAXT_SUCCESS)
rc =
mxfChannelGet(server, MXF_CLASS_MIL1553, MXF_SCLASS_RT_CHANNEL, MXF_MODULE_ALL, 5, out rt5);
if (rc == MAXT_SUCCESS)
rc =
mxfChannelGet(server, MXF_CLASS_MIL1553, MXF_SCLASS_RT_CHANNEL, MXF_MODULE_ALL, 7, out rt7);
#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)
if (rc == MAXT_SUCCESS)
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
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)
recPtr = txBuffer;
for (cmd = 0; cmd < NUM_REC_TX && rc == MAXT_SUCCESS; cmd++)
{
txRec1553.data = new UInt16[36];
txRec1553.timeTag = 0;
txRec1553.repeatCount = 1;
txRec1553.control = MXF_MIL1553_TXAPERIODIC_REC_CTRL_RT_RT;
txRec1553.dataSize = 4;
if (rc == MAXT_SUCCESS)
Marshal.StructureToPtr(txRec1553, recPtr, true);
if (rc == MAXT_SUCCESS)
}
Console.Write("Transmitting...\n");
if (rc == MAXT_SUCCESS)
{
Console.Write("Reading...\n");
rc =
mxfMIL1553RxAcqRead(bmBufferRx, 0, rxBufferSize, out rxAcqStatus, out msgCount, out byteCount, rxBuffer);
recPtr = rxBuffer;
for (rxRec = 0; rxRec < msgCount && rc == MAXT_SUCCESS; rxRec++)
{
if (rc == MAXT_SUCCESS)
{
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_RTRT:
Console.Write("RT{0} SA{1} to RT{2} SA{3} WC{4} (0x{5:x4})\n\r", address1, subAddress1, address2, subAddress2, wordCount1, rxRec1553[0].data[0]);
if (msgInfo[0].statusIndex[0] != 0xffff)
Console.Write("\t\tRT{0} SA{1} status: 0x{2:x4}\n\r", address1, subAddress1, rxRec1553[0].data[msgInfo[0].statusIndex[0]]);
if (msgInfo[0].statusIndex[1] != 0xffff)
Console.Write("\t\tRT{0} SA{1} status: 0x{2:x4}\n\r", address2, subAddress2, rxRec1553[0].data[msgInfo[0].statusIndex[1]]);
break;
}
}
}
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
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 (bcBufferTx > 0)
if (bmBufferRx > 0)
if (rt5Buffer > 0)
if (rt7Buffer > 0)
Console.Write("\n\rPress enter to terminate\n\r");
Console.ReadKey();
return;
}
}
}