using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
namespace ar429_example
{
class ar429_comm_queues
{
const int BUFFER_SIZE = 4096;
const int EX_MAX_PARAM = 8;
const int TX_INDEX = 0;
const int RX_INDEX = 1;
const UInt32 EX_USER_COMMAND_ID_INIT = 0x0;
const UInt32 EX_USER_COMMAND_ID_START_TX = 0x1;
const UInt32 EX_USER_COMMAND_ID_STOP_TX = 0x2;
const UInt32 EX_USER_COMMAND_ID_START_ACQ = 0x3;
const UInt32 EX_USER_COMMAND_ID_STOP_ACQ = 0x4;
const UInt32 EX_USER_COMMAND_ID_TERMINATE = 0x5;
const UInt32 EX_USER_COMMAND_ACK = 0xA5A5A5A5;
public class EX_COMMAND
{
public UInt32 command;
public UInt32 paramNum;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EX_MAX_PARAM)]
public UInt32[] param;
}
static void Main(string[] args)
{
UInt64 server;
var device = new UInt64[1];
var module = new UInt64[1];
var rxChannel = new UInt64[1];
var txChannel = new UInt64[1];
UInt64 rxBuffer = 0;
UInt64 txBuffer = 0;
var Cmd = new EX_COMMAND();
Cmd.param = new UInt32[EX_MAX_PARAM];
UInt64 devIdx = 0, modIdx = 0, rxChnIdx = 0, txChnIdx = 0;
UInt64 count = 0;
UInt32 rc;
if (rc == MAXT_SUCCESS)
Console.WriteLine("Starting");
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if ((rc == MAXT_SUCCESS) && (count != 0))
if ((rc == MAXT_SUCCESS) && (count == 0))
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
}
if (rc == MAXT_SUCCESS)
rc =
mxfDeviceFileUpload(device[0], MXF_DEVICE_FILETYPE_APPLICATION,
"ar429_embedded_comm_queues-flex.mxf");
if (rc == MAXT_SUCCESS)
{
Cmd.command = EX_USER_COMMAND_ID_INIT;
Cmd.paramNum = 0;
Cmd.param[0] = 0;
rc = CommandSend(txBuffer, rxBuffer, Cmd);
if (rc == MAXT_SUCCESS)
Console.Write("Initialisation\n");
}
if (rc == MAXT_SUCCESS)
{
Cmd.command = EX_USER_COMMAND_ID_START_ACQ;
Cmd.paramNum = 1;
Cmd.param[0] = (UInt32)rxChnIdx;
rc = CommandSend(txBuffer, rxBuffer, Cmd);
if (rc == MAXT_SUCCESS)
Console.Write("Acquisition started\n");
}
if (rc == MAXT_SUCCESS)
{
Cmd.command = EX_USER_COMMAND_ID_START_TX;
Cmd.paramNum = 1;
Cmd.param[0] = (UInt32)txChnIdx;
rc = CommandSend(txBuffer, rxBuffer, Cmd);
if (rc == MAXT_SUCCESS)
Console.Write("Transmission started\n");
}
if (rc == MAXT_SUCCESS)
{
Console.Write("Running...\n");
}
if (rc == MAXT_SUCCESS)
{
Cmd.command = EX_USER_COMMAND_ID_STOP_TX;
Cmd.paramNum = 1;
Cmd.param[0] = (UInt32)txChnIdx;
rc = CommandSend(txBuffer, rxBuffer, Cmd);
if (rc == MAXT_SUCCESS)
Console.Write("Transmission stopped\n");
}
if (rc == MAXT_SUCCESS)
{
Cmd.command = EX_USER_COMMAND_ID_STOP_ACQ;
Cmd.paramNum = 1;
Cmd.param[0] = (UInt32)rxChnIdx;
rc = CommandSend(txBuffer, rxBuffer, Cmd);
if (rc == MAXT_SUCCESS)
Console.Write("Acquisition stopped\n");
}
if (rc == MAXT_SUCCESS)
{
Cmd.command = EX_USER_COMMAND_ID_TERMINATE;
Cmd.paramNum = 0;
rc = CommandSend(txBuffer, rxBuffer, Cmd);
if (rc == MAXT_SUCCESS)
Console.Write("Terminating\n");
}
if (rc != MAXT_SUCCESS)
{
StringBuilder buffer = new StringBuilder(256);
{
buffer.Clear();
buffer.Append(string.Format("ERROR # 0x{0:x8}", rc));
}
Console.Write(buffer + "\n\r");
}
Console.Write("\nPress enter to terminate\n");
Console.ReadKey();
return;
}
private static UInt32 InitAttribHandler(UInt64 server, UInt64 cardIndex, UInt64 moduleIndex, UInt64 channelIndex, UInt64 attrib, ref UInt64 value)
{
if (attrib == KMXF_DEVICE_COMM_QUEUE_NUM)
{
value = 2;
return Convert.ToUInt32(true);
}
return Convert.ToUInt32(false);
}
private static UInt32 CommandSend(UInt64 txBuffer, UInt64 rxBuffer, EX_COMMAND cmd)
{
msg[0].
data =
new UInt32[256];
IntPtr msgPtr = IntPtr.Zero;
UInt64 readCnt;
UInt64 byteCnt;
UInt32 rc = 0;
if (rc == MAXT_SUCCESS)
{
try
{
msgPtr = Marshal.AllocHGlobal(BUFFER_SIZE);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
msg[0].dataSize = (2 + cmd.paramNum) * 4;
msg[0].data[0] = cmd.command;
msg[0].data[1] = cmd.paramNum;
for (int i = 0; i < cmd.paramNum; i++)
msg[0].data[i + 2] = cmd.param[i];
Marshal.StructureToPtr(msg[0], msgPtr, true);
if (rc != MAXT_SUCCESS)
Console.Write("Write error rc=0x{0:x8}\n", rc);
while (rc == MAXT_SUCCESS)
{
if (readCnt > 0)
{
msg[0].data[0] = 0;
if (msg[0].data[0] == EX_USER_COMMAND_ACK)
break;
}
}
if (msgPtr != IntPtr.Zero)
Marshal.FreeHGlobal(msgPtr);
return rc;
}
}
}