Author Topic: How to create an EasyPLC External Driver with Microsoft Visual Basic 6.0  (Read 6613 times)

EasyPLC_Master

  • Developer
  • Administrator
  • *****
  • Posts: 878
  • Nirtec
    • The EasyPLC Project
Create a new DLL ActiveX project:



Our new library must be called EasyPLCDriver, therefore will be necessary to modify the name of the project:



It is recommended to change the class name (by default class1) for a name that it describes the driver type (in this case Example).  
  
Add the reference InterfaceIO (available when installing EasyPLC):



This reference is an interface that serves like a template to generate our library.  
To implement the interface you must write: Implements IExternalIO



When you select the IExternalIO object from the right superior combo, a list of the all their methods and properties are showed on the left high combo, next is listed the function of each one of them:



Private Property Get IExternalIO_AnalogicDevice() As Boolean
‘Must return True if the driver has analogic inputs or outputs
End Property

Private Property Get IExternalIO_AnalogicInput(n As Integer) As Single
‘Must return the value of the analogic input number n
End Property

Private Property Let IExternalIO_AnalogicOutput(n As Integer, RHS As Single)
‘EasyPLC sets here the value of the analogic output number n
End Property

Private Property Get IExternalIO_AnalogicOutput(n As Integer) As Single
‘Returns the value of the analogic output number n
End Property

Private Sub IExternalIO_Configure()
‘This method is called by EasyPLC when the user presses the button ‘Configure’ from the EasyPLC ‘External Drivers configurator (see next picture). It should implement the appropriate functionalities if the ‘driver needs to be configured.
End Sub



Private Property Get IExternalIO_DigitalDevice() As Boolean
‘Must return True if the driver has digital inputs or outputs.
End Property

Private Property Get IExternalIO_DigitalInput(n As Integer) As Boolean
‘Must return the status of the digital input number n
End Property

Private Property Let IExternalIO_DigitalOutput(n As Integer, RHS As Boolean)
‘EasyPLC sets here the status of the digital output number n
End Property

Private Property Get IExternalIO_DigitalOutput(n As Integer) As Boolean
‘Returns the status of the digital output number n
End Property

Private Property Let IExternalIO_DriverNumber(ByVal RHS As Integer)
‘EasyPLC assigns an integer number to each one of the external drivers. This number can be used to keep ‘the data of the configuration of the driver. The RHS value returns the value that EasyPLC has assigned to ‘this driver.
End Property

Private Property Get IExternalIO_DriverNumber() As Integer
‘It returns the driver number assigned by EasyPLC.
End Property

Private Sub IExternalIO_Finish()
‘This method is called when EasyPLC closes the driver
End Sub

Private Sub IExternalIO_Init()
‘This method is called when EasyPLC initializes the driver
End Sub

Private Sub IExternalIO_OpenDr()
‘This method is called by EasyPLC when the driver starts, this is when the PLC changes to start mode or ‘when the program starts. It is used to read the data kept in the configuration (if is needed)
End Sub

Private Property Get IExternalIO_MessageStatus() As String
‘With this property we can assign a text about the current state of the driver.
End Property

Private Sub IExternalIO_ReadAllAnalogicInputs()
‘The PLC scan time consists on repeating the following three steps cyclically:  
‘1) Read the analogic and digital inputs.  
‘2) Execute all the instructions of the program  
‘3) Activate the pertinent analogic and digital outputs as a result of the program execution
‘EasyPLC calls to this method in the Step 1). Therefore should be carried in this method the reading of all ‘analogic inputs.
End Sub

Private Sub IExternalIO_ReadAllDigitalInputs()
‘The PLC scan time consists on repeating the following three steps cyclically:  
‘1) Read the analogic and digital inputs.  
‘2) Execute all the instructions of the program  
‘3) Activate the pertinent analogic and digital outputs as a result of the program execution
‘EasyPLC calls to this method in the Step 1). Therefore should be carried in this method the reading of all ‘digital inputs.
End Sub

Public Sub WriteAllDigitalOutputs()
‘EasyPLC executes this procedure when should be written the state of the digital outputs (Step 3)  
‘It is necessary for drivers where the state of all the outputs should be sent at the same time and not of each ‘one of the single outputs.
End Sub

Public Sub WriteAllAnalogicOutputs()
‘The same thing that the previous one but for the analogical outputs.
End Sub

Private Property Get IExternalIO_Ready() As Boolean
‘When EasyPLC actives the driver, will wait to that this method returns True before to use it, therefore this ‘property should return True when the driver will be ready to work.  
‘If the property is always false the driver won't work.
End Property

Private Sub IExternalIO_ResetAnalogicOutputs()
‘Method used to reset all the analogic outputs
End Sub

Private Sub IExternalIO_ResetDigitalOutputs()
‘Method used to reset all the digital outputs
End Sub

Private Property Get IExternalIO_TotalAnalogicInputsNumber() As Integer
‘Must return the number of available analogic inputs of this driver.
End Property

Private Property Get IExternalIO_TotalAnalogicsOutputNumber() As Integer
‘Must return the number of available analogic outputs of this driver.
End Property

Private Property Get IExternalIO_TotalDigitalInputsNumber() As Integer
‘Must return the number of available digital inputs of this driver.
End Property

Private Property Get IExternalIO_TotalDigitalOutputsNumber() As Integer
‘Must return the number of available digital outputs of this driver.
End Property

Public Property Get DigitalInputName(n As Integer) As String
‘Must return the name of the requested digital input
End Property

Public Property Get DigitalOutputName(n As Integer) As String
‘Must return the name of the requested digital output
End Property

Public Property Get AnalogicInputName(n As Integer) As String
‘Must return the name of the requested analogic input
End Property

Public Property Get AnalogicOutputName(n As Integer) As String
‘Must return the name of the requested analogic output
End Property


Programming each one of these properties and methods appropriately you will be able to design library of an external driver for EasyPLC.  
  
The library already compiled should be registered in the computer where it should be used (it is not necessary in the computer where it has been compiled because it is registered automatically).
To register it, the application regsvr32.exe it should be used.  
Example c:\WINDOWS\SYSTEM32\regsvr32.exe C:\YourPath\YourLibrary.dll


Calls that EasyPLC make to the external driver:

When EasyPLC pass the PLC to RUN mode, makes the following operations with the external driver:

1.   It assigns an identification number to the driver, this number is in function of the order of the selected drivers. Therefore makes a call to the method: DriverNumber passing the number id.
2.   Makes a call to the method: OpenDr.
3.   Makes a call to the method: Init.
4.   EasyPLC waits until the value of the property Ready is TRUE, when this happens the driver it is ready to work and continue the execution of EasyPLC.

Example:



In this configuration EasyPLC would make the following calls when pass the PLC to RUN mode:

ExternalDriver .DriverNumber = 1
ExternalDriver.OpenDr
ExternalDriver.Init        
Do
            DoEvents          
   ….
Loop While Not ExternalDriver.Ready

PLC in run mode.


Configuration Mode



In configuration mode, when the user presses the button ‘Configure’ EasyPLC makes the following calls:
ExternalDriver.DriverNumber = 1 (In this case)
ExternalDriver.Configure

An example of a external driver written in Visual Basic is available for the registered users. The driver can be configured from 8 to 16 digital inputs/outputs. When the driver is active a window appears to show the outputs state on a checkbox controls and the inputs can be activated checking the checkbox input controls.

IMPORTANT NOTE: THE EASYPLC EXTERNAL DRIVERS ONLY WORKS WITH THE EASYPLC REGISTERED VERSION!
« Last Edit: May 21, 2010, 09:47:41 AM by EasyPLC_Master »