using System;
using System.Text;
using System.Runtime.InteropServices;
using static MAXT.MXFoundation.mxf;
namespace RelayBox_example
{
public class relaybox
{
static void Main(string[] args)
{
UInt32 rc;
UInt64 server = 0;
UInt64 device = 0;
UInt64 rotarySw = 0, db9 = 0, relay = 0;
rc =
mxfServerConnect(
"192.168.0.1",
"admin",
"admin", Convert.ToUInt64(
true), out server);
if (rc != MAXT_SUCCESS)
{
Console.Write("Failed to connect; rc=0x{0:x8}", rc);
Console.WriteLine("\n\rPress a key to terminate");
Console.ReadKey();
return;
}
Console.Write("\nStarting\n");
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
Console.WriteLine("Relays currently set to 0x{0:x16}", relay);
if ((rotarySw != 0) || (db9 != 0))
Console.WriteLine("Rotary switch and DB9 configuration will override software configuration");
}
if (rc == MAXT_SUCCESS)
if (rc == MAXT_SUCCESS)
{
UInt16 i, A, B, C, D;
UInt16 mask;
Console.WriteLine("Relays now set to 0x{0:x16}", relay);
A = (UInt16)(relay & 0xFFFF);
B = (UInt16)((relay >> 16) & 0xFFFF);
C = (UInt16)((relay >> 32) & 0xFFFF);
D = (UInt16)((relay >> 48) & 0xFFFF);
for (i = 0; i < 16; i++)
{
Console.Write("{0:d2}: ", i);
mask = (UInt16)(1 << i);
if ((A & mask) == mask)
Console.Write("A");
if ((B & mask) == mask)
Console.Write("B");
if ((C & mask) == mask)
Console.Write("C");
if ((D & mask) == mask)
Console.Write("D");
if (((A | B | C | D) & mask) == mask)
Console.WriteLine();
else
Console.WriteLine("-");
}
}
if (rc != MAXT_SUCCESS)
{
var errorString = new StringBuilder(200);
{
errorString.Clear();
errorString.Append(string.Format("ERROR # 0x{0:x8}", rc));
}
Console.WriteLine(errorString);
}
Console.WriteLine("\n\rTerminating");
Console.WriteLine("\n\rPress enter to terminate");
Console.ReadKey();
return;
}
}
}