Overview & Simple Arguments
The SUDS Library
The information below assumes the SUDS library is already in Ignition's installation directory. Newer installations of Ignition may not include this library, but it can easily be imported following the steps below:
-
Download the SUDS library: https://fedorahosted.org/suds/
-
Place the library into Ignition's installation directory: Knowledge Base - Importing 3rd party modules
When working with Web Services, the SUDS documentation and the PyDocs are a good place to start.
The SUDS library is a SOAP-based web services client developed for Python. It is extremely simple to use and practically eliminates the need for the user to understand or even view the WSDL of a web service. The SUDS library interprets the WSDL file for you and through a couple simple function calls allows you to get a list of the available methods provided to you by the web service. You can then invoke these methods in Ignition through event scripting to send and receive data in your projects. You will have to familiarize yourself with the SUDS library in order to make use of it.
A Simple Example
If you read through the SUDS documentation you'll see that the Client object is the primary interface for most users. It is extremely simple using this object and a few print statements to view a list of available methods provided by the web service you are connecting to. This example will illustrate how to make an initial connect to a web service, print out the list of available methods, and then call one of these methods and display the resulting value in a label on an Ignition window at the push of a button. The below example uses a public web service and is available for anyone to test against.
-
First, we can use the script playground to test out some scripting calls and see the output. The below example shows how to get a reference to a client object. By printing this client object to the console we get an output of all the available methods, types and other information about the web service as defined in the WSDL file.
Example Codefrom
suds.client
import
Client
client
=
Client(
"http://www.w3schools.com/xml/tempconvert.asmx?WSDL"
)
print
client
This WSDL defines two functions: CelsiusToFahrenheit(string Celsius) and FahrenheitToCelsius(string Fahrenheit). These are the functions that this web service makes available to you. Don't worry about the fact that the methods are listed twice. This is just because the WSDL has two definitions of the functions that are formatted for different SOAP version standards. To call these functions in Ignition scripting you have to make use of the "service" member of the client object.
2. To make a simple conversion window in an Ignition project you can add two buttons, a numeric textbox, and a lable to a window. Then on the button to be used to calculate a Fahrenheit to Celsius calculation you would place something like the following:
from
suds.client
import
Client
client
=
Client(
"http://www.w3schools.com/xml/tempconvert.asmx?WSDL"
)
far_value
=
event.source.parent.getComponent(
'Numeric Text Field'
).floatValue
cels_value
=
client.service.FahrenheitToCelsius(far_value)
event.source.parent.getComponent(
'Label'
).text
=
cels_value
3. Then on the second button do the opposite.
from
suds.client
import
Client
client
=
Client(
"http://www.w3schools.com/xml/tempconvert.asmx?WSDL"
)
cels_value
=
event.source.parent.getComponent(
'Numeric Text Field'
).floatValue
far_value
=
client.service.CelsiusToFahrenheit(cels_value)
event.source.parent.getComponent(
'Label'
).text
=
far_value
4. With your scripts in place your window should now function as a simple temperature conversion tool!
Beyond the Example
This example is extremely simple and rather straight forward. The main steps to remember when attempting to use the SUDS library in scripting are as follows:
#Import the SUDS Client object
from
suds.client
import
Client
#Instantiate a new Client Object
client
=
Client(
"url_to_your_wsdl"
)
#Call the desired method using the service instance variable
client.service.MyMethod(myArgument)