Implementing serial communication between BC8000 and PC using VB.NET
2026-04-06 06:23:33··#1
Abstract: In modern industrial control, the controller acts as the lower-level machine to complete the acquisition, processing, and control of various signals and data in the field, while the upper-level machine provides a human-machine interface to realize data processing, real-time display of field data, and other monitoring and remote control functions. This paper introduces the principle and method of serial communication between the BC8000 bus terminal controller and the upper-level machine using VB.NET. Keywords: VB.NET; Serial Port Communication; SerialPort Control; BC8000 [align=center]Study on COM Port Communication between BC8000 and PC Based on VB.NET DENG Hua-chang, FANG Kang-ling, LIANG Kai, ZHANG Peng[/align] Abstract: In the fields of modern industrial control, PLC is used to collect, calculate, and control all kinds of signals and data, while the host computer can provide a mutual interface, realizing the functions of managing data and long-distance control. This paper introduces the theory and method of COM port communication between BC8000 and host computer based on VB.NET. Key Words: VB.NET; COM port communication; SerialPort; BC8000 The communication problem between a PC and a controller has always been a hot topic in the industry, widely used in industrial control systems, intelligent detection systems, data acquisition systems, etc. Two communication methods are commonly used between a PC and a controller: parallel communication and serial communication. Parallel communication refers to transmitting all bits of data simultaneously. Serial communication transmits data bit by bit sequentially. Parallel communication, while offering high transmission efficiency and speed, suffers from poor reliability, requires complex hardware, and is unsuitable for long-distance communication. Therefore, it is generally only applicable to systems demanding high real-time performance and transmission rates, limiting its practical application. In contrast, serial communication, although slower and less efficient, boasts high reliability, ease of implementation, and longer transmission distances, making it widely used in various scenarios, particularly suitable for communication between computers and controllers. Currently, software for implementing serial communication includes VC++ and VB6.0. VC++ is relatively weak in handling graphics, and training a skilled VC++ designer can be time-consuming. VB6.0 offers advantages such as ease of use, short learning curve, and rich graphics, but it is unsuitable for high-speed, high-efficiency automated monitoring systems. VB.NET, Microsoft's latest integrated development environment, is powerful, user-friendly, truly object-oriented (32-bit), and easy to learn and use, making it popular and widely used in various fields. This article will introduce how to use VB.NET to implement serial communication between a BC8000 and a PC. 1. BC8000 Serial Communication 1.1 Introduction to BC8000 The BC8000 is a bus terminal controller manufactured by BECKHOFF GmbH, Germany. A bus terminal controller is a bus coupler with PLC functionality. The BC8000 controller is approximately 100mm long, 47mm wide, and 68mm high, with bus terminals approximately 12mm wide. It can be expanded with up to 64 bus terminals. Its small size makes it unparalleled in environments with strict space requirements. It can also be easily embedded into various instruments. Due to its compact structure, easy installation, stable performance, and low price, it is widely used. The BC8000 has a built-in peripheral port (RS485), which can be directly connected to a PC for data transmission via an RS485/232 converter. Figure 1: [align=center] Figure 1 Connection Diagram of PC and BC8000[/align] 1.2 Communication Settings The initialization of the RS485 communication mode of the BC8000 is achieved by modifying the communication parameters in registers 32, 33, and 34 of table 001 of the controller via KS2000 to set the baud rate, parity, stop bits, and data bits: Register 32 sets the baud rate as follows: 0: 38400, 1: 19200, 2: 9600, 3: 57600, 4: 1200, 5: 2400, 6: 4800. Register 33 sets the mode as follows: 0: 7 data bits, even parity, 1: 7 data bits, odd parity, 2: 8 data bits, no parity, 3: 8 data bits, even parity, 4: 8 data bits, odd parity. Register 34 sets the stop bits as follows: 0: 1 stop bit, 1: 2 stop bits. After configuring RS485 communication mode, add the serial communication library in TwinCAT's Library Manager and call the following commands to send and receive data: (1) SendData command. This command can be used to send data conveniently. One or more bytes can be sent, up to a maximum of 255 bytes of data. (2) ReceiveData command. This command can be used to receive information conveniently. One or more bytes can be received, up to a maximum of 255 bytes of data. After programming, set the address selection switch of BC8000 to 99 (master mode) to transmit data. 2 Implementation of serial communication on the VB.NET platform Visual Basic.NET is one of the main components of the Microsoft Visual Studio.NET suite and is one of the most dynamic programming languages under the current Microsoft .NET architecture. It adds many new object-oriented features on the basis of VB6.0, such as encapsulation, inheritance, and object-oriented, which greatly enhances the functionality of VB. VB.NET supports object-oriented programming, multi-threaded processing, structured exception handling and other technologies, which can effectively ensure the stability and efficiency of the software. Meanwhile, VB.NET, under the Microsoft .NET framework, can conveniently and efficiently connect to and operate with SQL Server databases. Therefore, implementing serial communication using VB.NET has practical significance. 2.1 VB.NET Communication Implementation Methods There are two common methods for implementing serial communication using VB.NET: one is to write serial communication code using API functions, but the program is complex and can achieve more powerful functions, suitable for in-depth development; the other is to directly use controls. In versions prior to VS2005, the serial communication control was Mscomm, while in VS2005 it was upgraded to SerialPort. This control has rich properties and events closely related to serial communication, providing various operations on the serial port, and is convenient and easy to use. 2.2 SerialPort Control Properties The class containing this control is the latest one introduced by Microsoft in Microsoft .NET Framework 2.0. The main properties and driving events of this control are described below: BaudRate: Sets the baud rate. DataBits: Data bits. Modifiers: Inherited property control, its enumeration values are Public, Protected, Protected Friend, Friend, Private. Parity: Verification attribute, its enumeration values are None, Odd, Even, Mark, Space. PortName: Serial port number, corresponding to CommPort in the Mscomm control. Read: Reads data from the buffer, corresponding to Input in the Mscomm control. ReadBufferSize: Size of the receive buffer. ReceivedBytesThreshold: A DataReceived event is generated when a character is received in the receive buffer. StopBits: Stop bits. Write: Writes data to the buffer. WriteBufferSize: Size of the send buffer. DataReceived event: The most important event of SerialPort, where data can be processed. 2.3 Communication Program Design for the Host Computer Due to the very convenient interface design features of the VB.NET programming language, a consistent and user-friendly form interface can be quickly created. When using the SerialPort control, programmers only need to set and monitor its properties and events to complete the initialization of the serial port and the transmission of data. Field data is transmitted to the PC in real time through the standard RS232 serial interface, and the function of displaying field data is realized. The main program example is as follows: Public Class Form1 Dim buffB(50) As Byte 'Serial port receive buffer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort1.BaudRate = 9600 'Baud rate setting SerialPort1.PortName = "com1" 'Port setting If SerialPort1.IsOpen = False Then SerialPort1.Open() 'Open serial port End Sub Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived SerialPort1.Read(buffB, 0, 50) BeginInvoke(New EventHandler(Address Of function), SerialPort1.BytesToRead()) 'Receive string End Sub Sub function(ByVal sender As System.Object, ByVal e As System.EventArgs) TextBox1.Text = Encoding.ASCII.GetString(buffB, 0, 30) 'Display End Sub End Class 3 Application Example In the data monitoring system of Guizhou Shuigang No.2 Rolling Mill, it is necessary to collect real-time data such as the type and quantity of rolled steel through serial port, and process and record the collected data to provide a basis for operators to arrange production. The above system was designed and the running result is shown in Figure 2 below: [align=center] Figure 2 Data monitoring system running screen[/align] 4 Conclusion This paper uses VB.NET to implement serial communication between the BC8000 bus terminal controller and the host computer, and illustrates the effectiveness of this method through a practical application. The application of serial communication between the programmable logic controller and the host computer can effectively improve the overall automation level of the control system. It provides an effective solution for data transmission in small-scale automatic control systems. References [1] RS485 Bus coupler BC8000[S]. BECKHOFF New Automation Technology. 2006. [2] Tian Yuan, Li Suruo et al. VB.NET Programming[M]. Beijing: Beijing Jiaotong University Press, 2006. [3] Fan Yizhi, Liao Jinqi et al. Visual Basic.NET Automation System Monitoring—RS-232 Serial Communication[M]. Beijing: China Youth Press, 2002. [4] Chen Jianbo, Shi Dongwen, Xi Danli et al. Design and Implementation of Mine Wastewater Monitoring System Based on VB.NET[J]. Coal Mine Machinery. 2004, 10: 57-59. [5] Huang Weihua, Fang Kangling, Zhou Hongjun et al. Industrial Remote Monitoring System Based on KingSCADA and VB[J]. Metallurgical Automation. 2005, 2: 60: 62