Serial communication between VB's host computer and PLC - Database & Sql Blog Articles

    Probe domestic PA50-J straight round head gold-plated needle has an outer diameter of 0.68. The total length of the needle is 16
    Single chip microcomputer STM32L151CCU6

    1 Introduction

    In modern control systems, the PC acts as the host computer, responsible for system management, status monitoring, data processing, and report generation. Meanwhile, the PLC functions as the lower-level device, handling real-time control tasks. This architecture has become a standard in industrial automation, making communication between the PC and PLC a critical factor in system performance. Serial communication is widely used due to its simplicity and ease of implementation, making it a popular choice for connecting these two components.

    Visual Basic (VB) is a user-friendly programming environment with strong capabilities, especially when it comes to serial communication. This article demonstrates how VB6.0 can be used to establish communication between a PC and an Omron CPM2A PLC. By leveraging the Host Link communication protocol supported by the CPM2A, this approach provides an efficient way to monitor and control the PLC from a PC.

    The Host Link protocol allows the PC to communicate with multiple PLCs through a central unit, enabling centralized management and real-time monitoring. It also supports direct communication via the RS-232 port, which is ideal for small-scale applications. This makes it a suitable solution for many industrial control scenarios where cost and complexity need to be minimized.

    2 Principle Design

    2.1 System Structure

    The system consists of a PC acting as the host computer and a PLC as the lower-level controller. Since the Omron CPM2A PLC includes an RS-232 serial port, it can be directly connected to the PC's COM1 or COM2 port using an RS-232 cable. This forms a simple point-to-point communication system that enables basic data exchange and control.

    Figure 1: System Structure

    2.2 Host Link Communication Protocol

    The Host Link communication protocol is designed to connect a PC (such as an IBM PC or compatible machine) with multiple PLCs through a Host Link unit installed on each PLC. This setup allows the upper computer to manage and monitor all connected PLCs centrally. Through communication with the Host Link unit, users can edit or modify PLC programs and monitor their execution in real time, facilitating distributed control in automated systems.

    For smaller PLCs, communication can also be established via the RS-232C port. The Host Link protocol defines a structured communication format where data is exchanged in blocks. Each block starts with a device number and command, followed by a checksum (FCS), and ends with a terminator. The response block contains the result of the executed command, ensuring accurate and reliable data transmission.

    Figure 2: Communication Frame Format

    3 Software Implementation

    3.1 MSComm Control Introduction

    The MSComm control, developed by Microsoft, is an ActiveX component that simplifies serial communication programming under Windows. It offers a straightforward way for applications to send and receive data over a serial interface. The control operates in two modes: query mode and event-driven mode. This article uses the event-driven mode for real-time data handling.

    Key properties of the MSComm control include the communication port, baud rate, parity settings, and data bits. These are typically set during development, while other properties may use default values. Proper configuration ensures smooth and error-free communication between the PC and the PLC.

    3.2 PLC Parameter Settings

    The PLC is configured to use the default Host Link communication settings: 1 start bit, 7 data bits, even parity, 2 stop bits, and a baud rate of 9600 bps. The device number is set to 00, which is essential for identifying the correct PLC during communication.

    3.3 PC Software Design

    Using the MSComm control in VB6.0, we can develop a program that communicates with the PLC through the RS-232 port. Below is a sample code snippet showing how to initialize the serial port and send/receive data:

    'Program initialization and set serial port parameters

    Private Sub Form_Load()

    MSComm.CommPort = 1

    MSComm.Settings = "9600,e,7,2"

    MSComm.InputMode = comInputText

    MSComm.PortOpen = True

    End Sub

    'Write data to PLC

    Private Sub ButWrite_Click()

    If MSComm.PortOpen = False Then

    MSComm.PortOpen = True

    End If

    Dim plcEnd As String

    plcEnd = "@00sc00"

    MSComm.Output = plcEnd + FCS(plcEnd) + "*" + Chr(13)

    MSComm.InBufferCount = 0

    Dim outString As String

    outString = "@00wr0010" & Trim(txtContent.Text)

    outString = outString + FCS(outString) + "*" + Chr(13)

    MSComm.Output = outString

    End Sub

    'Read data from PLC

    Private Sub ButRead_Click()

    If MSComm.PortOpen = False Then

    MSComm.PortOpen = True

    End If

    Dim outString As String

    outString = "@00rr00100001"

    outString = outString + FCS(outString) + "*" + Chr(13)

    MSComm.InBufferCount = 0

    MSComm.Output = outString

    Dim i As Integer

    Do While MSComm.InBufferCount <= 14 Or i > 9000

    i = i + 1

    Loop

    If i < 9000 Then

    Dim inString As String

    inString = MSComm.Input

    txtContent.Text = "Output 010 channel data is " & Mid(inString, 8, 4)

    Else

    MsgBox("Read failed")

    End If

    End Sub

    'FCS Check Function

    Function FCS(ByVal fcsStr As String) As String

    Dim slen As Integer, i As Integer, xorResult As Integer

    Dim tempFCS As String

    slen = Len(fcsStr)

    xorResult = 0

    For i = 1 To slen

    xorResult = xorResult Xor Asc(Mid(fcsStr, i, 1))

    Next i

    tempFCS = Hex(xorResult)

    If Len(tempFCS) = 1 Then tempFCS = "0" & tempFCS

    FCS = tempFCS

    End Function

    4 Conclusion

    This paper presents a practical method for developing communication programs using VB, specifically the MSComm control, to enable communication between a PLC and a PC via a common serial port. Experimental results demonstrate that the program runs stably and reliably, with a simple and intuitive interface. With minor modifications, this approach can be applied to various industrial control devices, offering significant value in small-scale automation systems.

    One Digit LED Display

    1.2 Inch Fnd Numeric Display,Indoor Fnd Numeric Display,Single Digit Fnd Numeric Display,1 Digit Fnd Numeric Display

    Wuxi Ark Technology Electronic Co.,Ltd. , https://www.arkledcn.com

    Previous Post: The living room theater is not a dream? Samsung will push 75-inch curved panel next year
    Next Post: DCS system redundancy technology implementation and analysis - Database & Sql Blog Articles
    Home
    Recent Posts
    • Basic working principle and setting method of ga…
    • Basic working principle and setting method of ga…
    • Mitsubishi PLC's internal register Daquan - …
    • The living room theater is not a dream? Samsung …
    • The living room theater is not a dream? Samsung …
    • Serial communication between VB's host compu…
    • DCS system redundancy technology implementation …
    • Serial communication between VB's host compu…
    • DCS system redundancy technology implementation …
    • Deep Neural Network (DNN) = Human cerebral corte…
    • Modbus_Simulator simulation software for small h…
    • Thermocouple's commonly used measuring tempe…
    • Thermocouple's commonly used measuring tempe…
    • Stepper motor reluctance motor static characteri…
    • Stepper motor reluctance motor static characteri…
    • Issues in the selection of DCS - Database & …
    • Issues in the selection of DCS - Database & …
    • Transformer oil quality identification method - …
    • Transformer oil quality identification method - …
    • Causes of fire and explosion in transformers - N…