The modern world is a highly automated world where a wide variety of devices can be connected to a computer, and the simplest way to automate the connection is to use serial communication.
VB provides a system program for serial communication control that allows developers to develop serial communication, and provides a number of conveniences for the user.
Plc is an indispensable part of the current control field, and it has become very popular. How to easily interact with PLC has become a new competitive battlefield for many manufacturers. This has resulted in products such as human-machine interfaces and configuration software. The production of these products greatly simplifies the control, operation and use of the PLC. But there are also common shortcomings: too high prices and poor development. As a "raw" programming language, VB has undoubtedly obvious advantages in these two aspects.
This article combines a simple case, with a relatively basic concept to show how to achieve PC-PLC communication through VB, for the engineers involved in this field, will also benefit from the basic concepts provided in this article.
First, the basic concept of serial communication
1. Types of communication: Generally, the form of communication can be divided into two types, Parallel Communication and Serial Communication. The so-called parallelism is that the amount of transmission is 8 bits at a time; and the string is only transmitted once at a time. These two different communication methods are shown in Figure
2. There are also two types of serial communication commonly used in serial communication. Respectively RS-232 and RS-485
2-1 RS-232
The signal level of RS-232 is from the reference ground. As shown in the figure, the transmitting end refers to the grounding terminal 1 to transmit data; the receiving end refers to the grounding terminal 2 to restore the signal preparation of the transmitting end.
As can be seen from the figure, since the two ground terminals are not necessarily the same, and they are easily interfered, the signal is prone to errors when transmitted on the RS-232 line.
2-2 RS-485
The signal transmission mode of RS-485 is shown in the figure.
When the RS-485 signal is transmitted, it will be divided into positive and negative lines. When it reaches the receiving end, it will be subtracted to the original signal. If the original signal is represented as (DT), it will be divided. The signals are labeled as (D+) and (D-) respectively, then DT= (D+)-(D-)
Similarly, after receiving the signal, the receiving end also restores the original appearance according to the above formula. If the line is disturbed, the signals of the two lines are (D+)+Noise (D-)+Noise. Receiver restore signal is
(DT)= [(D+)+Noise]-[ (D-)+Noise]
As with the previous results, RS-485 can effectively prevent noise interference.
Second, the basic concept of Visual Basic
1. VB is Microsoft's Windows software and provides a lot of interface members. Objects, attributes, events, and methods are four important interfaces.
2. VB common control items.
2-1 label control
This control item is dedicated to displaying text, digitally used, and displayed as shown in the figure.
2-2 button control
This control has a high usage rate and provides a button for system users to operate.
2-3 Timer Control The maximum function of this control is to execute the set program code once in a fixed time.
VB provides a large number of control items, which are not described here.
Smart Life Switch,Tuya Smart Switch,Smart Power Switch,Tuya Eu Smart Switches
Shenzhen Chaoran Technology Corp. , https://www.chaoran-remote.com