Mini-Circuits® Programming Manual For the USB I/O Control Box Series 30/42012 Page 1 Contents Item Description Page 1 Overview………………………………………………………………………… 3 2 Operating in a Windows® Environment……….……………………………... 4 - 10 2.1 Software supported by ActiveX® and .NET Class Library……………… 5-6 2.2 DLL Structure (Functions & Properties)………………………………….. 7 - 10 2.3 Sample code……………………………………………………………....... 11 3 3.1 Operating in a Linux® Environment……….……………….…………………. Sample code……………………………………………………………....... 12 - 18 17 30/42012 Page 2 1- Overview This programming Manual is intended for customers wishing to create their own interface for MiniCircuits' USB I/O Control Boxes. Mini-Circuits offers support for USB Portable Test Equipment (PTE) in Windows® and Linux® Operating Systems, in a variety of programming environments including third-party applications such as LabVIEW® and MATLAB® through .NET assembly and ActiveX® Controls to write your own customized control applications. Mini-Circuits' CD package Includes: GUI program installation, DLL Objects 32/64 bit, Linux Support, project examples for 3RD party software and Documents. The latest CD version is available for download at http://www.minicircuits.com/support/software_download.html , see Figure 1. Figure 1 – Download Screen 30/42012 Page 3 2 - Operating in a Windows® Environment 32/64Bits OS with USB HID Support The DLL Object (Dynamic Link Library) - Concept: Dynamic Link Library is Microsoft's implementation of the shared library concept in the Microsoft Windows® environment. DLLs provide a mechanism for shared code and data, allowing a developer of shared code/data to upgrade functionality without requiring applications to be re-linked or recompiled. Mini-Circuits' CD package provides DLL Objects in order to allow your own Software Application to interface with the functions of the Mini-Circuits' USB Portable Test Equipment hardware, see Figure 2. User's Software Application (3 RD Party Software Such as LabVIEW®, Delphi®, C++, C#, Visual Basic®, and .Net) DLL (Dynamic Link Libraries) Mini-Circuits' USB Portable Test Equipment hardware Figure 2 – DLL Interface Mini-Circuits' provides two DLLs files: 1. ActiveX® com object - mcl_USB_To_IO.dllÆ Click to download http://www.minicircuits.com/support/software_download.html ® ActiveX com object can be used in any programming environment that supports ActiveX® objects - third party COM (Component Object Model) compliant application. The ActiveX® DLL should be registered using RegSvr32 (see pages 5 and 6 - Register an ActiveX® DLL). 2. .NET Class Library - mcl_USB_To_IO64.dllÆ Click to download http://www.minicircuits.com/support/software_download.html .NET object – a logical unit of functionality that runs under the control of the .NET 30/42012 Page 4 2.1 - Software supported by ActiveX® and .NET Class Library mcl_USB_To_IO.dll - ActiveX® com object Instructions mcl_USB_To_IO64.dll - .NET Class Library Instructions For 32bit Windows OS, copy mcl_USB_To_IO.dll to windows\system32 folder For 32bit Windows OS copy mcl_USB_To_IO64.dll to windows\system32 folder For 64bit Windows OS, copy mcl_USB_To_IO.dll to windows\SysWOW64 folder For 64bit Windows OS copy mcl_USB_To_IO64.dll to windows\SysWOW64 folder Register the DLL, see instructions below DLL Registry is not required Visual Studio 6 (VC++,VB®) NI LabVIEW® 8.0 or newer MATLAB® 7 or newer Delphi® Borland C++ Agilent VEE® Python NI CVI NET (VC++, VB.net, C# 2003,2005,2008,2010) NI LabVIEW®_2009 or newer MATLAB® 2008 or newer Delphi® Borland C++ * Additional 3RD party software are supported, contact Mini-Circuits for details. How to register mcl_USB_To_IO.dll, 32-bit DLL, on a 32-bit Windows operating system? Open the Run Command from the Start Menu and type regsvr32 c:\windows\system32\mcl_USB_To_IO.dll Figure 3 – Run Command 30/42012 Page 5 How to register mcl_USB_To_IO.dll, 32-bit DLL on a 64-bit Windows operating system? Run the Command Prompt as Administrator, see figure 4 Figure 4 – Command Prompt Type regsvr32 c:\windows\syswow64\mcl_USB_To_IO.dll, see figure 5 Click Enter, see figure 6. Figure 5 – Type command Figure 6 – Registration succeeded 30/42012 Page 6 2.2 - DLL Structure (both mcl_USB_To_IO.dll and mcl_USB_To_IO64.dll) DLLs Functions mcl_USB_To_IO.dll / mcl_USB_To_IO64.dll 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. Int Connect(String SN) Void Disconnect() Int Get_Available_SN_List(String SN_List) Int GetStatus() Int Read_ModelName(String ModelName) Int Read_SN(String SN) Int Set_ByteA(Byte val) Int Set_ByteB(Byte val) Int Set_ByteA_As_Output() Int Set_ByteA_As_Input() Int Set_ByteB_As_Output() Int Set_ByteB_As_Input() Int Set_Relay(Int RelayNo , Int On_OFF) Int Set_RelayByte(Byte val) Int Set_TTLBit(String BitName, Int BitVal) Int Set_SPI_PulseWidth(Int PulsWidth) Int SPI_OUT(String ClockBit, String DataBit, String LEBit, String RegData) Int SPI_OUT_Trigg(String RegData, Int Trigger) Int GetByte(String ByteName, Byte ReturnedByteVal) Int Read_Relays_Byte(Byte RetVal ) Int ReadBit(String BitRequest, Byte Ret_BitVal ) Int ReadByteA(Byte Ret_ByteVal ) Int ReadByteB(Byte Ret_ByteVal ) Functions Description: 1. Int Connect (String SN) SN variable is only needed when more than one I/O Control Box is connected to the computer. SN is the variable that holds the Serial Number of the selected I/O Control Box and can be ignored if using only one box. To get the serial number of the Control box unit check the bottom of the unit or function #6 2. Void Disconnect() Close connection to the I/O Control Box . Shutting down the program without disconnecting the device may result in connection problem to the device. If you experience such problems shut down the program, then unplug the I/O Control Box from the computer and plug it back in before restarting the program. 3. Int Get_Available_SN_List(String SN_List) SN_List is a variable that will receive a list of the Serial Numbers of all I/O Control boxes connected to the computer (Each serial number is separated by a single space character): “SN1 SN2 SN3 SN4 ” 4. Int GetStatus() The function returns the connection status. The function returns ‘0’ if connection fails or a nonzero value for a valid connection. 5. Int Read_ModelName(String ModelName) ModelName is a variable that will receive the I/O Box Model Name. The function returns a non-zero value upon success. 30/42012 Page 7 6. Int Read_SN(String SN) SN variable contains the I/O Box Serial Number. The function returns a non-zero value upon success. 7. Int Set_ByteA(Byte Val) Set value of entire Byte A (A0 to A7) with Val. The function returns a non-zero value upon success. Val is a variable which contains the desired state of Byte A (A0=LSB, A7=MSB) 8. Int Set_ByteB(Byte Val) Set value of entire Byte B (B0 to B7) with Val. The function returns a non-zero value upon success. Val is a variable which contains the desired state of Byte B (A0=LSB, A7=MSB) 9. Int Set_ByteA_As_Output() This function changes the mode of Byte A from input to output. Note output is the default configuration. The function returns a non-zero value upon success. 10. Int Set_ByteA_As_Input() This function changes the mode of Byte A from output to input. Note output is the default configuration. The function returns a non-zero value upon success. 11. Int Set_ByteB_As_Output() This function changes the mode of Byte B from input to output. Note output is the default configuration. The function returns a non-zero value upon success. 12. Int Set_ByteB_As_Input() This function changes the mode of Byte B from output to input. Note output is the default configuration. The function returns a non-zero value upon success. 13. Int Set_Relay(Int RelayNo , Int On_OFF) RelayNo - The number of the relay to be set (from 0 to 7.( On_OFF - The state the relay should be set to (0 or 1) 1-Common to NO 0=Common to NC When used with model USB-I/O-4D2R this function turns the 24V outputs On (when set to 'Common to NO') or Off (when set to 'Common to NC'). Out1=Relay0, Out2=Relay1. The function returns a non-zero value upon success. 30/42012 Page 8 14. Int Set_RelayByte(Byte Val) Set the state of all the relays at once. Each bit signifies the state of a single relay (1-Common to No 0=Common to Nc). When used with USB-I/O-4D2R only the two LSB bits are checked and bits 2-7 and 'No Care,' The function returns a non-zero value upon success. Example: Set_RelayByte(25) will set relays 0,3 and 4 to 'Common to No' and all other relays to 'Common to Nc' 15. Int Set_TTLBit(String BitName, Int BitVal) BitName is a variable which holds the specific Bit to be set. BitName can be "A0","A1"..."A7" or "B0","B1"..."B7". ("A0", "A1", "A2" or "A3" only when used with USB-I/O-4D2R( BitVal is a variable which holds the state to which the bit should be set. BitVal can be either '1' to set the bit specified to high logic state or '0' to set the bit to logic low state . The function returns a non-zero value upon success. Example: Set_TTLBit("B3",1) Will set bit#3 of byte B to logic high state. 16. Int Set_SPI_PulseWidth(Int PulsWidth) PulsWidth is a variable which contains the desired SPI pulse width in µSec. The function sets the pulse width of Clock, Data and LE. PulsWidth can be any integer number from 0 to 255, if PulsWidth is 0 the actual pulse width will be 0.08µSec. The function returns a non-zero value upon success. Note: duty cycle remains constant while clock frequency changes when pulse width is changed. 17. Int SPI_OUT(String ClockBit, String DataBit, String LEBit, String RegData) The function sends SPI data using 3 selected bits. ClockBit, DataBit, LEBit, RegData are variables which each holds the name of a bit to use for a function of SPI communication: ClockBit is the bit used for the SPI clock DataBit is the bit used for the SPI data LEBit is the bit used for the SPI LE These variables can hold values "A0","A1"..."A7" or "B0","B1"..."B7." RegData is a variable which holds a string representing the binary value of the data to be sent. For example: a string of "0110011101" will transmit the data 0110011101 and the required start, stop and parity bits. The function returns a non-zero value upon success. 18. Int SPI_OUT_Trigg(String RegData, Int Trigger) The function sends SPI data with a trigger bit that will rise and fall together with LE. The function uses the following bits: B0 for Clock, B1 for Data, B2 for LE, and B3 for the trigger . RegData is a variable which holds a string which represents the binary value of the data to be sent. For example: a string of "0110011101" will transmit the data 0110011101 and the required start, stop and parity bits. Trigger is a variable which determines if a trigger bit is required. If a trigger bit is needed the variable should be '1' and '0' if it is not needed. The function returns a non-zero value upon success. 30/42012 Page 9 19. Int GetByte(String ByteName, Byte ReturnedByteVal) Function not available for USB-I/O-4D2R. The function reads the value of a specified digital byte (to read relay states see function 20). The selected byte must set as input. ByteName is a variable which contains the name of the requested byte i.e "A" for byte A, or "B" for byte B. ReturnedByteVal variable will receive the value of the byte read. The function returns a non-zero value upon success. Example: GetByte("B", RetVal) will read byte B and store the value in the variable RetVal . 20. Int Read_Relays_Byte(Byte RetVal) The function reads the current state of all eight relays and stores them in a single byte, with each bit signifying the state of a single relay (1=Common to No 0=Common to Nc ) . RetVal is a variable which will store the value of the relay states byte with Relay0=LSB, and Relay7=MSB. The function returns a non-zero value upon success. 21. Int ReadBit(String BitRequest, Byte Ret_BitVal) The function reads the value of a specified bit. BitRequest is a variable which contains the name of the specified bit. For example: if the value is "A5", the function will read the value of bit 5 of byte A. Ret_BitVal is the variable that will receive the value of the bit read ('1' or '0') Example: ReadBit("B0",RetBit) will read the value of the LSB bit of byte B and store the value in the RetBit variable. The function returns a non-zero value upon success. 22. Int ReadByteA(Byte Ret_ByteVal) The function is not usable with USB-I/O-4D2R units, and byte A must be set to Input for the function to work. The function reads the value of byte A. Ret_ByteVal is a variable which receives the value of byte A read. The function returns a non-zero value upon success. 23. Int ReadByteB(Byte Ret_ByteVal) The function is not usable with USB-I/O-4D2R units, and byte B must be set to Input for the function to work. The function reads the value of byte B. Ret_ByteVal is a variable which receives the value of byte B read. The function returns a non-zero value upon success. 30/42012 Page 10 2.3 - Sample code The CD package also includes a number of sample programs developed to show you how to write your own programs. The sample programs were developed in Visual C++®, Visual Basic®, C# and LabVIEW®. The sample programs provide an excellent starting point to write your own applications. The complete project examples are available for download at: http://www.minicircuits.com/support/software_download.html 30/42012 Page 11 3 - Operating in a Linux® Environment 32/64Bits OS with USB HID Support To open a connection to the USB I/O Control Box, Vendor ID and Product ID are required: Mini-Circuits Vendor ID is: 0x20CE USB I/O Control Box Product ID is: 0x21 The communication with the sensor is done by USB Interrupt. The transmitted and received buffer sizes are 64 Bytes. Transmit Array should be 64 bytes Receive Array contains 64 bytes [Byte 0][Byte1][Byte2]………[Byte 63] [Byte 0][Byte1][Byte2]………[Byte 63] Commands List: Command Code – Byte[0] # Description 1 Get Model Name 40 -- 2 Get Serial Number 41 -- 3 Set single relay (Sets status of a specific Relay 0-7) 34 Byte[1] - specific relay number (0 -7) Byte[2] – '1' or '0' 4 Set all relays (Set the state of all relays at once) 33 Byte[1] – Byte value 0 to 255 5 Set single TTL Bit Sets a specific bit to either '1' or '0' 32 Byte[1] - "A" or "B" ASCII value Byte[2] - bit number 0 - 7 Byte[3] – '1' or '0' 6 Set a TTL Byte 11 Byte[1] - "A" or "B" ASCII value Byte[2] – Byte value 0 to 255 7 Set Byte A to input state 24 -- 8 Set Byte A to output state 25 -- 9 Set Byte B to input state 26 -- 10 Set Byte B to output state 27 -- 11 Send SPI output 36 See page 15 37 See Page 15 Send SPI output with Trigger at LE 12 rise Set the Pulse Width of the SPI Data, Additional Transmitted Bytes Byte[1] – Pulse Width in µSec 13 Clock & LE signals 8 14 Get the value of a specific TTL bit 30 Byte[1] - "A" or "B" ASCII value Byte[2] - Bit Number 0 - 7 15 Get the value of a digital Byte 10 Byte[1] - "A" or "B" ASCII value See detailed description below 30/42012 Page 12 1. Get Model Name: To get the Model Name, send code number 40 Transmit Array Byte[0]=40 Bytes[1] through 63 are NC - Not Care Received Array The Model Name will be returned in the receive array of ASCII characters. End of Model Name is signified by a 0 value. Byte [0] 40 Byte [1] Byte[0]=40 Byte[1] to the byte before the 0 value = Part Number All bytes after the 0 value up to byte [63] contain random values Byte [2] Byte [3] Byte [4] Byte [5] Byte [6] Byte [N] 0 Byte [63] ASCII characters representing the Model Name 2. Get Serial Number To get the Serial Number, send code number 41 Transmit Array Byte[0]=41 Bytes[1] through 63 are NC - Not Care Received Array The Serial Number will be returned in the receive array of ASCII characters. End of S/N is signified by a 0 value. Byte [0] 41 Byte [1] Byte[0]=41 Byte[1] to the byte before the 0 value = Serial Number All bytes after the 0 value up to byte [63] contain random values Byte [2] Byte [3] Byte [4] Byte [5] Byte [6] Byte [N] 0 Byte [63] ASCII characters representing the Serial Number 30/42012 Page 13 3. Set single relay (Set status of a specific relay) Transmit Array Byte[0]=34 Byte[1]=Specific relay number 0 - 7 (0Æ for Relay0, 1Æ for Relay1, etc…) Byte[2]= 1: COM to Normally Open, 0: COM to Normally Closed Bytes[3] through 63 are NC - Not Care For USB-I/O-4D2R this command is used to turn on or off one of the 24V outputs with Out1 equivalent to Relay0, Out2 equivalent to Relay 1 and Byte[2]=1 turning on an output, Byte[2]=0 turning it off. Example: Transmit Array to Turn On Relay5 Byte [0] 34 Byte [1] 5 Byte [2] 1 Byte [63] Received Array Byte[0]=34 Bytes[1] through [63] contain random values 4. Set all relays (Set state of all relays at once) Transmit Array Byte[0]=33 Byte[1]=Byte Value 0 - 255 (0Æ All Relays 'Common to No', 255Æ All Relays 'Common to Nc') Bytes[2] through 63 are NC - Not Care For USB-I/O-4D2R this command is used to turn on or off both the 24V outputs with Out1 equivalent to Relay0, Out2 equivalent to Relay 1 and bits 2-7 being NC. '1' turns on an output and 0 turns it off. Example: Transmit Array to set Relay1 and Relay6 to 'Common to No' and all others to 'Common to Nc' 42= 01000010b Byte [0] 33 Byte [1] 42 Byte [63] Received Array Byte[0]=33 Bytes[1] through [63] contain random values 30/42012 Page 14 5. Set single TTL Bit (Sets a specific bit to either '1' or '0') Transmit Array Byte[0]=32 Byte[1]= ASCII value of "A" (65) if the bit is from Byte-A or ASCII value of "B" (66) if the bit is from Byte-B Byte[2]= Bit number from 0 to 7 Byte[3]= '1' for Logic High, '0' for Logic Low Bytes[4] through 63 are NC - Not Care For model USB-I/O-4D2R only byte B and bits 0-3 of byte B are available. Example: Transmit Array to set bit 2 or Byte B to '1' (Logic High) Byte[0]=32, Byte[1]= 66 (ASCII value of "B") , Byte[2]= 2 (Bit 2),Byte[3]= '1' for Logic High Received Array Byte[0]=32 Bytes[1] through [63] contain random values 6. Set a TTL Byte Transmit Array Byte[0]=11 Byte[1]= ASCII value of "A" (65) for Byte-A or the ASCII value of "B" (66) for Byte-B Byte[2]= 1Æ for Logic High, 0Æ for Logic Low Bytes[3] through 63 are NC - Not Care For model USB-I/O-4D2R only byte B and bits 0-3 of byte B are available Received Array Byte[0]=11 Bytes[1] through [63] contain random values 7. Set byte A to Input state (Input state is high impedance) Transmit Array Byte[0]=24 Bytes[1] through 63 are NC - Not Care This command is not available for USB-I/O-4D2R Received Array Byte[0]=24 Bytes[1] through [63] contain random values 30/42012 Page 15 8. Set byte A to Output state Transmit Array Byte[0]=25 Bytes[1] through 63 are NC - Not Care This command is not available for USB-I/O-4D2R Received Array Byte[0]=25 Bytes[1] through [63] contain random values 9. Set byte B to Input state (Input state is high impedance) Transmit Array Byte[0]=26 Bytes[1] through 63 are NC - Not Care This command is not available for USB-I/O-4D2R Received Array Byte[0]=26 Bytes[1] through [63] contain random values 10. Set byte B to Output state Transmit Array Byte[0]=27 Bytes[1] through 63 are NC - Not Care This command is not available for USB-I/O-4D2R Received Array Byte[0]=27 Bytes[1] through [63] contain random values 30/42012 Page 16 11. Send SPI output ( SPI: "Serial Peripheral Interface" using selected Clock ,Data and LE bits) Transmit Array Byte[0]=36 Byte[1]= ASCII value of "Clock" Byte request ( 65 for A or 66 for B ) Byte[2]= Bit Number for "Clock" ( 0 to 7 ) Byte[3]= ASCII value of "Data" Byte request ( 65 for A or 66 for B ) Byte[4]= Bit number for "Data" ( 0 to 7 ) Byte[5]= ASCII value of "LE" Byte request ( 65 for A or 66 for B ) Byte[6]= Bit number for "LE" ( 0 to 7 ) Byte[7] = N = the number of data bits to send (up to 48, not counting parity, start or stop bits) Byte[8] to Byte[N+7]= the data value to send = 1 or 0 Bytes [N+8] through 63 are NC - Not Care Example: To send SPI Out:"10010" using B0 as clock, B1 as Data and B2 as LE Byte [0] 36 Byte [1] 66 Byte [2] 0 Byte [3] 66 Byte [4] 1 Byte [5] 66 Byte [6] 2 Byte [7] 5 Byte [8] 1 Byte [9] 0 Byte [10] 0 Byte [11] 1 Byte [12] 0 Byte [63] Notes: 1. Bytes used need to be set as Output. 2. For USB-I/O-4D2R only bits 0-3 of Byte B are available Received Array Byte[0]=36 Bytes[1] through [63] contain random values 12. Send SPI output with Trigger at LE rise This command uses Byte B for SPI transmission as follows: B0 for Clock, B1 for Data, B2 for LE, B3 for Trigger. Insure Byte B is set to Output before running this command. Byte[0]=37 Byte[1]= N = the number of bits requested to send up to 48, not counting parity, start or stop bits) Byte[2]= 1 to enable Trigger, 0 to disable it Byte[3] to Byte[N+2]= the data values to be sent = 1 or 0 Other Bytes through 63 are NC - Not Care Example: To send SPI Out:"10010111" must use B0 as clock, B1 as Data, B2 as LE and B3 as Trigger Enable Received Array Byte[0]=37 Bytes[1] through [63] contain random values 30/42012 Page 17 13. Set the Pulse Width of the SPI Data, Clock, and LE signals Transmit Array Byte[0]=8 Byte[1]= Pulse Width in micro seconds (0 to 255). Bytes[2] through 63 are NC - Not Care Note: When Byte[1]=0 pulse width is 0.08 micro seconds. Received Array Byte[0]=8 Bytes[1] through [63] contain random values 14. Get the value of a specific TTL bit Transmit Array Byte[0]=30 Byte[1]= ASCII value of "A" (65) for Byte-A or the ASCII value of "B" (66) for Byte-B Byte[2]= Bit number ( 0 to 7 ) Bytes[3] through 63 are NC - Not Care This command is not available for USB-I/O-4D2R Received Array Byte[0]=30 Bytes[1] through [63] contain random values 15. Get the value of a digital Byte (either TTL of HV digital) Transmit Array Byte[0]=10 Byte[1]= ASCII value of "A" (65) for Byte-A or the ASCII value of "B" (66) for Byte-B Bytes[2] through 63 are NC - Not Care This command is not available for USB-I/O-4D2R Received Array Byte[0]=10 Bytes[2] through [63] contain random values 30/42012 Page 18 3.1 – Sample code The Linux Folder in the CD package contains the following: usb2IO.c example source code using the libhid & libusb libraries to open the USB HID device. The complete project samples are available on the CD or at: http://www.minicircuits.com/support/software_download.html Windows, Visual Basic and Visual C++ are registered trademarks of Microsoft Corporation. LabVIEW is a registered trademark of National Instruments Corp. Delphi is a registered trademark of Codegear LLC. MATLAB is a registered trademark of MathWorks, Inc. Agilent VEE is a registered trademark of Agilent. Neither MiniCircuits nor the Mini-Circuits USB I/O Control Boxes are affiliated with or endorsed by the owners of the above referenced trademarks. Mini-Circuits and the Mini-Circuits logo are registered trademarks of Scientific Components Corporation. 30/42012 Page 19