« Close

Datasheets and User Guides

App Notes

Software & Driver


2.8.1 - Feedback Functions


The low-level Feedback functions LJM_AddressesToMBFB, LJM_MBFBComm, and LJM_UpdateValues may be used together or separately to perform Modbus Feedback (MBFB) operations on the LabJack device.

Want Something Simpler?

For simpler functions that do the same thing as the low-level Feedback functions, see the Single Value Functions or the Multiple Value Functions.


[C/C++] Write to DAC0, read from AIN0 using LJM_AddressesToMBFB, LJM_MBFBComm, and LJM_UpdateValues

 * Name: stepwise_feedback.c
 * Desc: Shows how to read from a few analog inputs
 *       using a LabJack and the cross platform LabJackM
 *       Library using the C-style API

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <LabJackM.h>

#include "LJM_Utilities.h"

int main()
  int handle, err;

  // Just something that isn't positive so we know
  // errAddress has or hasn't been modified
  int errAddress = -2;

  // Set up the data
  enum { NUM_FRAMES = 2 };
  int numFrames = NUM_FRAMES;

    {"DAC0", "AIN0"};
  const double VALUE_0 = 1.23;
  const double VALUE_1 = 0.0;

  int aAddresses[NUM_FRAMES];
  int     aTypes[NUM_FRAMES];
  int    aWrites[NUM_FRAMES] = {LJM_WRITE, LJM_READ };
  int aNumValues[NUM_FRAMES] = {1,         1        };

  enum { NUM_VALUES = 2 };
  double aValues[NUM_VALUES] = {VALUE_0,   VALUE_1  };


  unsigned char UnitID = LJM_DEFAULT_UNIT_ID;

  // Fill out aAddresses
    aAddresses, aTypes);
  ErrorCheck(err, "LJM_NamesToAddresses");

  // Open first found LabJack
  err = LJM_Open(LJM_dtANY, LJM_ctANY, "LJM_idANY", &handle);
  ErrorCheck(err, "LJM_Open");


  err = LJM_AddressesToMBFB(MaxBytesPerMBFB, aAddresses,
    aTypes, aWrites, aNumValues, aValues, &numFrames,
  ErrorCheck(err, "LJM_AddressesToMBFB");

  printf("\nLJM_MBFBComm will overwrite the Transaction ID and Unit ID of the following command\n");
  PrintFeedbackCommand(aMBFB, "Feedback command");

  // Send the command and receive the response
  err = LJM_MBFBComm(handle, UnitID, aMBFB, &errAddress);
  ErrorCheckWithAddress(err, errAddress, "LJM_MBFBComm");

  PrintFeedbackResponse(aMBFB, "Feedback response");

  // Get the data back in a readable form
  err = LJM_UpdateValues(aMBFB, aTypes, aWrites,
    aNumValues, numFrames, aValues);
  ErrorCheck(err, "LJM_UpdateValues");

  // Print results
  printf("%s: %f\n", ADDRESS_STRINGS[1], aValues[1]);

  // Close
  err = LJM_Close(handle);
  ErrorCheck(err, "LJM_Close");


  return LJME_NOERROR;

Possible output:

deviceType: LJM_dtT7
connectionType: LJM_ctUSB
serialNumber: 470010117
pipe: 0
The maximum number of bytes you can send to or receive from this device in one packet is 64 bytes.

LJM_MBFBComm will overwrite the Transaction ID and Unit ID of the following command
Feedback command:
Header: 0x00 0x00 0x00 0x00 0x00 0x0e 0x01 0x4c
frame 00: 0x01 0x03 0xe8 0x02 0x3f 0x9d 0x70 0xa4
frame 01: 0x00 0x00 0x00 0x02
Feedback response:
Header: 0x01 0x89 0x00 0x00 0x00 0x06 0x01 0x4c
data: 0x40 0x9a 0xfd 0x5f
AIN0: 4.843429

The above example is available on the C/C++ Examples page.