Building HMI WithVBTutorial

Download Building HMI WithVBTutorial

Post on 13-Apr-2015




0 download

Embed Size (px)


<p>Building Your HMI Using Visual Basic Technologies - A TutorialJohn Weber The Software</p> <p>October 21, 1998 Houston, TXPoster Presentation</p> <p>Copyright 1998 Qualitrol International &amp; Software Toolbox.All rights reserved worldwide.The Software Toolbox is a registered trademark of Qualitrol International.</p> <p>Why are we here today ? Take the mystery out of objects and VB Objects &amp; terminology ActiveX &amp; Containers VB - The Glue</p> <p> Sample Applications Process Graphics PLC Connections Trending/Logging Alarming/Logging Recipes Networking</p> <p>Defining the Technologies</p> <p>Software Objects What are they ? You cant touch them - except on the disks or CD you load them onto your PC from You can see them in many cases through their user interface Are pieces of software for a specific task or family of similar tasks Are similar to subroutines or functions May contain numerous subroutines and functions of their own Used to model software after real-world machine or process components or sections Are easily transported from one PC to another provided standard interfaces are followed Much of the software you use on your PC is built of objects</p> <p>Objects - The Building BlocksExample - an object representation of a PLCInput Modules Output Class Modules Class</p> <p>Interfaces</p> <p>Power Supply</p> <p>PLC Rack</p> <p>Object Terminology Classes - groupings of similar object types Properties - define how the object behaves Methods - make things happen Events - occur when things happenHypothetical PLC Analog Input Module classProperties - number of channels, voltage level, scaling set points, channel type Methods - send analog input to CPU, scale value Events - voltage changed on field input side, scaling updated, updated value sent to CPU, configuration change received from CPU</p> <p>Object TerminologyA simple software object - a text box on a VB formPropertiesAlignment BackColor BorderStyle Font Height Name Text Visible Width and 43 others</p> <p>MethodsDrag Move OLEDrag Refresh SetFocus ShowWhatsThis and 5 others</p> <p>EventsChange Click DblClick DragDrop DragOver GotFocus LostFocus KeyPress Mousedown Mouseup and 13 others</p> <p>More Object Terminology COM - Component Object Model DCOM - Distributed Component Object Model = COM + Networks ActiveX - a type of COM object Container - a place you assemble your objects to form an application Office productivity applications Development tools - visual basic, etc. Web browser</p> <p> OLE - Object Linking and Embedding</p> <p>Software Objects ExamplesCommand Button Object</p> <p>Command Button Properties</p> <p>Everything on your Excel spreadsheet is an object! - the worksheet is a collection of cell objects, a workbook is a collection of worksheet objects</p> <p>Cell Properties</p> <p>Cell Object</p> <p>Software Objects ExamplesInvoking the Print Method</p> <p>The Print Event</p> <p>Software Objects Examples</p> <p>Visual Basic (VB) comes with a lot of free objects that give you the Windows look and feel with minimal work</p> <p>Software Objects ExamplesActiveX control objects plug-in to VB to let you add functionality PLC Communications Trends Gauges Tanks</p> <p>Adding an ActiveX Component to the VB Toolbar &amp; To A FormRight Mouse Click with pointer over the toolbar and select components The Default VB Toolbar Double click the new component on the toolbar and it is added to your form! Check the component you want to add ABCTL OLE Control module in this case, click the Apply button, click the OK button, and the control is added to the toolbar</p> <p>An Automation Software Object</p> <p>Actual PLC Communciations ActiveX Object instances Placed into a Visual Basic form container Instance (noun) - a single copy of a type of software object (I.e. text box or ActiveX control) on a form Instanciate (verb) - the act of placing a single copy of an object onto a form</p> <p>Browsing the Objects InterfacesActual PLC ActiveX object in a VB container application where its properties, methods, and events are browseable using VBs Object Browser Function</p> <p>Events Properties</p> <p>Methods</p> <p>VB - The Glue to connect objects in your container VB - Visual Basic - a full fledged development environment VBA - Visual Basic for Applications It is macro language in the Office applications Is licensed by over 100 companies for use as their scripting language for customization</p> <p> Both Use simple, object.method, object_event syntaxes VB known by 3,000,000 people worldwide</p> <p>Assembling the Objects in a ContainerSimple Visual Basic Syntax for referring to objectsProperties - ObjectName.Property = variable or value Methods - Objectname.Methodname (parameters) Events - Private Sub Objectname_EventName( ) user Logic End Sub</p> <p>Example StatementsText1.Text = Hello World ABCTL1.FileAddr = N7:0 ABCTL1.Autopoll(500)</p> <p>displays text in a text box by setting the .Text property on the Text1 text box object Sets a PLC memory address property (.FileAddr) to read using a plug-in ActiveX control object Invokes the .Autopoll Method to read data every 500ms using a plug-in ActiveX control object</p> <p>Human Machine Interface Apps HMI = Human Machine Interface Process Graphics PLC Connectivity for Data Trending and Logging Alarming and Logging Recipe Loading Networking</p> <p>Process Graphics - StaticStep 1Select the VB image control from the VB toolbar and add to the form</p> <p>Step 2 - Paste an image from a Symbol Library to the image control, set the stretch property on the image control to true and size to fit your needs</p> <p>Process Graphics - DynamicAdd an instance of a dynamic gauge ActiveX plug in to your VB toolbar and then to your form</p> <p>Right click on the object with your mouse, select properties on the pull down menu that appears and use this properties page to set your look and feel. Here weve used a preconfigured look and feel from the objects library to get setup quick</p> <p>PLC Connectivity and Data adding the ActiveX Control</p> <p>Add an off-the-shelf ActiveX control for PLC connectivity to your VB toolbar and then add instances of the control to your VB form Use multiple instances of the PLC ActiveX control to keep code to a minimum Give the each instance an intuitive name such as PLCMachine1 and PLCMachine2 in your applications Use separate instances for reading and writing to keep your code to a minimum, even though most PLC Communications ActiveX controls dont require you to use separate instances for reading and writing</p> <p>PLC Connectivity and Data setting propertiesThis particular PLC communications ActiveX control represents each physical hardware adapter as a logical adapter. You run a simple config program shown here to set the hardware settings and communications parameters. By doing this, the developer of this control gives you the ability to change the hardware interfaces to your PLC without recompiling your program. When you right click on each instance of the PLC control, you bring up this properties page to set the properties on the control for whether you are reading or writing (.function), the PLC node address (.node), the PLC memory address (.Fileaddr), and the number of points to read/write.</p> <p>PLC Connectivity and Data Making the read happen</p> <p> Reading occurs when the .Trigger or .Autopoll methods are invoked In this example when the Form Loads, (Form_Load() Event) the Autopoll method on the instance of the PLC ActiveX control called ABCTL1 is invoked. The PLC control does its job and when it is done, it fires the OnReadDone() event Displays are updated using the 3 lines of code shown above in the ABCTL1_OnReadDone() Event Data is accessed in the PLC ActiveX control using the WordVal and BitVal methods to properly format the data Other methods such as floatval, stringval, longval, etc. are available for other data types</p> <p>Trending and LoggingBuilds upon what youve already learned by adding 2 new controls Trending ActiveX control</p> <p> VBs standard Data control for database connectivitySetup a single instance of the PLC ActiveX control and its properties like before but this time use the standard VB command buttons On_Click() event to start the polling of the PLC based on user input</p> <p>Properties Page for the Trending ActiveX Control</p> <p>Trending and Logging - VB CodeInvoke the PLC ActiveX Controls .Autopoll method to start/stop polling when user clicks on command buttons These lines setup the timebase and variables on the trend chart ActiveX control when the form is loaded Update text boxes on screen with data from the PLC ActiveX Control Plot data on the trending ActiveX control Log the data to the database using the VB data controls methods This OnReadDone Event fires every time a poll completes - the autopoll rate sets your trend update rate for you</p> <p>Trending and Logging</p> <p>The Finished Product in Run Mode</p> <p>Alarming and Logging - Building the Form Uses same controls andadds one new</p> <p> Uses new methods and events on PLC ActiveX control to provide alarm generation capability</p> <p>VB List Box Control for simple alarm display - new to this project</p> <p>VB Data Control for Database Connectivity</p> <p>PLC ActiveX Communications Control</p> <p>Alarming and Logging Generating the Alarms Watchpoint Methods Method included in PLC ActiveX control User specifies high, low limits and type of alarms desired (on high, on low, on change, on normal, on discrete change) Autopoll method used to tell control how often to check the points</p> <p> Could all be done with VB If-then structures Using the ActiveX controls methods instead saves code and troubleshooting time</p> <p>Alarming and Logging You setup the watchpoints and go on doing other things in your applications Handle the events when they happen OnAnalogHigh OnAnalogLow OnAnalogChange OnAnalogNormal OnDiscreteChange</p> <p>Alarming and Logging- VB CodeSetting up the watchpoint by invoking the .WatchPointAdd method in the PLC Comms ActiveX Control</p> <p>Use the .Autopoll method to start polling the PLC when the command buttons are clicked - also clear the alarms display when polling starts</p> <p>Build the high alarm message text string, display it in the list box, then log the data to the database using the data controls methods</p> <p>Alarming and Logging- VB Code</p> <p>Build the low alarm message text string, display it in the list box, then log the data to the database using the data controls methods</p> <p>Alarming and Logging- VB CodeBuild the normal alarm message text string, display it in the list box, then log the data to the database using the data controls methods</p> <p>Update a text box on the screen each time a new value is read from the PLC</p> <p>Do some simple data validation when the user enters a PLC memory address</p> <p>Alarming and Logging Finished Product</p> <p>Alarming and Logging Advanced Displays</p> <p>For more advanced alarm displays, ActiveX plugins are available to provide the needed functionality</p> <p>Recipe Loading - Setting up the Data ControlUse VBs standard Data Control to connect to a database</p> <p> Dont let all the properties confuse or worry you Key properties to set on data control:</p> <p> DatabaseName = pathname and filename of the database RecordSource = table name or query name to get records from in the database - data control gives you a pull-down list</p> <p>Recipe Loading - Data BindingText box properties page has 2 key properties that allow the user to connect or bind the value shown in the field to a column in a database table or query DataSource - the name of the data control that you setup to connect to the database DataField - the actual column, pulled from an auto-generated pulldown list, whose data will be bound to the text box</p> <p>Each text box field on the form is bound using the DataSource and DataField properties to a column in the database</p> <p>Recipe Loading - In ActionWhen the user clicks on the next or previous recipe buttons, the code shown below advances the database pointer forward or backward one record while checking to make sure the beginning or end of the database table is not passed</p> <p>Recipe Loading - In ActionWhen user clicks on Download to PLC, the code below loads the displays values into the PLC ActiveX control and invokes its trigger method to write the data to the PLC. When the OnWriteDone event fires, the user is notified with a message box</p> <p>Networking - Leveraging Newer Ethernet Aware PLCsClient PCs running your VB HMI Application and using a PLC ActiveX control that supports direct Ethernet connections to the PLC</p> <p>TCP/IP Ethernet Network</p> <p>PLCs with built-in Ethernet Interfaces</p> <p>Networking - Retrofitting to Proprietary PLC NetworksClient PCs running your VB HMI Application and utilizing a PLC ActiveX control that provides with it an EXE application for your server to bridge from Ethernet to the PLC networks or an ActiveX control that is an OPC client and can talk to an OPC server</p> <p>Gateway Server running a software bridge between the PLCnetworks and TCP/IP Ethernet</p> <p>TCP/IP Ethernet NetworkProprietary PLC Network</p> <p>Remote user via Windows Dial-Up Networking</p> <p> Provides a solution when the investment to replace PLCs with Ethernet Based CPUs is too high or the PLC network interface cards for each client are cost-prohibitive The gateway software bridge can be either an EXE program that is included with some PLC communications ActiveX controls or an OPC server</p> <p>Transfer Line Application</p> <p>Transfer Line Application</p> <p>Microbrewery Application</p> <p>Benefits of Using Visual Basic for HMI Applications Use the right tool for the right job Simple to moderately complex apps Dont reinvent a pre-configured HMI in VB if thats really what you need</p> <p> Support for wide range of ActiveX plug-ins Widely known scripting language Flexibility - you control the application Cost you can distribute your VB code royalty free ActiveX components have low or no royalty fees for</p> <p>Resources for further learning Understanding ActiveX &amp; OLE - David Chappel, Microsoft Press Office97 Visual Programmers Guide Microsoft Press Microsoft Websites Download copy of this presentation and other presentations and technical papers at</p> <p></p> <p>Where do I find ActiveX controls and tools for Industrial HMI Applications ?Although this presentation is a non-commercial, sharing of knowledge presentation, we added this slide after show because so many of you at the show were asking this question! The Software Toolbox is a company that provides you with a single place to look to find all the software tools you need for automation applications, including Visual Basic based HMI applications. Visit our website today for more product information.</p> <p></p>


View more >