labjack-ljm-python icon indicating copy to clipboard operation
labjack-ljm-python copied to clipboard

add example for DAC0/1

Open stefan894 opened this issue 1 year ago • 3 comments

would be nice if labjack would also provide an example for DAC0/1, as this is not the case, I did one on my own. Published here as help for others

under Labjack T7 I got DAC0/1 working with this example:

from labjack import ljm

print(ljm.__version__)


class labjack_T7_dac:

      def __init__(self):
          # Open Labjack T7 device, Any connection, Any identifier
          self.handle = ljm.openS("T7", "ANY", "ANY")


      def write_dac(self, dac0: float = 0, dac1: float = 0):
          if (0 <= dac0 <= 5.0) and (0 <= dac1 <= 5.0):
              self.aDAC = ["DAC0", "DAC1"]
              self.aValueDAC = [dac0, dac1]
              self.numFrames = len(self.aDAC)
              ljm.eWriteNames(self.handle, self.numFrames, self.aDAC, self.aValueDAC)
          else:
              print("DAC values out of range")


      def close(self):
          ljm.close(self.handle)


      def main(self):
          self.write_dac(5.0,1.2)
          self.close()


if __name__ == '__main__':
  c = labjack_T7_dac()
  c.main()

stefan894 avatar Dec 13 '24 08:12 stefan894

The DACs are one of the easiest features to use. There is no configuration, just write to the register. We provide examples like eWriteName.py and eWriteNames.py to demonstrate generally how to write registers. They also both set a DAC.

I am worried that our documentation was not sufficient. Was DAC usage not clear?

davelopez01 avatar Dec 18 '24 22:12 davelopez01

Hi Davel,

As there was an example for ADC, I was also expecting an example for DAC..

As you see, I was able to figure it out and provided the example here, so that others just can use it, without going through documentation ;-)

stefan894 avatar Dec 19 '24 07:12 stefan894

Thanks for bringing this to our attention. I will look into adding a DAC example that supports all T-series devices.

davelopez01 avatar Dec 20 '24 21:12 davelopez01

We have added a DAC example to the master branch:

single_dac.py

davelopez01 avatar Apr 24 '25 21:04 davelopez01