#define LOOPBACK
using System;
using System.Text;
using System.Runtime.InteropServices;
using static MAXT.MXFoundation.mxf;
namespace mil1553_example
{
public class mil1553_errors
{
const UInt64 BUF_SA3_RX = 0;
const UInt64 RT_ADRS = 20;
const UInt64 RT_SUBADRS = 3;
const UInt64 RT_ADRS_ERROR = 5;
static void Main(string[] args)
{
UInt64 server;
var device = new UInt64[1];
var module = new UInt64[1];
var bc = new UInt64[1];
var rt = new UInt64[1];
var bcBufferTx = new UInt64[1];
UInt64 bcBufferRx = 0;
var rtBuffer = new UInt64[1];
IntPtr txBuffer = IntPtr.Zero;
UInt32 txBufferSize = 20 * 1024;
IntPtr rxBuffer = IntPtr.Zero;
UInt32 rxBufferSize = 20 * 1024;
err.errors = new UInt16[34];
var errorString = new StringBuilder(200);
UInt64 bus = MXF_MIL1553_BUS_A | MXF_MIL1553_BUS_B;
UInt64 rxAcqStatus;
UInt64 msgCount = 0;
UInt64 byteCount, indexBuffer;
UInt64 rxRec;
UInt32 loop = 0;
UInt64 address, subAddress, dir, wordCount;
UInt32 msg;
UInt64 deviceCount = 0;
UInt64 moduleCount = 0;
UInt64 channelCount = 0;
UInt32 rc;
#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\r");
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS && deviceCount > 0)
if (rc == MAXT_SUCCESS && moduleCount > 0)
if (rc == MAXT_SUCCESS && moduleCount == 0)
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
#if LOOPBACK
if (rc == MAXT_SUCCESS)
#endif
if (rc == MAXT_SUCCESS)
{
txBufferSize = 1024;
for (msg = 0; msg < 1 && rc == MAXT_SUCCESS; msg++)
{
if (rc == MAXT_SUCCESS)
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)
rc =
mxfRxAcqBufferStatusGet(bcBufferRx, out UInt64 status, out UInt64 realMsgCount, out UInt64 pendingBytes, out msgCount);
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)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
}
if (rc == MAXT_SUCCESS)
{
err.errors[0] = MXF_MIL1553_ERRORID_PAR;
}
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
{
minorFrame[0].modulo = 1;
minorFrame[0].buffer = bcBufferTx[BUF_SA3_RX];
minorFrame[0].retryHaltOptions = MXF_MIL1553_TXPERIODIC_MJRFRAME_MSG_RETRY_ERROR_ENABLE | MXF_MIL1553_TXPERIODIC_MJRFRAME_MSG_RETRY_ALT_BUS;
}
}
if (rc == MAXT_SUCCESS)
{
txRec1553.data = new UInt16[36];
txRec1553.repeatCount = 1;
txRec1553.control = MXF_MIL1553_TXPERIODIC_REC_CTRL_ERROR_INJ;
txRec1553.service.txPeriodicUpdateMsg.errorIndex = 0;
txRec1553.dataSize = 8;
txRec1553.data[0] = 0x0000;
txRec1553.data[1] = 0x0000;
txRec1553.data[2] = 0x1111;
txRec1553.data[3] = 0x2222;
Marshal.StructureToPtr(txRec1553, txBuffer, true);
}
if (rc == MAXT_SUCCESS)
{
txRec1553.data = new UInt16[36];
txRec1553.repeatCount = 1;
txRec1553.control = MXF_MIL1553_TXPERIODIC_REC_CTRL_ERROR_INJ;
txRec1553.service.txPeriodicUpdateMsg.errorIndex = 1;
txRec1553.dataSize = 8;
txRec1553.data[0] = 0x0000;
txRec1553.data[1] = 0x0000;
txRec1553.data[2] = 0x1111;
txRec1553.data[3] = 0x2222;
Marshal.StructureToPtr(txRec1553, txBuffer, true);
}
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting BC - RT\n\r");
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
IntPtr recPtr = IntPtr.Zero;
do
{
rc =
mxfMIL1553RxAcqRead(bcBufferRx, 0, rxBufferSize, out rxAcqStatus, out msgCount, out byteCount, rxBuffer);
if (rc > MAXT_SUCCESS)
Console.Write("mxfMIL1553RxAcqRead() error; rc=0x{0:x8}\n\r", rc);
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} Bus{3} (0x{4:x4})\n\r", address, subAddress, wordCount, (rxRec1553[0].control & MXF_MIL1553_RX_REC_CTRL_MSG_BUS_B) > 0 ? "B" : "A", rxRec1553[0].data[0]);
Console.Write("\t\tRT status: 0x{0:x4}\n\r", rxRec1553[0].data[msgInfo[0].statusIndex[0]]);
Console.Write("\t\tParity {0}\n\r", (rxRec1553[0].control & MXF_MIL1553_RX_REC_CTRL_MSG_PARITY_ERROR) > 0 ? "Error" : "OK");
break;
}
}
}
if (rc == MAXT_SUCCESS)
}
loop++;
} while (loop < 10 && rc == MAXT_SUCCESS);
}
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
}
if (rc == MAXT_SUCCESS)
{
Console.Write("Stopping BC - RT\n\r");
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
Console.Write("Total number of transactions: {0}\n\r", transGlobal.totalCount);
}
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
Console.Write("Total number of errors: {0}\n\r", errorGlobal.totalError);
}
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");
}
for (indexBuffer = 0; indexBuffer < 1; indexBuffer++)
{
if (bcBufferTx[0] > 0)
{
if (rc != MAXT_SUCCESS)
Console.Write("Free buffer failed !\n\r");
}
}
for (indexBuffer = 0; indexBuffer < 1; indexBuffer++)
{
if (rtBuffer[0] > 0)
{
if (rc != MAXT_SUCCESS)
Console.Write("Free buffer failed !\n\r");
}
}
if (bcBufferRx > 0)
{
if (rc != MAXT_SUCCESS)
Console.Write("Free buffer failed !\n\r");
}
Console.Write("\n\rPress enter to terminate\n\r");
Console.ReadKey();
return;
}
}
}