MX Foundation 4
flexdac.c
/*****************************************************************************
//
// File:
// flexdac.c
//
// Copyright (c) MAX Technologies Inc. 1988-2021, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the configuration of an FlexDAC module and perform
// basic transmission on five single-ended channels.
//
// Hardware requirements:
// - MAXT FlexMAX with FlexDAC module
//
*****************************************************************************/
#include "example.h"
#define MAX_ANALOG_CHN_NUM 5
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_DEVICE device=0;
HMXF_MODULE module=0;
HMXF_CHANNEL txChn[MAX_ANALOG_CHN_NUM];
HMXF_BUFFER txBuffer;
uint64 count=0;
int iPort;
// Connect to services and initialize environment
rc = mxfServerConnect("192.168.0.1", "admin", "admin", FALSE, &server);
if (rc != MAXT_SUCCESS)
{
printf("Failed to connect; rc=0x%08x", rc);
printf("\nPress a key to terminate\n");
getchar();
return 0;
}
// Initialize the server
printf("\nStarting\n");
rc = mxfSystemInit(server);
if(rc == MAXT_ERROR_ANOTHER_PROCESS_RUNNING)
rc = mxfSystemResourcesInit(server, 0);
// Get a handle to Analog FlexDAC channel #0, 4, 17, 18 and 63
if (!rc)
rc = mxfSystemDeviceAllGet(server, MXF_DEVICE_FLEXMAX, 1, &count, &device);
if(!rc && count)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_FLEXDAC, 1, &count, &module);
if(!rc && count)
{
rc = mxfModuleChannelGet(module, 0, &txChn[0]);
if(!rc)
rc = mxfModuleChannelGet(module, 4, &txChn[1]);
if (!rc)
rc = mxfModuleChannelGet(module, 17, &txChn[2]);
if (!rc)
rc = mxfModuleChannelGet(module, 18, &txChn[3]);
if (!rc)
rc = mxfModuleChannelGet(module, 63, &txChn[4]);
}
// If channel not found, return an error
if (!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
// Set time base
if(!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_USEC);
// Set the outut range to +/-10V single-ended
for (iPort=0; iPort<MAX_ANALOG_CHN_NUM && !rc; iPort++)
rc = mxfAttributeUint64Set(txChn[iPort], KMXF_FLEXDAC_CHN_OUTPUT_RANGE, VMXF_FLEXDAC_CHN_OUTPUT_RANGE_SE_BIPOLAR_10V);
// Set the channel selection to DAC #0, 4, 17, 18 and 63
if (!rc)
rc = mxfAttributeUint64Set(module, KMXF_FLEXDAC_MODULE_CHN_SELECTION, 0x8000000000060011ULL);
// Allocate TX aperiodic buffer
if(!rc)
rc = mxfTxAperiodicBufferAlloc(module, MXF_TXAPERIODIC_PRIORITY_NORMAL, sizeof(recANALOG), &txBuffer, NULL);
// Set output to +5.0V
if(!rc)
{
recANALOG.timeTag = 0;
recANALOG.control = 0;
recANALOG.repeatCount = 1;
recANALOG.reserved = 0;
recANALOG.dataSize = MAX_ANALOG_CHN_NUM*sizeof(uint16);
recANALOG.dataMask = 0x8000000000060011ULL;
for (iPort=0; iPort<MAX_ANALOG_CHN_NUM && !rc; iPort++)
{
rc = mxfFlexDacDataConvert(txChn[iPort], 5.0, &recANALOG.data[iPort]);
}
}
if(!rc)
rc = mxfFlexAnalogTxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_DEFAULT, 0, 1, &recANALOG);
if (rc)
{
char buffer[256];
if (mxfSystemErrorStringGet(server, rc, sizeof(buffer), buffer))
sprintf(buffer, "ERROR # 0x%08X", rc);
printf("%s\n\r", buffer);
}
printf("\nPress enter to terminate\n");
getchar();
// Terminate
return rc;
}
Updated 10/23/2023