using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
namespace discrete_example
{
class discrete_pulse_clock
{
const int MAX_TX_RECORDS_TO_TRANSMIT = 1;
static void Main(string[] args)
{
UInt32 rc;
UInt64 server;
UInt64 device = 0;
var module = new UInt64[1];
var txChannel = new UInt64[1];
UInt64 txBuffer = 0;
IntPtr recPtr = IntPtr.Zero;
UInt64 moduleCount = 0;
UInt64 channelCount = 0;
UInt64 txBufferSize = 0;
IntPtr txHostBuffer = IntPtr.Zero;
UInt64 data;
#if LOCAL
#else
#endif
if (rc != MAXT_SUCCESS)
{
Console.Write("Failed to connect; rc=0x{0:X8}", rc);
Console.ReadKey();
return;
}
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting ...\n");
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
rc =
mxfModuleChannelAllGet(module[0], MXF_CLASS_DISCRETE, MXF_SCLASS_TX_CHANNEL, 1, out channelCount, txChannel);
if (rc == MAXT_SUCCESS && channelCount == 0)
rc = MAXT_ERROR_NOT_FOUND;
if (rc == MAXT_SUCCESS)
{
if (rc == MAXT_SUCCESS)
{
try
{
txHostBuffer = Marshal.AllocHGlobal((int)txBufferSize);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
recPtr = txHostBuffer;
for (data = 0; data < MAX_TX_RECORDS_TO_TRANSMIT; data++)
{
rec.timeTag = 0;
rec.control = MXF_DISCRETE_TX_REC_CTRL_PULSE_START;
rec.repeatCount = 1;
rec.data = 0x0000;
rec.edge = 0x0003;
rec.highDuration = (UInt32)(200000000);
rec.lowDuration = (UInt32)(100000000);
Marshal.StructureToPtr(rec, recPtr, false);
}
}
if (rc == MAXT_SUCCESS)
{
Console.Write("Transmitting ...\n");
}
if (rc == MAXT_SUCCESS)
{
}
if (rc == MAXT_SUCCESS)
{
recPtr = txHostBuffer;
rec.timeTag = 0;
rec.control = 0;
rec.repeatCount = 1;
rec.data = 0x0000;
rec.edge = 0x0003;
rec.highDuration = 0;
rec.lowDuration = 0;
Marshal.StructureToPtr(rec, recPtr, true);
}
if (txBuffer > 0)
if (txHostBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(txHostBuffer);
if (rc != MAXT_SUCCESS)
{
StringBuilder errorString = new StringBuilder(256);
Console.WriteLine(errorString + "\n");
}
Console.Write("Terminating ...\n");
Console.Write("\nPress a key to terminate\n");
Console.ReadKey();
return;
}
}
}