Author Topic: Adding drivers programatically  (Read 2981 times)

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Adding drivers programatically
« on: July 22, 2016, 11:33:07 AM »
Hi ,

I'd like to add the drivers programmatically while loading the Software could someone please guide me as to how that could be done.

Mikefly95

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Adding drivers programatically
« Reply #1 on: July 22, 2016, 11:50:48 AM »
This is in C# but how I do it. And i am connecting to an OPC Server

        AdvancedHMIDrivers.OpcDaCom opc = new AdvancedHMIDrivers.OpcDaCom();
        string OPCServerConn = "OPCServer";

        public void SetDemandPoints(string SetPoint, int SetValue)
        {
            try
            {
                opc = new AdvancedHMIDrivers.OpcDaCom();
                opc.OPCServer = OPCServerConn;
                opc.Write(SetPoint, Convert.ToString(SetValue));
            }
            catch
            {
                Console.WriteLine("Error on SetDemandPoints");
            }
                   
        }

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Adding drivers programatically
« Reply #2 on: July 22, 2016, 12:23:15 PM »
hey,
thanks Mikefly95
could you please guide me as to how to do this in vb.net

Mikefly95

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Adding drivers programatically
« Reply #3 on: July 22, 2016, 01:19:01 PM »
Something like this i would guess. Not an expert by any means.

    Dim CLX As New Drivers."DriverHere"

    Public Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CLX = New Drivers."DriverHere"
        CLX.ReadModifyWriteTag()

    End Sub

Someone may correct me.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Adding drivers programatically
« Reply #4 on: July 23, 2016, 03:25:40 PM »
Here is a little trick to learn how to create objects in code and ensure you have all of the supporting code with it:

- Start a new project as you normally do
- Add a driver to the form
- In Solution Explorer, at the top you will see an icon for Show All Files. Click that to enable it
- Now you should have an option to drill down into the MainForm
- Drill down into the MainForm.vb and look for MainForm.Designer.vb
- Right click Mainform.Designer.vb and select View Code
- Look for all the code associated to the driver instance

You will see something like this:

Declaring the object instance and adding to the components collection to ensure proper disposal
Code: [Select]
        Me.EthernetIPforSLCMicroCom1 = New AdvancedHMIDrivers.EthernetIPforSLCMicroCom(Me.components)

Setting the properties
Code: [Select]
        '
        'EthernetIPforSLCMicroCom1
        '
        Me.EthernetIPforSLCMicroCom1.CIPConnectionSize = 508
        Me.EthernetIPforSLCMicroCom1.DisableSubscriptions = False
        Me.EthernetIPforSLCMicroCom1.IniFileName = ""
        Me.EthernetIPforSLCMicroCom1.IniFileSection = Nothing
        Me.EthernetIPforSLCMicroCom1.IPAddress = "192.168.1.233"
        Me.EthernetIPforSLCMicroCom1.IsPLC5 = False
        Me.EthernetIPforSLCMicroCom1.PollRateOverride = 500
        Me.EthernetIPforSLCMicroCom1.Port = 44818
        Me.EthernetIPforSLCMicroCom1.Timeout = 5000

Declaring the variable as Friend Scope (You may use Private scope unless you refer to the driver from other forms)
Code: [Select]
    Friend WithEvents EthernetIPforSLCMicroCom1 As AdvancedHMIDrivers.EthernetIPforSLCMicroCom


Following this pattern will ensure you do everything necessary to properly create, setup, and dispose of the object.