The text of a manual · part 24 of 28
HawkEye 1500 Series Reference & Programmers Manual, pages 231 to 240
Pages 231 to 240 of 276
The original document is the PDF (1.3 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the Microscan HE1510, RVSI CiMatrix HE1510 and Siemens HE1510
Page 231
Example 3, Connecting to Two Cameras at Once
Option Explicit Dim WithEvents m_cam1 As ImageConnection Dim WithEvents m_cam2 As ImageConnection
2 ReadRunner Programming
Private Sub Form_Load() CameraDropdown1.AutoConnect = False CameraDropdown2.AutoConnect = False Set m_cam1 = New ImageConnection Set m_cam2 = New ImageConnection m_cam1.AutoConnect = False m_cam2.AutoConnect = False End Sub Private Sub Form_Unload(Cancel As Integer) m_cam1.DisconnectAll Set m_cam1 = Nothing Set m_cam2 = Nothing End Sub Private Sub CameraDropdown1_CameraSelected(selDevice As String) m_cam1.DeviceName = selDevice End Sub Private Sub CameraDropdown2_CameraSelected(selDevice As String) m_cam2.DeviceName = selDevice End Sub
Private Sub m_cam1_OnNewRecord(ByVal objReport As MIOBJLib.IMiCycleReport) MiImageView1.NewRecord objReport End Sub
Private Sub m_cam2_OnNewRecord(ByVal objReport As MIOBJLib.IMiCycleReport) MiImageView2.NewRecord objReport End Sub
The key difference between this example and the previous ones is that the AutoConnect property of both CameraDropdowns and both ImageConnections are set to False. This means that we have to manually handle what happens when a camera is selected in the dropdowns. You see how this is done via the CameraSelected event handlers. Setting the
Rev 2.4.1, Nov 2008
HawkEye 1500 Reference & Programmers Manual
2-13
Page 232
Chapter
2
ReadRunner Programming Reference
DeviceName property of an ImageConnection is all that is necessary to establish a connection to the named device. Since we have two connections, we also need to handle both OnNewRecord events and send the images to the corresponding MiImageView controls. 7.
2-14
You’re done. You can run the project. It is even possible to make two separate connections to the same camera.
HawkEye 1500 Reference & Programmers Manual
Rev 2.4.1, Nov
Page 233
Example 4, Controlling the HawkEye™ 1500
Example 4, Controlling the HawkEye™ 1500
•
Establish a connection to a HawkEye™ 1500.
•
Use a Checkbox control to switch between triggered and continuous acquisition modes.
•
Send virtual triggers by way of a push button.
•
Display images.
We will once again use the CameraDropdown to select a device. We start out with a variation of the previous example: 1.
Create a new “Standard EXE” project.
2.
Select Project->References… and check the Microscan HawkEye™ Reader Object Type Library (MIOBJ.DLL).
3.
Select Project->Components… and check BOTH the Microscan ReadRunner ActiveX Library (RRKIT.OCX) and the Microscan HawkEye™ Reader ActiveX Library (MIOBJUI.DLL).
4.
Select the CameraDropdown form.
5.
Select a Checkbox control and place on the form. In the properties, change the name of the control to UseTrigger and the caption to read “Use Trigger”.
6.
Place a CommandButton on the form. In the properties, change the name of the control to VirtualTrigger and the caption to read “Send Virtual Trigger”.
Rev 2.4.1, Nov 2008 component and place across the top of the
HawkEye 1500 Reference & Programmers Manual
2-15
2 ReadRunner Programming
This example illustrates how to send commands to the HawkEye™ 1500. Any of the RRKIT.DLL connection objects (ReportConnection, ImageConnection, CommandConnection) can send commands to the connected device using the CommandSend() method. In this example, we will use an ImageConnection to do this, since we just happen to be displaying images as well. This example also serves as an introduction to the Application and AppSetting objects. Here are the goals for this example:
Page 234
Chapter
2
ReadRunner Programming Reference
7.
Select the Imageview component and position on the form.
8.
Similar to the previous example, enter the following code to initialize an ImageConnection, connect it to the MiImageView control and handle the OnConnectionReset event to set the initial state of the controls. Also, notice that when the OnConnectionReset event is received and the iconn.IsConnected is true, then we use the iconn.CommandSend method to send the “CONTROL” command to the camera. Otherwise, we disable the Checkbox and CommandButton controls. Option Explicit Dim WithEvents iconn As ImageConnection Private Sub Form_Load() Set iconn = New ImageConnection iconn_OnConnectionReset End Sub Private Sub Form_Unload(Cancel As Integer) Set iconn = Nothing End Sub
2-16
HawkEye 1500 Reference & Programmers Manual
Rev 2.4.1, Nov
Page 235
Example 4, Controlling the HawkEye™ 1500
Private Sub iconn_OnConnectionReset() If iconn.IsConnected Then iconn.CommandSend "CONTROL" Else UseTrigger.Enabled = False VirtualTrigger.Enabled = False End If End Sub
We want to enable the checkbox and button only after we establish control as a result of sending the “CONTROL” command. To do this, select the iconn object and select the OnControlStatusChanged event to add an event handler. Although this event returns a integer code signifying the status of the camera, we can simply check if we now have control by using the HaveControl property of the ImageConnection: Private Sub iconn_OnControlStatusChanged(ByVal newStatus As Long) UseTrigger.Enabled = iconn.HaveControl VirtualTrigger.Enabled = iconn.HaveControl End Sub
10.
To have the checkbox reflect whether the camera is triggered or not, we need to do a “Query” of the TRIG command. The two possible states are “TRIG C” for continuous and “TRIG T” for triggered. A query consists of sending the “TRIG ?” command to see what the current setting is. It is possible to use CommandSend to do everything, but we will instead use the Application object. This object simplifies querying and changing settings, and is particularly useful when the commands are complex and/or you are changing more than one setting at a time. Add the following code: At the top of the module declare the following: Dim app As New Application Dim bInUpdateVisuals as boolean
Change the code in the OnConnectionReset event to read: Private Sub iconn_OnConnectionReset() If iconn.IsConnected Then app.Query iconn.ASCIIConnection, "TRIG" ‘ <-----add this line iconn.CommandSend "CONTROL" Else UseTrigger.Enabled = False VirtualTrigger.Enabled = False End If End Sub
Rev 2.4.1, Nov 2008
HawkEye 1500 Reference & Programmers Manual
2-17
ReadRunner Programming
9.
2
Page 236
Chapter
2
ReadRunner Programming Reference
Notice that the app.Query command requires that you pass an MiASCIIConnection object as the first parameter. Use the ImageConnection.ASCIIConnection property in this case. Add a new subroutine to handle updating the checkbox: Private Sub UpdateVisuals() bInUpdateVisuals = True Dim bTriggered As Boolean bTriggered = app.Setting("TRIG").Params(0) = "T" UseTrigger.Value = IIf(bTriggered, vbChecked, vbUnchecked) VirtualTrigger.Enabled = bTriggered bInUpdateVisuals = False End Sub
There are a couple of things to notice here. The Application object consists of a collection of AppSetting objects. You index this collection with the name of the setting, in this case “TRIG”. Each AppSetting can have multiple parameters, which are indexed using a zero based index. Therefore, the line bTriggered = app.Setting("TRIG").Params(0) = "T" is setting the state of the Boolean variable bTriggered, depending on whether or not the first parameter is “T”. Also, we set the global variable bInUpdateVisuals to True at the start and False at the end of this subroutine. This is because we are setting the checkbox state in this routine which will, in turn, cause an event to happen. As you will see, we don’t really want to handle the event in this case, since the event will call UpdateVisuals and we’d be stuck in an infinite recursion. We will use this global boolean to prevent this. Now we can handle the checkbox Click event: Private Sub UseTrigger_Click() If bInUpdateVisuals Then Exit Sub If UseTrigger.Value = vbChecked Then app.Setting("TRIG").SetParam 0, "T" Else app.Setting("TRIG").SetParam 0, "C" End If app.WriteSettings iconn.ASCIIConnection UpdateVisuals End Sub
The first line exits immediately if we find we got here via UpdateVisuals to prevent recursion.
2-18
HawkEye 1500 Reference & Programmers Manual
Rev 2.4.1, Nov
Page 237
Example 4, Controlling the HawkEye™ 1500
To send all the changed settings back to the camera (in this case, there’s only one), we use the WriteSettings method of the Application object. Again, you need to provide an MiASCIIConnection, so use the ASCIIConnection property of iconn. We then call UpdateVisuals to make sure the checkbox reflects the current state of the “TRIG” command. 11.
Lastly, to send the virtual trigger command, handle the Click event for the VirtualTrigger button: Private Sub VirtualTrigger_Click() ' send a virtual trigger command iconn.CommandSend "VT 2" End Sub
12.
Rev 2.4.1, Nov 2008
You’re done. Run the project.
HawkEye 1500 Reference & Programmers Manual
2-19
2 ReadRunner Programming
Next, you can see how the SetParam method is used; in this case, we are setting the first parameter to either “T” or “C”, depending on the state of the check box.
Page 238
Chapter
2
ReadRunner Programming Reference
Example 5, Image Overlay Graphics and Auto Connection This example illustrates how to make a custom graphic overlay. It also demonstrates how to connect automatically to a camera without using the CameraDropdown control as in previous examples: 1.
Establish an image connection to a known HawkEye™ 1500 by name.
2.
Display an image, but disable the normal overlay graphics and replace them with custom graphics consisting of: –
A crosshair display
–
Decode string and pass/fail counters at the top of the image
This project will begin in standard fashion:
2-20
1.
Create a new “Standard EXE” project.
2.
Select Project->References… and check the Microscan HawkEye™ Reader Object Type Library (MIOBJ.DLL).
3.
Select Project->Components… and check BOTH the Microscan ReadRunner ActiveX Library (RRKIT.OCX) and the Microscan HawkEye™ Reader ActiveX Library (MIOBJUI.DLL).
4.
Select the MiImageView
5.
Select the MiImageView1control and, in its properties, set the ShowCycleGraphics, ShowCycleText and ShowOverlay properties to False. In this example, we will take over all drawing ourselves.
component and position on the form.
HawkEye 1500 Reference & Programmers Manual
Rev 2.4.1, Nov
Page 239
Example 5, Image Overlay Graphics and Auto Connection
ReadRunner Programming
2
The complete code for this example follows: Option Explicit Const MY_CAMERA = "jdzoffice" ‘ <-------- replace with your camera name
Const TRANSPARENT = 1 Const OPAQUE = 2 Implements MiDrawObj ‘ <---------- makes this form a DrawObj
Dim WithEvents coord As MiCoordinator Dim WithEvents iconn As ImageConnection Dim saveReport As MiCycleReport Dim myFont As New StdFont Private Sub Form_Load() Set coord = New MiCoordinator Set iconn = New ImageConnection
Rev 2.4.1, Nov 2008
HawkEye 1500 Reference & Programmers Manual
2-21
Page 240
Chapter
2
ReadRunner Programming Reference coord.ClearDevices With myFont .Size = 7 .Name = "Arial" End With MiImageView1.DrawObjAdd Me, "overlay" iconn_OnConnectionReset End Sub Private Sub Form_Unload(Cancel As Integer) coord.DeviceFocusSet "" Set coord = Nothing Set iconn = Nothing Set saveReport = Nothing End Sub Private Sub iconn_OnConnectionReset() If Not iconn.IsConnected Then MiImageView1.ClearRecords End If End Sub Private Sub coord_OnDeviceDiscovered(ByVal newDevice As MIOBJLib.IMiDevice) If newDevice.Name = MY_CAMERA then coord.DeviceFocusSet MY_CAMERA End If End Sub Private Sub iconn_OnNewRecord(ByVal objReport As MIOBJLib.IMiCycleReport) MiImageView1.NewRecord objReport Set saveReport = objReport End Sub Private Sub Form_Resize() On Error Resume Next MiImageView1.Move 0, 0, ScaleWidth, ScaleHeight End Sub Private Sub MiDrawObj_Draw(ByVal midc As MIOBJUILibCtl.IMiDC) If iconn.IsConnected Then If Not saveReport Is Nothing Then midc.SetBkMode OPAQUE midc.SetFont myFont midc.SetTextColor vbCyan Dim s As String With saveReport s = saveReport.ReportDecode.DecodeDataFormatted s = Replace(s, vbCrLf, "") s = s & " Passed = " & .CountDecodes
2-22
HawkEye 1500 Reference & Programmers Manual
Rev 2.4.1, Nov