MX Foundation 4
discrete_Multi.cs
/******************************************************************************
//
// File:
// discrete_Multi.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 how to set the discretes on the multi module.
// To make it work properly, you need an external loopback on the multi module, connecting each TX to
// its corresponding RX.
// When there is no error and the multi DIOs are correctly set, no message is displayed.
// When you have a wrong value on the multi DIOs, a message will pop out.
// To provoke an error, simply unplug the LB.
//
// Hardware requirements:
// - MAXT Flex.
// - Loopback plugged on the multi port (connecting each TX to its corresponding RX)
//
*******************************************************************************/
//#define LOCAL
using System;
using static MAXT.MXFoundation.mxf;
using System.Text;
namespace discrete_example
{
class discrete_Multi
{
static void Main(string[] args)
{
UInt32 rc;
UInt64 moduleCount = 0;
UInt64 channelCount = 0;
UInt64 server;
UInt64 device = 0;
var module = new UInt64[1];
var rx = new UInt64[1];
var tx = new UInt64[1];
UInt64 i;
UInt64 state = 0;
StringBuilder errorString = new StringBuilder();
// 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
// Initializes init callback handler to set all TX and RX channels to DIOs on the multi module
if (rc == MAXT_SUCCESS)
// Initialize MX Foundation library
if (rc == MAXT_SUCCESS)
{
Console.Write("Starting ...\n");
rc = mxfSystemInit(server);
}
// Get handle of device
if (rc == MAXT_SUCCESS)
rc = mxfSystemDeviceGet(server, 0, out device);
// Get handle of discrete input channel
if (rc == MAXT_SUCCESS)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_DIOFIFO_EH, 1, out moduleCount, module);
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_DISCRETE, MXF_SCLASS_RX_CHANNEL, 1, out channelCount, rx);
// Get handle of discrete output channel
if (rc == MAXT_SUCCESS)
rc = mxfModuleChannelAllGet(module[0], MXF_CLASS_DISCRETE, MXF_SCLASS_TX_CHANNEL, 1, out channelCount, tx);
// Sets all pin on the Multi module to 1 and reads the value to verify that it was actually set for about 10 seconds
Console.Write("Setting multi DIOs to 0xFF for 10 seconds. \n");
Console.Write("Unplug the LB at any time to provoke an error. \n");
for (i = 0; i < 10000 && rc == MAXT_SUCCESS; i++)
{
if (rc == MAXT_SUCCESS)
rc = mxfDiscreteChannelWrite(tx[0], 0xFF00, 0xFF00);
if (rc == MAXT_SUCCESS)
rc = mxfDiscreteChannelRead(rx[0], 0xFF00, out state);
if (state != 0xFF00)
Console.Write("DIOs on the multi module were not correctly set. \r\t");
}
Console.Write("\n Stopping.\n");
if (rc != MAXT_SUCCESS)
{
rc = mxfSystemErrorStringGet(server, rc, (UInt32)errorString.Length, errorString);
Console.WriteLine(errorString + "\n");
}
// Unload MX Foundation library
Console.Write("\nPress a key to terminate\n");
Console.ReadKey();
return;
}
private static UInt32 initHandler(UInt64 server, UInt64 deviceIndex, UInt64 moduleIndex, UInt64 channelIndex, UInt64 attrib, ref UInt64 value)
{
UInt64 device;
var deviceInfo = new MXF_DEVICE_INFO();
UInt32 rc;
// Sets all MXF_MODULE_MULTI_EH first TX and RX channels to DIOs
if (attrib == KMXF_CHANNEL_CLASS)
{
rc = mxfSystemDeviceGet(server, deviceIndex, out device);
if (rc == MAXT_SUCCESS)
rc = mxfDeviceInfoGet(device, out deviceInfo);
if (rc == MAXT_SUCCESS && (deviceInfo.modules[moduleIndex].type == MXF_MODULE_MULTI_EH))
{
value = MXF_CLASS_DISCRETE;
return 1;
}
}
return 0;
}
}
}
Updated 10/23/2023