|
| 1 | +# Copyright (C) 2025 Analog Devices, Inc. |
| 2 | +# |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without modification, |
| 6 | +# are permitted provided that the following conditions are met: |
| 7 | +# - Redistributions of source code must retain the above copyright |
| 8 | +# notice, this list of conditions and the following disclaimer. |
| 9 | +# - Redistributions in binary form must reproduce the above copyright |
| 10 | +# notice, this list of conditions and the following disclaimer in |
| 11 | +# the documentation and/or other materials provided with the |
| 12 | +# distribution. |
| 13 | +# - Neither the name of Analog Devices, Inc. nor the names of its |
| 14 | +# contributors may be used to endorse or promote products derived |
| 15 | +# from this software without specific prior written permission. |
| 16 | +# - The use of this software may or may not infringe the patent rights |
| 17 | +# of one or more patent holders. This license does not release you |
| 18 | +# from the requirement that you obtain separate licenses from these |
| 19 | +# patent holders to use this software. |
| 20 | +# - Use of the software either in source or binary form, must be run |
| 21 | +# on or directly connected to an Analog Devices Inc. component. |
| 22 | +# |
| 23 | +# THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 24 | +# INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A |
| 25 | +# PARTICULAR PURPOSE ARE DISCLAIMED. |
| 26 | +# |
| 27 | +# IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 28 | +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY |
| 29 | +# RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 30 | +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 31 | +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 32 | +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | + |
| 34 | +import argparse |
| 35 | + |
| 36 | +import numpy as np |
| 37 | + |
| 38 | +from adi.ad7091rx import ad7091rx |
| 39 | + |
| 40 | + |
| 41 | +def main(): |
| 42 | + # Set up argument parser |
| 43 | + parser = argparse.ArgumentParser(description="AD7091R Example Script") |
| 44 | + parser.add_argument( |
| 45 | + "--uri", |
| 46 | + type=str, |
| 47 | + help="The URI for the AD7091R device", |
| 48 | + default="serial:COM7,230400,8n1", |
| 49 | + ) |
| 50 | + parser.add_argument( |
| 51 | + "--device_name", |
| 52 | + type=str, |
| 53 | + choices=["ad7091r-2", "ad7091r-4", "ad7091r-8"], |
| 54 | + help="The device name (Supported devices are ad7091r-2, ad7091r-4, ad7091r-8)", |
| 55 | + default="ad7091r-8", |
| 56 | + ) |
| 57 | + |
| 58 | + # Parse arguments |
| 59 | + args = parser.parse_args() |
| 60 | + |
| 61 | + # Set up AD7091R device |
| 62 | + ad7091r_dev = ad7091rx(uri=args.uri, device_name=args.device_name) |
| 63 | + |
| 64 | + # Get ADC channel 0 raw value and print it |
| 65 | + raw = ad7091r_dev.channel[0].raw |
| 66 | + print(f"Raw value read from channel0 is {raw}") |
| 67 | + |
| 68 | + # Capture a buffer of 100 samples from channel 0 and display them |
| 69 | + chn = 0 |
| 70 | + ad7091r_dev._rx_data_type = np.int32 |
| 71 | + ad7091r_dev.rx_output_type = "raw" |
| 72 | + ad7091r_dev.rx_enabled_channels = [chn] |
| 73 | + ad7091r_dev.rx_buffer_size = 100 |
| 74 | + |
| 75 | + data = ad7091r_dev.rx() |
| 76 | + |
| 77 | + print(data) |
| 78 | + |
| 79 | + |
| 80 | +if __name__ == "__main__": |
| 81 | + main() |
0 commit comments