MX Foundation 4
flexdio.c
/******************************************************************************
//
// File:
// flexdio.c
//
// Copyright (c) MAX Technologies Inc. 1988-2022, 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 FlexMAX with FlexMAX DIO module.
//
*******************************************************************************/
#include "example.h"
// #define LOCAL
int main(void)
{
uint32 rc;
uint64 deviceCount;
uint64 moduleCount=0;
uint64 channelCount=0;
HMXF_SERVER server;
HMXF_DEVICE device=0;
HMXF_MODULE module=0;
HMXF_CHANNEL io=0;
uint64 i;
uint64 state;
char errorString[200];
uint64 dev, mod, port;
// 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 channel
if(!rc)
rc = mxfSystemDeviceAllGet(server, MXF_DEVICE_FLEXMAX, 1, &deviceCount, &device);
if(!rc)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_FLEXDIO, 1, &moduleCount, &module);
if(!rc && moduleCount)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_ALL, MXF_SCLASS_ALL, 1, &channelCount, &io);
if (!rc && !channelCount)
rc = MAXT_ERROR_NOT_FOUND;
if (!rc)
{
rc = mxfChannelLocationGet(io, &dev, &mod, &port);
if (!rc)
printf("IO Channel location=%"PRIu64".%"PRIu64".%"PRIu64"\n", dev, mod, port);
}
// Configure pin #1 as input with pull-up
if(!rc)
rc = mxfFlexDIOModeSet(io, 1, MXF_FLEXDIO_MODE_IN_PULLUP);
// Configure pin #2 as output low-side
if(!rc)
rc = mxfFlexDIOModeSet(io, 2, MXF_FLEXDIO_MODE_OUT_LS);
// Read value of input pin #1 and set it inverted to output pin #2 for about 10 seconds
for(i=0; i < 10000 && !rc; i++)
{
rc = mxfFlexDIOChannelRead(io, 0x02, &state);
state<<=1; // to be aligned with mask 0x04
state = ~state;
if(!rc)
rc = mxfFlexDIOChannelWrite(io, 0x04, state);
if((i%125)==0)
printf(".");
}
printf("\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;
}
Updated 10/23/2023