analogdevicesinc / pyadi-iio

Python interfaces for ADI hardware with IIO drivers (aka peyote)
https://analogdevicesinc.github.io/pyadi-iio
Other
146 stars 106 forks source link

ad7606. Channel 0 for Timestamp #602

Open Miavu87 opened 1 month ago

Miavu87 commented 1 month ago

Hello, I am new to a development with AD7606 and I am trying to run the example given in the repository: "pyadi-iio/examples /ad7606.py".

The example shows an error on the line "sc = ad7606.scale_available" because it tries to read the data from channel 0.

In my device, it assigns channel 0 to the Timestamp:

        IIO context has 2 devices:
                iio:device0: ad7606-8
                        9 channels found: 
                                timestamp:  (input)
                                voltage0:  (input)
                                3 channel-specific attributes found: 
  ...

On the other hand, if I run iio_info the channel Timestamp is number 8.

      IIO context has 2 devices:
              iio:device0: ad7606-8 (buffer capable)
                      9 channels found:
                              voltage0:  (input, index: 0, format: le:S16/16>>0)
                              3 channel-specific attributes found:
                                      attr  0: raw value: 32767
      ....

I fixed everything by making a new file "ad7606.py" and changing the line:

          @property
          def scale_available(self):
              """Provides all available scale settings for the AD7606 channels"""
              return self._get_iio_attr(self.channel[0].name, "scale_available", False)

Along the line:

        @property
        def scale_available(self):
            """Provides all available scale settings for the AD7606 channels"""
            return self._get_iio_attr(self.channel[0].name, "scale_available", False)

Is this the only solution?

THANK YOU!!

Miavu87 commented 1 month ago

Sorry, the solution is: return self._get_iio_attr(self.channel[1].name, "scale_available", False)`

tfcollins commented 1 month ago

Can you generate a context file for the device and provide it here? They can be created through use of the pytest-libiio module or with iio-emu.

Miavu87 commented 1 month ago

Hi, I have continued working with my device and having problems with Device Tree and Udev. At this moment, the device isn't created and therefore iio_info doesn't work for me.

As soon as I solve it I will send you what you requested.

Thank you.

Miavu87 commented 1 month ago

Hi, I was able to generate the XML file (attached): context_file.xml ==> The order of the channels is as expected.

I attach a file with the context from a Python script (with import iio): context_from_python.txt ==> Timestamp is channel 0

Thanks, Files_context.zip

tfcollins commented 1 month ago

I don't think you used the correct tool to generate the XML file. Note that you cannot use iio-genxml from libiio itself. This is different than the tools provided by iio-emu or pytest-libiio

Miavu87 commented 1 month ago

Hi, i attached the file generated with command "gen_xml --uri local: --xml generated.xml"

Seems to be OK, but in my IDE (VsCode) I can see channel 0 as Timestamp.

Thank you.

El mar, 1 oct 2024 a las 22:34, Travis F. Collins @.***>) escribió:

Can you generate a context file for the device and provide it here? They can be created through use of the pytest-libiio module https://tfcollins.github.io/pytest-libiio/master/cli_tools/ or with iio-emu https://github.com/analogdevicesinc/iio-emu/tree/main/tools.

— Reply to this email directly, view it on GitHub https://github.com/analogdevicesinc/pyadi-iio/issues/602#issuecomment-2387020678, or unsubscribe https://github.com/notifications/unsubscribe-auth/BLYI3TADWK4DICX7NLVQIX3ZZMBMPAVCNFSM6AAAAABPGDW6B6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBXGAZDANRXHA . You are receiving this because you authored the thread.Message ID: @.***>

tfcollins commented 1 month ago

In your file you can see the log messages:

XML generated:

<?xml ...

Context re-creation from generated XML succeeded!

Those surrounding log messages (not xml data) only come from iio-genxml. See here https://github.com/analogdevicesinc/libiio/blob/main/utils/iio_genxml.c#L99 . The issue with using iio-genxml (not gen_xml) is that it doesn't retrieve values from the context which are required for baseline emulation

Miavu87 commented 1 month ago

Hi, I'm sorry but I don't know how to get the XML file from pytest-libiio or iio-emu.

Could you send me an example?

Thanks again.

tfcollins commented 1 month ago

Can you generate a context file for the device and provide it here? They can be created through use of the pytest-libiio module or with iio-emu.

I detailed this here with these tools

Miavu87 commented 1 month ago

Hello, I'm sorry but I am absolutely unable to compile ios-emu. I have tried thousands of things and thousands of tests.

If you like, we'll drop the matter.

Thanks for everything.