2.12 Communications with a Windows PC (Visual Basic Application)
Using Automatic Reception with the MP3000 as a Slave
2-330
Visual Basic Application Example
A program example is shown below.
• Form Programming Example
In the programming example that is given below, a
Timer
must be placed on the
Form
from the Com-
ponents in the toolbox. Initialize the
Timer
in the handler function for Form Load event.
The Winsock socket library is required to run this program.
TextBox6 to
TextBox10
TextBox1 to
TextBox4
TextBox9
TextBox5
ComboBox1
Command1
Public Class Form1
Inherits System.Windows.Forms.Form
∗
∗
Dim TransPort As Short
Dim SFC, CPUNum As Byte
Dim DataNum, Adr As Short
Dim Ssbuf, Srbuf As String
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Command1.Click
Dim MyIP, DstIP As String
Dim MyPort, DstPort As Short
Dim rc As Short
'---- Get the PC’s IP address ----
MyIP = TextBox1.Text & "." & TextBox2.Text & "." & _
TextBox3.Text & "." & TextBox4.Text
'---- Get the PC’s port number ----
MyPort = Val(TextBox5.Text)
'---- Get the MP3000’s IP address ----
DstIP = TextBox6.Text & "." & TextBox7.Text & "." & _
TextBox8.Text & "." & TextBox9.Text