– 68 –
8
Chapter
Sample Program
This chapter shows a sample program that runs in Microsoft Visual Basic 6.0 (SP6) for reading and writing data.
The program shown here is meant to be used as a reference for your own program creation, and therefore all its actions are not
guaranteed.
Before running the program, check the following summary of points for communication conditions.
•Parity, communication speed to be set in this program. Please match these values with the conditions of the micro controller.
Warning when using an RS-232C to RS-485 converter
The sent data is sometimes added to the response data from the slave before it is received. In this case, when receiving the data,
process the response data only after first getting rid of the number of bytes from the sent data.
Compatible OS
Windows 2000 Professional
Windows XP Professional Edition
Fuji Electric Systems Co., Ltd. assumes no responsibility for damages or infringement upon third party rights as a result of using
this sample program.
Use this program while conforming to the contents of the agreement listed within.
■
Example of data reading
• Operation: Reads and displays 2 word data of the set address at once.
• Function code to be used: 03H, 04H
• Number of read words: 2
' Variable Declaration ***********************************************************************
Dim idx As Integer
Dim Ansdat() As Byte ' Response data stack
Dim Rxbuff As Variant ' Received data buffer
Dim PauseTime ' Sets the communication wait time.
' The necessary wait time changes depending on the
transmission speed and transmission frame length.
Dim Stno As Byte ' Communication number
Private Sub Form_Load()
' Initializing the Variable ******************************************************************
Stno = 1
Main.Visible = True
End Sub
'------------------------------------------
'Read continuous words sample program
'Function code : 03H, 04H
'Number of words : 2
'------------------------------------------
Private Sub TX1_Click()
TX1.Enabled = False
Caution
• Windows
®
is a registered trademark of the Microsoft Corporation.
• Visual Basic
®
is a registered trademark of the Microsoft Corporation.