There are a few different methods for developing a LabVIEW application that can communicate to a Galil motor controller.
1 - Not recommended for new Applications. DMCWin32 Library and Galil developed VI's. This method is simple, but limited support is offered beyond the vi's that are provided on the Galil software CD.
2 - Not recommended for new Applications. Active X Toolkit. This method has been the preferred method for any existing applications with LabVIEW and Galil motor controllers. It requires the purchase of the Active X Toolkit for $595. Details on using the Active X Toolkit with LabVIEW are covered in application note 4414. http://www.galil.com/download/application-note/note4414.pdf
3 - Recommended Method. GalilTools Communication Library. Using the GalilTools Communication Library is the recommended method for any new applications that are being developed with LabVIEW. This post will review 2 examples. The first covers basics of how to integrate the GalilTools Communication Library into a LabVIEW application. The second covers the more advanced function of integrating COM events into a LabVIEW application.
The GalilTools Communication Library (Galil class) provides methods for communication with a Galil motion controller over Ethernet, RS-232 or PCI buses. It consists of a native C++ Library and a similar COM interface which extends compatibility to Windows programming languages (e.g. VB, C#, etc).
---C++ Library (Windows and Linux)---
Both Full and Lite versions of GalilTools ship with a native C++ communication library. The Linux version (libGalil.so) is compatible with g++ and the Windows version (Galil1.dll) with Visual C++ 2008.
---COM (Windows)---
To further extend the language compatibility on Windows, a COM (Component Object Model) class built on top of the C++ library is also provided with Windows releases. This COM wrapper can be used in any language and IDE supporting COM (Visual Studio 2005, 2008, etc). The COM wrapper includes all of the functionality of the base C++ class.
---Using the COM class with Labview---
Working vi's of the below examples, as well as other vi's can be found in the LabVIEW Hello Galil example.
http://www.galil.com/learn/api-examples
1 - make sure GalilTools version 1.3.0.0 or later is installed on the PC. The free version of GalilTools contains the Communication Library, so no software purchase is required.
http://www.galil.com/downloads/software
(2) - Open National Instruments Labview Version 8.6. Versions 8.0, 8.2 and 8.5 were also tested. Later versions should be compatible as well.
select "Blank VI".
(3) From the File menu choose "Save As" ('File/Save As') and name the file Galil.
(4) Choose 'Window/Show Block Diagram'.
(5) In the Functions Palette ('View/Functions Palette'), expand "Connectivity" then "ActiveX".
(5a) Drop the "Automation Open" function onto Galil.vi Block Diagram.
(6) Right-clink on the Automation Open function and choose 'Select ActiveX Class/Browse'. (This may take a moment)
(6a) In the drop down box choose "Galil Version x.x" (n.n is the version number, ex Galil Version 0.3). Highlight the Galil Object, click OK.
-Recommended for beginners to Labview- Right click on the Automation Open function, choose 'Visible Items/Label'. This can be done with most labview blocks/functions.
(7) Drop a "Property Node" (Functions Palette/Connectivity/ActiveX) onto the Block Diagram to the right of the Automation Open function.
(7a) Connect the "Automation Refnum" terminal of the Automation Open funtion to the "reference" terminal on the Property Node. (The text of the Property Node should change to "IGalil" from "Automation".)
(7b) Left-click on the Property element of the Property Node and choose 'address'.
(7c) Right-clink on the Property element of the Property Node and choose 'Change to Write'.
(8) Drop an "Invoke Node" (Functions Palette/Connectivity/ActiveX) onto the Block Diagram to the right of the Property Node.
(8a) Connect the "reference out" terminal of the Property Node (top right terminal, mouseover will show Galil.IGalil) to the "reference" terminal of the Invoke Node. (The text of the Invoke Node should change to "IGalil" from "Automation".)
(8b) Left-click on the Method element of the Invoke Node and choose 'connection'.
(9) Drop an "Invoke Node" (Functions Palette/Connectivity/ActiveX) onto the Block Diagram to the right of the Invoke Node.
(9a) Connect the "reference out" terminal of the last Invoke Node (top right terminal, mouseover will show Galil.IGalil) to the "reference" terminal of the Invoke Node. (The text of the Invoke Node should change to "IGalil" from "Automation".)
(9b) Left-click on the Method element of the Invoke Node and choose 'libraryVersion'.
(10) Drop an "Invoke Node" (Functions Palette/Connectivity/ActiveX) onto the Block Diagram to the right of the Invoke Node.
(10a) Connect the "reference out" terminal of the last Invoke Node (top right terminal, mouseover will show Galil.IGalil) to the "reference" terminal of the Invoke Node. (The text of the Invoke Node should change to "IGalil" from "Automation".)
(10b) Left-click on the Method element of the Invoke Node and choose 'command'.
(10c) Drop a "String Constant" (Functions Palette/Programming/String) onto the Block Diagram.
(10d) Insert the text "MG TIME" (quotes removed) into the String Constant
(10e) Connect the output of the string constant to the command input on the command Propert Node.
(11) Goto the Galil.vi Front Panel window. In the Controls Palette ('View/Controls Palette'), expand "Modern" then "String&Path".
(11a) Drop the "String Control" block onto Front Panel.
(11b) Rename "String" to "Connection String:"
(11c) Leave the string box empty. This can later be changed to the connection string of the controller (192.168.1.100, GALILPCI1, COM 19200 etc). (See Note1)
(12) Drop the "String Indicator" (Controls Palette/Modern/String&Path) onto the Front Panel.
(12a) Rename "String" to "Connected To:"
(12b) Increase the size of the string box by ~double the length and width.
(13) Drop the "String Indicator" (Controls Palette/Modern/String&Path) onto the Front Panel.
(13a) Rename "String" to "Library Version:"
(13b) Increase the size of the string box by ~double the length.
(14) Drop the "String Indicator" (Controls Palette/Modern/String&Path) onto the Front Panel.
(14a) Rename "String" to "MG TIME"
(15) Drop an "Error Out.ctl" control (Controls Palette/Classic/Classic Array, Matrix & Cluster) onto the Front Panel.
(16) Goto the Galil.vi Block Diagram window.
(17) Connect the "error out" terminal of the Automation Open function to the "error in" terminal of the 'address' Property Node.
(17a) Connect the "error out" terminal of the 'address' Property Node to the "error in" terminal of the 'connection' Invoke Node.
(17b) Connect the "error out" terminal of the 'connection' Invoke Node to the "error in" terminal of the 'libraryVersion' Invoke Node.
(17c) Connect the "error out" terminal of the 'libraryVersion' Invoke Node to the "error in" terminal of the 'command' Invoke Node.
(17c) Connect the "error out" terminal of the 'command' Invoke Node to the terminal on the 'error out' block.
(18) Connect the terminal of the 'Connections String:' block to the "address" terminal on the Property Node.
(18a) Connect the terminal of the 'Connected To:' block to the "connection" terminal on the connection Invoke Node.
(18b) Connect the terminal of the 'Library Version:' block to the "libraryVersion" terminal on the libraryVerion Invoke Node.
(18c) Connect the terminal of the 'MG TIME' block to the "command" output terminal on the command Invoke Node.
(19) Goto the Front Panel window. Choose 'Operate/Run' to run the VI.
Note1: If the Connection String string control is left blank, the GalilTools connection dialog will be displayed. If a valid connection string is specified (ex COM1 19200), the program will attempt this connection directly.
---Handling Events with Labview and the GalilTools Communication Library---
There are 3 type of events that can occur in the COM class: onMessage, onInterrupt, onRecord.
onMessage handles unsolicited messages that are sent from the controller.
onInterrupt handles interrupts that are sent from the controller. Not all Galil Controllers have this functionality, see UI and EI in your controllers command reference for more information.
onRecord handles the DR data record information sent from the controller.
This example will show how to set the onMessage event handler in Labview.
(1) Start with the above example.
(2) Drop a Register Event Callback (REC) onto the Block Diagram. (Connectivity/ActiveX).
(3) Connect the output of the Automation Open to the Event of the REC.
(4) Left-click on Event and choose onMessage.
(5) Create a Sting Indicator on the Main panel, and name it "message". Goto the Block Diagram, right-click on the terminal for the string indicator 'message' and choose Create/Refrence.
(6) Connect the string indicator reference to the User Parameter of REC.
(7) Right-click on the VI Ref of REC - choose Create Callback VI.
(7a) Save the created VI as event_onMessage.vi
(8) Show the Block Diagram of event_onMessage.vi. Right-click on Event Data and select 'Cluster, Class, & Variant Palette/Unbundle by Name'.
(8a) Connect the Event Data terminal to the new Unbundle by name message.
(9) Drop a Property Node (Connectivity/ActiveX) onto the event_onMessage.vi Block Diagram.
(9a) Connect the terminal of the message object (icon at the bottom) to the reference terminal of the property node.
(10) Left-click on the Property element on the property node and choose 'value'.
(10a) Right-click on that same element and choose 'Change To Write'.
(10b) Connect the output of the message bundle to the value terminal on the property node.
(11) On the main panel of event_onMessage, drop an Error out block (Classic/Classic Array, Matrix & Cluster).
(11a) in the block diagram, connect the error out of the property node to the input of the error out block.
(12) Save event_onMessage.vi
- Create a program that will run in the controller and send out unsolicited messages -
(13) Add an Invoke node after the library version block, connect it up, and change it to programDownload. Change the command block to XQ, from MG TIME. Add a string constant that has the program:
#A
MG TIME
WT500
JP#A
When using events in Labview, it is a requirement that OFFLINE be sent to address in order to close the connection to the controller and the drivers. In this example, a stop button is used in a event structure.
(14) In the Galil.vi Front Panel, add a retangular stop button (Classic/Classic Boolean) (other boolean buttons should work as well). Rename it from 'stop' to 'stop_vi'.
(15) In the Galil.vi Block Diagram, add an Event Structure (Programming/Structures)
(15a) Right click on 'Timeout' in the event structure and choose "Edit Events Handled by This Case".
(15b) Change the Event Sources to 'stop_vi', and the Events to 'Value Change'
(16) Place a Unregister For Events (Connectivity/AvtiveX) block, a Property Node block (Connectivity/ActiveX), a String Constant (Programming/String), and an Error out (Front Panel - Classic/Classic Array, Matrix & Cluster)
(16a) Connect the 'event callback refnum' terminal output of the REC to the 'event registration refnum' terminal input of the Unregister For Events block.
(16b) Connect the Error output of the REC to the error input of the Unregister For Events block.
(16c) Connect the Property node to the end of the chain for the program download and execution. Change the element to write and choose address. Connect a string constant of OFFLINE to the address terminal.
(16d) Connect the error chain through Unregister For Events to the error out.
The VI should now be ready to run, make sure to use the Stop button to stop the execution of the vi.
In the image above, the "Error Out.ctl" displays error -2147467259. This error code indicates that there was a failed connection (here as a result of choosing "OFFLINE"). If this error were received when trying to connect to an actual controller, there may be an issue with the actual connection. In this case, please close Labview and other applications then make sure that the GalilTools software can connect to the controller.
Another common error is -2147352567. This may occur as a result of opening too many connections to the Galil (more connections than there are handles). A possible cause is opening a new connection on each library call. The address node should only be called once in an application.
There are more errors that are not defined here but the source text will help determine the error response from Galil. For example, as seen above, the sources text Exception occurred in Galil: 5001 OPEN ERROR. OFFLINE specified to Galil::Galil() in Galil.vi helps the developer understand the error code.