MX Foundation 4
selfTests.cs
/*****************************************************************************
//
// File:
// selfTests.cs
//
// Copyright (c) MAX Technologies Inc. 1988-2019, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the basic usage of some self test functions
// for different protocols and some card components.
//
// Hardware requirements:
// - MAXT Flex.
//
*****************************************************************************/
//#define EXT_LOOPBACK
//#define LOCAL
using System;
using static MAXT.MXFoundation.mxf;
using System.Text;
using System.Runtime.InteropServices;
namespace DeviceMgmt_example
{
class selfTests
{
const int EXT_LOOPBACK = 1;
static void Main(string[] args)
{
UInt32 rc;
UInt64 server;
UInt64 device = 0;
UInt64 result = 0;
StringBuilder info = new StringBuilder("", 256);
StringBuilder diagnostic = new StringBuilder("", 256);
UInt64 zone = 0;
UInt64 port;
int testCnt = 0;
int failCnt = 0;
// Connect to services and initialize environment
#if LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", 0, out server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", 0, out server);
#endif
if (rc != MAXT_SUCCESS)
{
Console.Write("Failed to connect; rc=0x%08x", rc);
Console.ReadKey();
return;
}
if (rc == MAXT_SUCCESS)
Console.Write("Starting ...\n\n");
// Gets the device handle
if (rc == MAXT_SUCCESS)
rc = mxfSystemDeviceGet(server, 0, out device);
Console.Write("mxfSelfTestMEMORY(EXHAUSTIVE) ... ");
rc = mxfSelfTestMEMORY(device, MXF_SELFTEST_LEVEL_EXHAUSTIVE, out result, info, diagnostic);
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestMILSTD1553(port #{0}) ... ", port);
rc = mxfSelfTestMILSTD1553(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestEBR1553(port #{0}) ... ", port);
rc = mxfSelfTestEBR1553(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestSERIALASYNC(port #{0}) ... ", port);
rc = mxfSelfTestSERIALASYNC(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestARINC429(port #{0}) ... ", port);
rc = mxfSelfTestARINC429(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestARINC717(port #{0}) ... ", port);
rc = mxfSelfTestARINC717(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestHDLC(port #{0}) ... ", port);
rc = mxfSelfTestHDLC(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestCSDB(port #{0}) ... ", port);
rc = mxfSelfTestCSDB(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestARINC629(port #{0}) ... ", port);
rc = mxfSelfTestARINC629(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestDISCRETE(port #{0}) ... ", port);
rc = mxfSelfTestDISCRETE(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (port = 0; ; port++)
{
Console.Write("mxfSelfTestARINC708(port #{0}) ... ", port);
rc = mxfSelfTestARINC708(device, port, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
if (rc == MAXT_ERROR_PORT_NOT_FOUND) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (zone = 0; ; zone++)
{
double value;
Console.Write("mxfSelfTestVOLTAGE({0}) ... ", zone);
rc = mxfSelfTestVOLTAGE(device, zone, out value, out result, info, diagnostic);
if (rc == MAXT_ERROR_ZONE) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
Console.Write(" value = {0:F2} \n", value);
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (zone = 0; ; zone++)
{
double value;
Console.Write("mxfSelfTestCURRENT({0}) ... ", zone);
rc = mxfSelfTestCURRENT(device, zone, out value, out result, info, diagnostic);
if (rc == MAXT_ERROR_ZONE) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
Console.Write(" value = {0:F2} \n", value);
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
for (zone = 0; ; zone++)
{
double value;
Console.Write("mxfSelfTestTEMPERATURE({0}) ... ", zone);
rc = mxfSelfTestTEMPERATURE(device, zone, out value, out result, info, diagnostic);
if (rc == MAXT_ERROR_ZONE) { rc = 0; Console.Write("\r \r"); break; }
Console.Write("\n");
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
Console.Write(" value = {0:F2} \n", value);
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
}
Console.Write("mxfSelfTestRTCLK() ... \n");
rc = mxfSelfTestRTCLK(device, MXF_SELFTEST_LEVEL_QUICK, out result, info, diagnostic);
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
Console.Write("mxfSelfTestDEBUGCOMPORT() ... \n");
rc = mxfSelfTestDEBUGCOMPORT(device, 0, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
Console.Write("mxfSelfTestNVSTORAGE() ... \n");
rc = mxfSelfTestNVSTORAGE(device, MXF_SELFTEST_LEVEL_QUICK, out result, info, diagnostic);
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
Console.Write("mxfSelfTestSYNCIO() ... \n");
rc = mxfSelfTestSYNCIO(device, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
Console.Write("mxfSelfTestIRIGB(Digital) ... \n");
rc = mxfSelfTestIRIGB(device, MXF_SELFTEST_IRIGB_SIGNAL_DIGITAL, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
#if EXT_LOOPBACK
Console.Write("mxfSelfTestIRIGB(AM) ... \n");
rc = mxfSelfTestIRIGB(device, MXF_SELFTEST_IRIGB_SIGNAL_AM, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc > 0)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
Console.Write("mxfSelfTestIRIGB(AM+1PPS External Signal) ... \n");
rc = mxfSelfTestIRIGB(device, MXF_SELFTEST_IRIGB_SIGNAL_AM_1PPS, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
testCnt++; if (rc > 0 || result > 0) failCnt++;
if (rc > 0)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
#endif
# if LOCAL
Console.Write("mxfSelfTestETHERNET() ... \n");
rc = mxfSelfTestETHERNET(device, 0, MXF_SELFTEST_LEVEL_QUICK, EXT_LOOPBACK, out result, info, diagnostic);
testCnt++; if (rc >0 || result > 0) failCnt++;
if (rc != MAXT_SUCCESS)
{
Console.Write(" ERROR = 0x{0:X8} \n", rc);
}
else
{
Console.Write(" info = {0} \n", info);
Console.Write(" Result = {0} \n", result > 0 ? "FAILED" : "PASSED");
if (result > 0)
Console.Write(" diagnostic = {0} \n", diagnostic);
}
Console.Write(" \n");
#endif
Console.Write(" --------------------------------------- \n");
Console.Write(" TEST {0} ", failCnt > 0 ? "FAILED" : "PASSED");
if (failCnt > 0)
Console.Write("({0} of {1} tests failed) \n", failCnt, testCnt);
else
Console.Write("\n");
Console.Write(" --------------------------------------- \n");
Console.Write("\n");
if (rc != MAXT_SUCCESS)
{
var errorString = new StringBuilder(256);
if (mxfSystemErrorStringGet(server, rc, (UInt32)Marshal.SizeOf(errorString), errorString) != 0)
Console.Write(errorString + "ERROR # 0x{0:X8}", rc);
Console.Write("{0}\n\r", errorString);
}
Console.Write("\nPress a key to terminate\n");
Console.ReadKey();
return;
}
}
}
Updated 03/30/2022