MX Foundation 4
discrete_Multi.c
/******************************************************************************
//
// File:
// discrete_Multi.c
//
// Copyright (c) MAX Technologies Inc. 1988-2017, 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)
//
*******************************************************************************/
#include "example.h"
uint32 initHandler(HMXF_SERVER server, uint64 deviceIndex, uint64 moduleIndex, uint64 channelIndex, uint64 attrib, uint64* value);
// #define LOCAL
int main(void)
{
uint32 rc;
uint64 moduleCount;
uint64 channelCount;
HMXF_SERVER server;
HMXF_DEVICE device=0;
HMXF_MODULE module=0;
HMXF_CHANNEL rx=0;
HMXF_CHANNEL tx=0;
uint64 i;
uint64 state=0;
char errorString[200];
// Connect to services and initialize environment
#ifdef LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", FALSE, &server);
#endif
// Initializes init callback handler to set all TX and RX channels to DIOs on the multi module
if (!rc)
rc = mxfSystemInitAttributeUint64CallbackHandler(server, &initHandler);
// Initialize MX Foundation library
if(!rc)
{
printf("Starting ...\n");
rc = mxfSystemInit(server);
}
// Get handle of device
if (!rc)
rc = mxfSystemDeviceGet(server, 0, &device);
// Get handle of discrete input channel
if(!rc)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_DIOFIFO_EH, 1, &moduleCount, &module);
if(!rc)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_DISCRETE, MXF_SCLASS_RX_CHANNEL, 1, &channelCount, &rx);
// Get handle of discrete output channel
if(!rc)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_DISCRETE, MXF_SCLASS_TX_CHANNEL, 1, &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
printf("Setting multi DIOs to 0xFF for 10 seconds. \n");
printf("Unplug the LB at any time to provoke an error. \n");
for(i=0; i < 10000 && !rc; i++)
{
if(!rc)
rc = mxfDiscreteChannelWrite(tx, 0xFF00, 0xFF00);
if(!rc)
rc = mxfDiscreteChannelRead(rx, 0xFF00, &state);
if(state != 0xFF00)
printf("DIOs on the multi module were not correctly set. \r\t");
}
printf("\n Stopping.\n");
if(rc)
{
if(mxfSystemErrorStringGet(server, rc, sizeof(errorString), errorString))
sprintf (errorString,"ERROR # 0x%08X", rc);
printf("%s\n\r", errorString);
}
// Unload MX Foundation library
printf("\nPress a key to terminate\n");
getchar();
return rc;
}
uint32 initHandler(HMXF_SERVER server, uint64 deviceIndex, uint64 moduleIndex, uint64 channelIndex, uint64 attrib, uint64* value)
{
HMXF_DEVICE device;
MXF_DEVICE_INFO deviceInfo;
uint32 rc;
channelIndex=channelIndex;
// Sets all MXF_MODULE_MULTI_EH first TX and RX channels to DIOs
if(attrib == KMXF_CHANNEL_CLASS)
{
rc = mxfSystemDeviceGet(server, deviceIndex, &device);
if(!rc)
rc = mxfDeviceInfoGet(device, &deviceInfo);
if(!rc && (deviceInfo.modules[moduleIndex].type == MXF_MODULE_MULTI_EH))
{
*value = MXF_CLASS_DISCRETE;
return TRUE;
}
}
return FALSE;
}
Updated 10/23/2023