result = F_OpenInstancesAndFPAs("*# FPA-1 20204004 TYPE-MSP FPA-2 20183001 TYPE-ARM")
The string passed to the initialization function specified the adapters and their types to be initialized. The type information is described in more detail in this article in the this wiki:
Generic DLL CLI: Getting Started
The below example, after initialization of the adapters, will load a different configuration file each adapter, perform AutoProgram, read the report message from each adapter (same as GUI), and finally offer the option to read current/voltage measurement values from a single adapter. The power measurement feature is for XStream-Iso and XStreamPro-Iso adapters only.
Imports System.Runtime.InteropServices Imports System.Text Module Module1 Const XS_ADC_NUM_MEMBERS As Integer = 15 Const DEFAULT_JTAG_3ST As Integer = 0 Const DEFAULT_RESET_3ST As Integer = 2 Const MODE_XS_IO_CLR_FLAGS As Integer = 19 Const IO_PULLUP_EN As Integer = 1 ' Function to build the message Function GetFullMessage() As String Dim message As New StringBuilder() Dim index As Integer = 0 Dim charByte As Byte ' Loop until we get the null-terminating character Do charByte = F_GetReportMessageChar(index) If charByte = 0 Then ' Null-terminating character Exit Do End If message.Append(Chr(charByte)) ' Append the character to the message index += 1 Loop ' Return the complete message Return message.ToString() End Function Sub ProcessADCData() ' Call initialization functions Dim response As Integer Dim data_block(XS_ADC_NUM_MEMBERS) As Double Dim data_block_ptr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Double)) * data_block.Length) Try ' Infinite loop to get power results and print them While True ' Call the F_Get_Power_Results function with the pointer response = F_Get_Power_Results(data_block_ptr) ' Print the values Console.WriteLine("ExtVcc= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 0 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Vcc= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 1 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Vpp= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 2 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" ExtVccMin= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 3 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" ExtVccMax= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 4 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" VccMin= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 5 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" VccMax= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 6 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Icc_mA= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 7 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Icc_mA_av4= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 8 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Icc_mA_av16= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 9 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Icc_mA_min= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 10 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Icc_mA_max= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 11 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Temperature= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 12 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Icc_mA_av64= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 13 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine(" Icc_mA_av= " & Marshal.PtrToStructure(Of Double)(data_block_ptr + 14 * Marshal.SizeOf(GetType(Double)))) Console.WriteLine() Console.WriteLine("Press any button to get another sample: ") Console.ReadLine() End While Catch ex As Exception Console.WriteLine("Exception: " & ex.Message) Finally ' Free the unmanaged memory Marshal.FreeHGlobal(data_block_ptr) End Try End Sub Sub Main() ' Open adapters - this binds adapter(s) to this application. ' Any adapters not opened here could potentially be opened by another application in parallel. Dim result As Integer ' result = F_OpenInstancesAndFPAs("FPAs-setup.ini") ' Read configuration from file result = F_OpenInstancesAndFPAs("*# FPA-1 20204004 TYPE-MSP FPA-2 20183001 TYPE-ARM") ' result = F_OpenInstancesAndFPAs("*# FPA-1 20171645 TYPE-MSP FPA-2 20210120 TYPE-ARM") ' Open two adapters over USB ' result = F_OpenInstancesAndFPAs("*# FPAETH-IP-1 192.168.0.101 TYPE-MSP FPAETH-IP-2 192.168.0.102 TYPE-ARM") ' Open two adapters over LAN (XStreamPro-Iso only) ' result = F_OpenInstancesAndFPAs("<path to FPAs-setup.ini file>") ' Read configuration from file ' Select adapter index for accepting commands result = F_Set_FPA_index(0) ' Select all opened adapters for sending commands ' result = F_Set_FPA_index(1) ' Select only adapter 1 for sending commands ' result = F_Set_FPA_index(2) ' Select only adapter 2 for sending commands result = F_Initialization() ' Initialize selected adapter(s) result = F_Set_FPA_index(1) 'MSP result = F_ConfigFileLoad("MSP430-F169.cfg") result = F_Set_FPA_index(2) 'ARM result = F_ConfigFileLoad("STM32H750VB-Issi-ext.cfg") ' Config file can be easily created in the GUI, or parameters can be set using F_Set_Config_Value_By_Name ' If the configuration file above already has a valid code path, the following function(s) is(are) not necessary ' result = F_ReadCodeFile("<path to code file>") ' Flush code buffer, read first code file. Can be used for *.hex, *.txt, *.srec, *.sxx etc. ' result = F_ReadCodeFile_BaseAddr("<path to code file>", baseAddr) ' Same as above but designed for *.bin files. Function will add baseAddr to code address. Can also be used to shift regular code files. ' result = F_AppendCodeFile("<path to code file>") ' Append code file, does not flush code buffer. ' result = F_AppendCodeFile_BaseAddr("<path to code file>", baseAddr) ' Same as F_ReadCodeFile_BaseAddr but used for appending ' Factory erase target (optional) ' result = F_Clear_Locked_Device() ' Erase, Blank Check, Write and Verify code programmed to target(s) result = F_Set_FPA_index(0) ' All adapters result = F_AutoProgram(0) Try ' Loop to set FPA index and retrieve messages Dim indices() As Integer = {1, 2} For Each index As Integer In indices result = F_Set_FPA_index(index) 'Dim messagePtr As IntPtr = F_Report_Message() 'Dim message As String = Marshal.PtrToStringAnsi(messagePtr) 'Console.WriteLine(message) 'Get message one character at a time Dim completeMessage As String = GetFullMessage() Console.WriteLine(completeMessage) Console.WriteLine("Press any button to get another message:") Console.ReadLine() Next Catch ex As Exception Console.WriteLine("Exception: " & ex.Message) End Try 'Get power samples result = F_Set_FPA_index(1) 'Select FPA 1 ProcessADCData() 'Measure current for MSP End Sub End Module
The target DLL in this case is the Generic-FPA.dll, however, the user can also target MSP430, ARM, M, 2000, CC, or iMOTION only by changing the referenced DLL in the GenericFPAModule.vb file:
Generic-FPA.dll (unified DLL for all API-DLL types)
MSP430FPA.dll, or GangPro430FPA.dll (DLL for FlashPro/GangPro-430 only)
FlashProARM-FPAsel.dll, or GangProARM-FPAsel.dll (DLL for FlashPro/GangPro-ARM only)
FlashProM-FPAsel.dll, or GangProM-FPAsel.dll (DLL for FlashPro/GangPro-M only)
FlashPro2000-FPAsel.dll (DLL for FlashPro-2000 only)
FlashProCC-FPAsel.dll, or GangProCC-FPAsel.dll (DLL for FlashPro/GangPro-CC only)
FlashProiMOTION-FPAsel.dll, or GangProiMOTION-FPAsel.dll (DLL for FlashPro/GangPro-iMOTION only)
The notable difference is that when using the Generic-FPA.dll, when specifying the adapter list, the extra TYPE-xxx strings are required. If targeting, the MSP430FPA.dll for example, the TYPE-MSP would be omitted.