使用基于事件的脚本

调度程序等待的FIX32.NODE1.DOWNTIMESTART.F_CV值为真。调度程序等待的FIX32.NODE1.DOWNTIMESTART.F_CV值为真。当它为真时,脚本则启动一个窗体让用户输入停机事件发生的原因。当用户单击“确定”后,脚本打开一个相关的数据库,并写入时间、日期、数据源和停机事件描述到数据库中。使用下表中的参数来创建事件对象和窗体,准确地将选项按钮放在结构内部。

停机开始事件属性 

对象

属性

设置

事件

名称
事件类型
数据源

Line1Packer1DownTime
On True
Fix32.NodeName.DownTimeStart.F_CV

窗体

名称
Caption

frmDownTime
Downtime Monitoring Logging to Relational Database

命令按钮

名称
Caption

cmdOK
OK

Frame

名称
Caption

fraLine1Packer1
Packaging Line 1 Packer 1

Option Button

名称
Caption

optDownTimeReasonOne
Bad packaging material

Option Button

名称
Caption

optDownTimeReasonTwo
Fallen bottle or bottle jam on line to packer

Option Button

名称
Caption

optDownTimeReasonThree
Low oil pressure in packer drive

Option Button

名称
Caption

optDownTimeReasonFour
<Leave this caption blank>

Textbox

名称
启用

TxtDownTimeReasonFour
False

例: 记录监测停机时间

'Place the following code into the subroutine created after

'clicking the VB Editor button in the Modify Event Entry dialog.

 

'On the Event object's OnTrue event, initialize the form

'with the Event's data source and then show the form.

'Line1Packer1DownTime is the name of the event created

'in Scheduler.

 

Private Sub Line1Packer1DownTime_OnTrue()

     frmDownTime.InitializeDataSource _

     (Line1Packer1DownTime.Source)

     frmDownTime.Show

 

End Sub

 

关系型数据库的停机监控记录

'Place the following code directly in the form you create and 'set a reference to Microsoft DAO 3.See 'Visual Basic Editor Help for details on setting references.

 

Public sDataSource As String

 

'This is the initialize routine that is called from the Event

'object's OnTrue event.It creates a public instance of the

'string name of the data source for the form to use.

Public Sub InitializeDataSource(DataSource As String)

     sDataSource = DataSource

 

End Sub

 

'When the option button beside the text box is selected,

'enable and set focus to the text box.

Private Sub optDownTimeReasonFour_Click()

 

     txtDownTimeReasonFour.Enabled = True

     txtDownTimeReasonFour.SetFocus

 

End Sub

 

'When the form gets activated, set the first option to true

Private Sub UserForm_Activate()

     optDownTimeReasonOne.Value = True

 

End Sub

 

'When the user selects OK, store which reason they chose.

Private Sub cmdOK_Click()

     Dim DownTimeReason As String

     If optDownTimeReasonOne.Value = True Then

          DownTimeReason = optDownTimeReasonOne.Caption

     ElseIf optDownTimeReasonTwo.Value = True Then

          DownTimeReason = optDownTimeReasonTwo.Caption

     ElseIf optDownTimeReasonThree.Value = True Then

          DownTimeReason = optDownTimeReasonThree.Caption

     ElseIf optDownTimeReasonFour.Value = True Then

          If txtDownTimeReasonFour.Text <> "" Then

               DownTimeReason = txtDownTimeReasonFour.Text

          Else

               MsgBox "Please enter a reason for the _

               downtime event"

               txtDownTimeReasonFour.SetFocus

          End If

     End If

 

'Call the AddDownTimeEventData subroutine to add the

'downtime information to the database.

Call AddDownTImeEventData(DownTimeReason)

     Unload Me

 

End Sub

 

'This subroutine writes the data to the database and

'updates it.

'This database has not been provided and will need to be created

'for this subroutine to execute without error.

 

Public Sub AddDownTImeEventData(DownTimeReason As String)

 

     'Create an instance of the Workspace.

     Dim wrkSpace As Workspace

     Set wrkSpace = CreateWorkspace("", "admin", "", dbUseJet)

 

     'Open the downtime database.

     Dim db As Database

     Set db = wrkSpace.OpenDatabase(System.PicturePath & _

     "\downtime.mdb")

 

     'Create a recordset.

     Dim rs As Recordset

     Set rs = db.OpenRecordset("Packaging", dbOpenDynaset)

 

     'Set up the time of downtime occurrence.

     Dim TimeDate As Date

     TimeDate = Now

     rs.AddNew

     rs.Fields(1) = TimeDate

     rs.Fields(2) = TimeDate

     rs.Fields(3) = sDataSource

     rs.Fields(4) = DownTimeReason

     rs.Fields(5) = Fix32.NODE1.downtimeperiod.f_cv

     rs.Update

 

End Sub

 

相关信息

您最近了解过 iFIX 吗 ?

查看最新版 iFIX 的所有新功能。

让 iFIX 帮助您提高效率,降低成本。