Post Go back to editing

SS+ scripting from Python: How to read/write AD243x registers and I2C peripherals in main and subnodes

Category: Software
Product Number: SS+
Software Version: 2.2.0.2

Migrating some SS4.7 Python scripts to SS+ 2.2 and the new interface and I don't find any documentation or examples that illustrate how to interface from Python to actual hardware via SS+ like I did in SS4.7.

Have I overlooked an example or something that explains this?  I got  SigmaStudioPlus-Rel2.2.0\Examples\ScriptingClient\Python\PythonScripting.py to run so I can see how to get the environment set up from Python (can't say I understand it yet).

Specifically I'm looking to migrate the following types of things from SS4.7 to SS+:

EEPROM EXAMPLE

#  access the EEPROM peripheral, write and then read it
ic_name = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, "IC 1")

masterAddress = 0x68
busAddress = 0x69
chipAddress = 0x50
addrwidth = 2
# first we're going to write 0x00 to the 1st address
writeaddress =0x0000
writeNumberBytes = 1
writedata_ee = [0x00]

writedata_ee_v = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_BYREF | pythoncom.VT_UI1, writedata_ee)
stat = server.A2B_SLAVE_PERIREGISTER_WRITE(ic_name, masterAddress, busAddress, nodeID,
chipAddress, writeaddress, addrwidth, writeNumberBytes, writedata_ee_v)
...
readAddress = 0x0000
readNumberBytes = 1
readdata_ee = []
readdata_ee_v = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_BYREF | pythoncom.VT_UI1, readdata_ee)

stat = server.A2B_SLAVE_PERIREGISTER_READ(ic_name, masterAddress, busAddress, nodeID,
chipAddress, readAddress, addrwidth, readNumberBytes, readdata_ee_v)

AD24xx GPIO EXAMPLE
#GPIO_Bits is a bit mask (8 bits) for which GPIO to enable
#nodeID is the sequential (sub) node number, i.e. 0 to N
def GPIOSet(nodeID, GPIO_Bits):

ic_name = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, "IC 1")
masterAddress = 0x68
busAddress = 0x69
writedata = [GPIO_Bits]

writedata_v = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_BYREF | pythoncom.VT_UI1, writedata)
stat = server.A2B_SLAVE_REGISTER_WRITE(ic_name, masterAddress, busAddress, nodeID, GPIO_ADDR, 1, writedata_v)
return stat

ROOT NODE READ EXAMPLE
ic_name = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, "IC 1")
readdata = []
readdata_v = VARIANT( pythoncom.VT_ARRAY | pythoncom.VT_BYREF | pythoncom.VT_UI1, readdata)
stat = server.A2B_MASTER_REGISTER_READ(ic_name, 0x68, 0x02, 1, readdata_v)
I looked at a2b.thrift and could make a WAG that ReadWritePacket might have something to do with it along with PeripheralReadWrite() from SdkScripting.Thrift but there's no info I can find about them.

This is part of a hardware test environment that is migrating from AD242x to AD243x. Specifically need this to work with AD2433 and AD2437 devices.

Thanks,

Brewster


tried to fix the funky formatting, seems to be a bug in whatever the forum software is.
[edited by: Brewster at 3:09 AM (GMT -4) on 22 Jun 2024]
  • Thank you for your question. I am reviewing the information you provided and may come back with follow up questions. I appreciate your patience as I work on your query. 

  • Hi Arun,

    Sure, let me know what other information you might need.  I have a similar question in the SS+ forum for a non A2B use case.

  • we have connected you internally

  • A little self followup:
    This isn't quite all settled down yet; you need to use an older Thrift 12 release to build the libraries as the latest breaks things. ADI has indicated when it's released they'll have support for the current Thrift release.

    Read over: https://wiki.analog.com/resources/tools-software/a2bv2/quickstartguide/thriftuserguide

    Create the .py files with something like:
    .\thrift-0.12.0.exe -r --gen py SdkScripting.Thrift
    .\thrift-0.12.0.exe -r --gen py a2b.Thrift

    Here's some code snippets, you might need different things:
    Library loading:
    try:
        from thrift.transport import TSocket
        from thrift.protocol import TBinaryProtocol
        from thrift.transport import TTransport

    except:
        import pip
        pip.main(['install', 'thrift'])
        from thrift.transport import TSocket
        from thrift.protocol import TBinaryProtocol
        from thrift.transport import TTransport

    import time
    from SdkScripting.SdkScripting import Client
    from SdkScripting.ttypes import Position
    from SdkScripting.ttypes import Size
    from a2b.ttypes import *
    import os

    Here's an example of reading and writing EEPROM. node UID is the thing that SS+ calls it, which is problematic as you edit in SS+ these will change around, i.e. they're not referenced to an particular order of nodes.  For EEPROM this would be something like GenericDevices_#:

    def EEPROM_write(nodeUID, addr, data):
    pkt = ReadWritePacket()
    pkt.DevAddr =0x50 # all of our HW is at default addr
    pkt.AddrWidth = 2
    pkt.Addr = addr
    pkt.DataWidth = 1
    pkt.Data = data
    pkt.PeriWrite = True
    pkt.Data = client.PeripheralReadWrite(nodeUID, pkt)
    return True

    def EEPROM_read(nodeUID, addr):
    pkt = ReadWritePacket()
    pkt.DevAddr =0x50 # all of our HW is at default addr
    pkt.AddrWidth = 2
    pkt.Addr = addr
    pkt.DataWidth = 1
    pkt.PeriWrite = False
    pkt.Data = client.PeripheralReadWrite(nodeUID, pkt)
    return pkt.Data

    An example of setting GPIO in the A2B part:

    GPIO_ADDR = 0x4A

    def GPIOSet(nodeID, GPIO_Ctrl_Address,  GPIO_Bits):
        RegAddrValGPIO = RegAddrValPair()
        RegAddrValGPIO.RegAddr = GPIO_Ctrl_Address
        RegAddrValGPIO.RegVal = GPIO_Bits

        ssp_result = client.SetRegValue(nodeID, RegAddrValGPIO)
        return ssp_result