Sample program location: (in GP-Pro EX DVD-ROM) \WinGP\SDK\Pro-SDK\DotNet\EasySmpl
Imports ProEasyDotNet
' Imports ProEasy object.
Public Class Form1
Inherits System.Windows.Forms.Form
#Region "Code generated with Windows form designer"
Public Sub New()
MyBase.New()
' This call is necessary for Windows form designer.
InitializeComponent()
' ProEasy Initialization. After calling InitializeComponent(), runs initialization.
Dim iResult As Integer = ProEasy.EasyInit() ' WinGP Initialize SDK once at the beginning.
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
End If
End Sub
' Form overwrites the dispose to execute post processing on the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
-Snip (Codes designed by Windows form designer are omitted hereafter)-
#End Region
Private Sub ReadBit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ReadBit.Click
End Sub
Private Sub Read16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Read16.Click
Try
' Read data.
Dim nDataAry(1) As Short
' Read.
Dim iResult As Integer = ProEasy.ReadDevice16("#WinGP", "Buf_16", nDataAry, 1)
' Here the symbol "Buf_16" (USR201) configured in GP-Pro EX is used.
' You can also specify the device address directly.
' 38.5.2.2 How to specify device addresses directly
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Me.Buf_16.Text = CStr(nDataAry(0))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Read32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Read32.Click
Try
' Read data.
Dim nDataAry(1) As Integer
' Read.
Dim iResult As Integer = ProEasy.ReadDevice32("#WinGP", "Buf_32", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Me.Buf_32.Text = CInt(nDataAry(0))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ReadBCD16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ReadBCD16.Click
Try
' Read data.
Dim nDataAry(1) As Short
' Read.
Dim iResult As Integer = ProEasy.ReadDeviceBCD16("#WinGP", "Buf_BCD16", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Me.Buf_BCD16.Text = CShort(nDataAry(0))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ReadBCD32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ReadBCD32.Click
Try
' Read data.
Dim nDataAry(1) As Integer
' Read.
Dim iResult As Integer = ProEasy.ReadDeviceBCD32("#WinGP", "Buf_BCD32", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Me.Buf_BCD32.Text = CInt(nDataAry(0))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ReadFloat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ReadFloat.Click
Try
' Read data.
Dim nDataAry(1) As Single
' Read.
Dim iResult As Integer = ProEasy.ReadDeviceFloat("#WinGP", "Buf_Float", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Me.Buf_Float.Text = CSng(nDataAry(0))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ReadDouble_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ReadDouble.Click
Try
' Read data.
Dim nDataAry(1) As Double
' Read.
Dim iResult As Integer = ProEasy.ReadDeviceDouble("#WinGP", "Buf_Double", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Me.Buf_Double.Text = CDbl(nDataAry(0))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ReadStr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ReadStr.Click
Try
' Read data.
Dim nDataAry As String
' Read.
Dim iResult As Integer = ProEasy.ReadDeviceStr("#WinGP", "Buf_Str", nDataAry, 10)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Me.Buf_Str.Text = nDataAry
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ReadVariant_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ReadVariant.Click
End Sub
Private Sub ReadSymbol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ReadSymbol.Click
End Sub
Private Sub WriteBit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
WriteBit.Click
Try
' Read data.
Dim nDataAry(1) As Short
nDataAry(0) = CShort(Val(Me.WBuf_Bit.Text))
' Read.
Dim iResult As Integer = ProEasy.WriteDeviceBit("#WinGP", "Buf_16", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Write16_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Write16.Click
Try
' Write data.
Dim nDataAry(1) As Short
nDataAry(0) = CShort(Val(Me.WBuf_16.Text))
' Write.
Dim iResult As Integer = ProEasy.WriteDevice16("#WinGP", "Buf_16", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Write32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Write32.Click
Try
' Write data.
Dim nDataAry(1) As Integer
nDataAry(0) = CInt(Val(Me.WBuf_32.Text))
' Write.
Dim iResult As Integer = ProEasy.WriteDevice32("#WinGP", "Buf_32", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub WriteBCD16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
WriteBCD16.Click
Try
' Write data.
Dim nDataAry(1) As Short
nDataAry(0) = CShort(Val("&h" + Me.WBuf_BCD16.Text))
' Write.
Dim iResult As Integer = ProEasy.WriteDevice16("#WinGP", "Buf_BCD16", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub WriteBCD32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
WriteBCD32.Click
Try
' Write data.
Dim nDataAry(1) As Integer
nDataAry(0) = CInt(Val("&h" + Me.WBuf_BCD16.Text))
' Write.
Dim iResult As Integer = ProEasy.WriteDeviceBCD32("#WinGP", "Buf_BCD32", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub WriteFloat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
WriteFloat.Click
Try
' Write data.
Dim nDataAry(1) As Single
nDataAry(0) = CSng(Val(Me.WBuf_Float.Text))
' Write.
Dim iResult As Integer = ProEasy.WriteDeviceFloat("#WinGP", "Buf_Float", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub WriteDouble_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
WriteDouble.Click
Try
' Write data.
Dim nDataAry(1) As Double
nDataAry(0) = CDbl(Val(Me.WBuf_Double.Text))
' Write.
Dim iResult As Integer = ProEasy.WriteDeviceDouble("#WinGP", "Buf_Double", nDataAry, 1)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub WriteString_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
WriteString.Click
Try
' Write data.
Dim nDataAry As String
nDataAry = Me.WBuf_Str.Text
' Write.
Dim iResult As Integer = ProEasy.WriteDeviceStr("#WinGP", "Buf_Str", nDataAry, 10)
If iResult Then
Dim sErrMsg As String
ProEasy.EasyLoadErrorMessageEx(iResult, sErrMsg)
MsgBox(sErrMsg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub WriteVariant_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles WriteVariant.Click
' In VB.NET, Variant type is no longer used. Instead Object type is used.
' Along the change, WriteDeviceVariant() has been changed to WriteDeviceEasyObject().
End Sub
Private Sub WriteSymbol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
WriteSymbol.Click
' Only WriteSymbol system found is WriteSymbolVariant().
End Sub
End Class