using System;
using static MAXT.MXFoundation.mxf;
using System.Runtime.InteropServices;
using System.Text;
namespace async_flexsmp_rs232_example {
class async_flexsmp_rs232 {
static void Main(string[] args) {
UInt32 rc = MAXT_SUCCESS;
UInt64 server = 0;
var device = new UInt64[1];
var module = new UInt64[1];
UInt64 rxChannel = 0, txChannel = 0;
UInt64 bufferSize = 0, mxfRxBuffer = 0, mxfTxBuffer = 0;
UInt64 rxAcqStatus = 0;
UInt64 deviceCount = 0, moduleCount = 0, msgCount = 0, byteCount = 0;
#if (LOCAL)
#else
rc =
mxfServerConnect(
"192.168.0.1",
"admin",
"admin", Convert.ToUInt64(
false), out server);
#endif
if (rc == MAXT_SUCCESS) {
Console.WriteLine("Initializing ...");
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS && deviceCount == 1) {
}
if (rc == MAXT_SUCCESS && moduleCount == 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) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
#if (LOOPBACK)
if (rc == MAXT_SUCCESS) {
}
#endif
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
string dataString = "Hello, World!\0";
byte[] dataByte = Encoding.UTF8.GetBytes(dataString);
reserved = 0,
timeTag = 0,
control = 0,
repeatCount = 1,
dataSize = (UInt32)dataByte.Length,
data = new byte[256],
};
Array.Copy(dataByte, txRec.data, dataByte.Length);
IntPtr recPtr = Marshal.AllocHGlobal((int)bufferSize + 256);
Marshal.StructureToPtr(txRec, recPtr, false);
Console.WriteLine("Transmitting ...\n");
Marshal.FreeHGlobal(recPtr);
}
if (rc == MAXT_SUCCESS) {
}
if (rc == MAXT_SUCCESS) {
IntPtr recPtr = Marshal.AllocHGlobal((int)bufferSize);
if (recPtr == IntPtr.Zero) {
rc = MAXT_ERROR_MEM;
}
if (rc == MAXT_SUCCESS) {
Console.WriteLine("Receiving ...");
rc =
mxfASYNCEHRxAcqRead(mxfRxBuffer, 1, bufferSize, out rxAcqStatus, out msgCount, out byteCount, recPtr);
if (rc == MAXT_SUCCESS && msgCount == 1) {
Console.WriteLine(
" Timetag: {0} Size: {1}", rxRec.
timeTag, rxRec.
dataSize);
Console.WriteLine(
" String: {0}", Encoding.UTF8.GetString(rxRec.
data, 0, (
int)rxRec.
dataSize));
}
}
if (recPtr != IntPtr.Zero) {
Marshal.FreeHGlobal(recPtr);
}
}
if (rc == MAXT_SUCCESS) {
}
if (rc != MAXT_SUCCESS) {
StringBuilder buffer = new StringBuilder(256);
buffer.Append(string.Format("ERROR # 0x{0:x8}", rc));
}
Console.WriteLine(buffer);
}
Console.WriteLine();
Console.WriteLine("Terminating...");
if (mxfRxBuffer != 0) {
}
if (mxfTxBuffer != 0) {
}
Console.WriteLine();
Console.WriteLine("Press enter to exit");
Console.Read();
return;
}
}
}