Part Number: USB-TO-GPIO
Hello Anne Ngo77,
I wish to develop library API for USB-TO-GPIO using Python. I couldn't find any programming manual on TI website.
Can you share the programming manual, If you've?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: USB-TO-GPIO
Hello Anne Ngo77,
I wish to develop library API for USB-TO-GPIO using Python. I couldn't find any programming manual on TI website.
Can you share the programming manual, If you've?
I will check if we have any documentation. Please allow a few days.
We do not have any documentation available. There is an unsupported API on the web here, but what you see online is all we have.
https://www.ti.com/tool/FUSION_DIGITAL_POWER_API
Hello Matt Schurman,
Thank you for your reply. I was followed up your instruction from the C# sample code and I had written basic find and close device function in Python as shown below one. But It says no adapter found in the PC. Parallelly I was cross checked on device manager, if so there were no adapter connected with the PC(but it was connected an adapter with the PC).
Do I need to install any USB adapter driver/human interface device driver to get to detect an adapter on the device manager?
PC: Windows 10 Operating System (64-bit)
import clr # Import clr from pythonnet
clr.AddReference("C:\\Program Files (x86)\\Texas Instruments Fusion API\\Library\\TIDP.SAA.dll") # Load the dll file(C:\\ folder)
from TIDP.SAA import IAdapterDriverFactory # Import class from Our C# namespace
class USB_TO_GPIO(object):
def __init__(self):
self.adapter = '' # Create an object
def exception_handler(self, exception):
print("Exception occured:", exception)
def find_adapter(self):
try:
self.device = IAdapterDriverFactory.Discover()
return self.device
except Exception as ex:
self.exception_handler(ex)
def close(self):
try:
self.device.Dispose()
print("Device closed succesfully")
except Exception as ex:
self.exception_handler(ex)
a = USB_TO_GPIO()
print(a.find_adapter())
a.close()
Hello, As I said before, the Fusion API is not officially supported, so there is only limited guidance we can give here.
That being said, I've used a python class like below, to discover and transact with the SAA tool.
(This is python 3.x with the "pythonnet" module installed, in 2.7 you would need use a .NET compatible build like IronPython).
import clr
import System
import sys
import csv
sys.path.append("C:\Program Files (x86)\Texas Instruments Fusion API\Library")
import TIDP.SAA as SAA_API
class SAA:
def __init__(self):
'''Python SAA adapter constructor'''
if SAA_API.SMBusAdapter.Discover() == 0:
print("No SMBus Adapter Found");
exit()
self.SAA = SAA_API.SMBusAdapter.Adapters[0]
return None
def Write_Byte(self, dev_addr, cmd_addr, val):
'''Wrapper for SAA Write Byte Function, explicitly states which overload to use in Fusion API
Args:
(uint8) dev_addr = PMBus Slave Address (0-127)
(uint8) cmd_addr = PMBus CMD Address (0-255)
(uint8) val = Data Byte to Write (0-255)
Returns:
(bool) True if successful
(bool) False otherwise
'''
return (self.SAA.Write_Byte.Overloads[System.Byte, System.Byte, System.Byte](dev_addr, cmd_addr, val) == 0)
def Read_Byte(self, dev_addr, cmd_addr):
'''Wrapper for SAA Write Byte Function, explicitly states which overload to use in Fusion API
Args:
(uint8) dev_addr = PMBus Slave Address (0-127)
(uint8) cmd_addr = PMBus CMD Address (0-255)
Returns:
(uint8) Data Byte if successful
None otherwise
'''
ret = self.SAA.Read_Byte.Overloads[System.Byte, System.Byte](dev_addr, cmd_addr)
if ret.SAA_Status == 0:
return int(ret.Data.Hex, 16)
else:
return None
Hello Matt Schurman,
Finally as attached code is works for me and thank you for your support.
import clr # Import clr from 'pythonnet' to interface runtime engine with .net
from System import Byte
class USB_TO_GPIO(object):
def __init__(self):
""" SAA adapter constructor - discovering a device via the SMBus API.
This library file provides you with the information required to use functions for remotely controlling your instrument.
from usb-to-gpio import USB_TO_GPIO # Importing USB_TO_GPIO file
TI = USB_TO_GPIO() # Initialize & opens an instrument reference
TI.configure(pec_enabled=False) # Selects 100-KHz/400-KHz bus speed & PEC mode
TI.send_byte(dev_addr=0x001, cmd_addr=0x00) # Performs a “Send_Byte”
TI.write_byte(dev_addr=0x01, cmd_addr=0x00, data=0x00) # Performs a “Write_Byte”
TI.close() # Close the device reference
"""
try:
clr.AddReference("C:\\Program Files (x86)\\Texas Instruments Fusion API\\Library\\TIDP.SAA.dll") # Load the dll file(C:\\ folder)
import TIDP.SAA as API # Import TIDP.SAA dll file
if API.SMBusAdapter.Discover() != 0: # Find an adapter
self.device = API.SMBusAdapter.Adapter # Import class from C# namespace
print('Device has opened')
else:
print("No Adapter Found")
except:
import_error()
def __repr__(self):
''' print statement to compute the "informal" string representation of an object '''
return repr(self.device)
###########################################
# Error Handler
###########################################
def import_error(self):
''' Update import error reported by the system of loading dll driver error.
'''
print("dll file not loaded, 'TI USB-TO-GPIO driver was not present/installed'.")
exit()
def exception_handler(self, exception):
print("Exception occured:", exception)
###########################################
# SMBus Adapter
###########################################
def configure(self, pec_enabled=False):
''' Select 100-KHz/400-KHz bus speed & PEC mode'''
self.device.Set_Bus_Speed(self.device.BusSpeed.Speed100KHz)
self.device.Set_PEC_Enabled(pec_enabled)
def send_byte(self, dev_addr, cmd_addr):
'''
Wrapper for SAA Write Byte Function, explicitly states which overload to use in Fusion API
Args:
(uint8) dev_addr = PMBus Slave Address (0-127) - b'\x7F'
(uint8) cmd_addr = PMBus CMD Address (0-255) - b'\xFF'
Returns:
(bool) True if successful
(bool) False otherwise
'''
try:
if self.device.Send_Byte(Byte(dev_addr), Byte(cmd_addr)) == 0: # 0 = received acknowledgement
return 'Success'
except Exception as ex:
self.exception_handler(ex)
def write_byte(self, dev_addr, cmd_addr, data):
'''
Wrapper for SAA Write Byte Function, explicitly states which overload to use in Fusion API
Args:
(uint8) dev_addr = PMBus Slave Address (0-127) - b'\x7F'
(uint8) cmd_addr = PMBus CMD Address (0-255) - b'\xFF'
(uint8) data = Data Byte to Write (0-255) - b'\xFF'
Returns:
(bool) True if successful
(bool) False otherwise
'''
try:
if self.device.Write_Byte(Byte(dev_addr), Byte(cmd_addr), Byte(data)) == 0: # 0 = received acknowledgement
return 'Success'
except Exception as ex:
self.exception_handler(ex)
def read_byte(self, dev_addr, cmd_addr):
'''
Wrapper for SAA Write Byte Function, explicitly states which overload to use in Fusion API
Args:
(uint8) dev_addr = PMBus Slave Address (0-127) - b'\x7F'
(uint8) cmd_addr = PMBus CMD Address (0-255) - b'\xFF'
Returns:
(uint8) Data Byte if successful
NACK otherwise
'''
try:
status = self.device.Read_Byte(Byte(dev_addr), Byte(cmd_addr))
if status.SAA_Status == 'ACK':
return int(status.Data.Hex, base=16)
else:
return 'NACK'
except Exception as ex:
self.exception_handler(ex)
def i2c_write(self, byteaddr=0x70, bytecmd=0x04, bytedata=[0x00]):
'''
Wrapper for SAA Write Byte Function, explicitly states which overload to use in Fusion API
Args:
(uint8) dev_addr = PMBus Slave Address (0-127) - b'\x7F'
(uint8) cmd_addr = PMBus CMD Address (0-255) - b'\xFF'
(uint8) data = Data Byte to Write (0-255) - b'\xFF'
Returns:
(uint8) Data Byte if successful
NACK otherwise
'''
try:
if self.device.I2C_Write(Byte(byteaddr), Byte(bytecmd), bytes(bytedata)) == 0:
return 'Success'
except Exception as ex:
self.exception_handler(ex)
def close(self):
try:
self.device.Dispose()
print('Device has closed')
except Exception as ex:
self.exception_handler(ex)