MX Foundation 4
discrete.c
/******************************************************************************
//
// File:
// discrete.c
//
// Copyright (c) MAX Technologies Inc. 1988-2015, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates how to read discrete input and to write to
// discrete output using direct access.
//
// Hardware requirements:
// - MAXT Flex.
//
*******************************************************************************/
#include "example.h"
#define LOCAL
int main(void)
{
uint32 rc;
uint64 deviceCount;
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;
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
// Initialize MX Foundation library
if(!rc)
{
printf("Starting ...\n");
rc = mxfSystemInit(server);
}
// Get handle of discrete input channel
if(!rc)
rc = mxfSystemDeviceAllGet(server, MXF_DEVICE_ALL, 1, &deviceCount, &device);
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);
// Read value of input pin #1 and set it to output pin #2 for about 10 seconds
for(i=0; i < 10000 && !rc; i++)
{
rc = mxfDiscreteChannelRead(rx, 0x02, &state);
state<<=1; // to be aligned with mask 0x04
if(!rc)
rc = mxfDiscreteChannelWrite(tx, 0x04, state);
}
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;
}
Updated 10/23/2023