Blogger Tips and TricksLatest Tips And TricksBlogger Tricks

Thursday, 13 June 2013

PLC & Visual Basic 6.0 Communication using MSComm Control

Hi Friends Here i want to share a new post related to PLC and Visual Basic VB6.0 Communication
VB code is given below. Enjoy
“Real Time Automated Control using PLC-VB Communication”

This paper is to enable the Delta PLC (Programmable Logic Control) DVP14SS to communicate with the Visual Basic 6.0. The communication between DVP14SS and Visual Basic 6.0 is via Modbus Serial Protocol. Computers are used as a link between humans and PLC systems as they have more graphics and visual capabilities. These are nothing but SCADA systems widely used for determining plant set-ups and displaying plant status on high quality screens. They also record/log the system data for long period .The SCADA software’s are the software packages needs to be purchased from vendors and the cost depends on tag count. Visual Basic 6.0 platform can be used develop the SCADA application effectively. Using VB 6.0 we integrate software and hardware across spectrum of vendors easily. Here we show simple approach to communicate Delta PLC with visual Basic using MSComm control in visual basic. By means of Visual Basic cost effective solution is possible as Visual Basic we do not need to purchase licenses and is cheaper than SCADA packages. It also has the advantages like flexibility.

I.      Introduction
Communication has become a major part of any process control automation system. Today PLC communication is as much for data acquisition as plant control. The objective of communication is to collect or transfer large / small amount of data. Over the course of time certain interfacing standards have been generated by industry in order to make communication between systems from two different manufacturers more simple. These standards typically defined the communications medium, transmission voltages, speed of communication, (baud rate). The first such real standard was RS232. This was written by the Electronic Industries Association (EIA). The main advantage of this being cost as RS232 interfaces are very simple and thus cheap, plus of course the fact that most PCs, which are used more and more in automation systems today, have at least one RS232 (serial) interface as a standard.

Programmable Logic Controllers (PLC’s) are solid state devices using integrated circuits to control process or machines. They can store instructions like sequencing counting, timing, arithmetic, data manipulation and communication [2]. A PLC is an example of a hard real time system since output results must be produced in response to input conditions within a bounded time, otherwise unintended operation will result.PLC reads the status of the external input devices, e.g. keypad, sensor, switch and pulses, and execute by the microprocessor logic, sequential, timing, counting and arithmetic operations according the status of the input signals as well as the pre-written program stored in the PLC [5]. The generated output signals are sent to output devices as the switch of a relay, electromagnetic valve, motor drive, control of a machine or operation of a procedure for the purpose of machine automation or processing procedure.

Visual Basic (VB) is developed by Microsoft Corporation and is most widely used development environment in the world.  Visual Basic is tool provides platform to develop new optimum Windows/SCADA applications. Visual Basic can communicate with PLC with various ways. Visual Basic does not have code for communication protocol inbuilt. User need to write code for communication protocol or need to purchase ActiveX controls  which are used to develop applications. ActiveX control with Libraries can be purchased to develop application. Here we are using MSComm ActiveX control freely available in VB to establish communication with delta PLC.


II.Method of Interfacing
Delta DVP14SS comes with serial port and the communication protocol is serial Modbus protocol which is a open protocol. Visual Basic acts as a Modbus Master device which issues request or commands (Query) on serial bus which is received by slave.  PLC acts as a Modbus slave device and responds to the Master by sending massage called response. Modbus Query and Response contains fields like device address, function code, data, and error check [1]. Figure 1 shows the system block diagram. 

                                                                      Function code for Delta plc

Read Coil Status
S, Y, M, T, C
Read Input Status
S, X, Y, M,T, C
Read Holding Registers
T, C, D
Force Single Coil
S, Y, M, T, C
Preset Single Register
T, C, D
Force Multiple Coils
S, Y, M, T, C
Preset Multiple Register
T, C, D
Report Slave ID

Table 2 shows the Query format to read Input Status of contacts Y20 to Y47from slave device address 01

                                                TABLE II Query to Read input status y20 - y47
Field Name
Example (Hex)
Slave Address
Command code
Starting Address Hi
Starting Address Lo
Number of Points Hi
Number of Points Lo
Error Check ( LRC )

Table 3 shows the response from slave device to Query shown above.

                                                          TABLE III Response from slave
Field Name
Example (Hex)
Slave Address
Command code
Bytes Count
DataCoils Y033…Y024
DataCoils Y043…Y034
DataCoils Y053…Y044
DataCoils Y063…Y054
DataCoils Y070…Y064
Error CheckLRC

The PLC receives the messages without a communication error, but cannot handle it, an exception response willreturn to the master device. In the exception response, the most significant bit of the original command code is set to 1, and an exception code explains the condition that caused the exception is returned. Table 4 shows message response with exception code. [3] [4]

                                             TABLE IIV Exception response from slave
Field Name
Example (Hex)
Slave Address
Exception Code
Error Check ( LRC )

Table 5 shows different exception codes available in DVP14SS PLC [3] [4].

                                                          TABLE IIIV Exception codes
Illegal command code:
The command code received in the command message is not available for the PLC.
Illegal device address:
The device address received in the command message is not available for the PLC.
Illegal device value:
The device value received in the command message is not available for the PLC.
Check Sum Error
Check if the check Sum is correct
Illegal command messages
The command message is too short.
Command message length is out of range.

Visual Basic has ActiveX MSComm control 6.0 to send andreceive ASCII characters on communication port. MSCommcontrol added through the project component menu as shown in fig 2.
MSComm control is a drag and drop tool and can be accessed, handled with its properties and event handler. 

Following steps are implemented to obtain desired objective.
A.    Knowing  the Modbus Protocol for Delta PLC DVP14SS series MPU support Modbus ASCII/RTU communication format with speed of up to 115,200bps. and modification on data length (data bits, parity bits, stop bits).Modbus communication format ,CRC calculation ,Modbus addressing for various internal devices of PLC are the key factor in the  interface. Communication parameters for COMcan be manipulated by writing ladder program. Here we use default protocol settings hence we do not alter PLC program. [4]
B.    Writing Visual Basic code for MSComm Control
Designing windows form in visual basic as shown in fig 4. Form contains controls like Timer, MSComm Control, Button, textbox etc.

OnComm () event in MSComm control is used to receive response from slave PLC.

Dim strRx As String
    Select Case MSComm1.CommEvent
        Case comEvReceive
        Case comEvEOF
strRx = MSComm1.Input

Similarly MSComm.output property is used to send ASCII characters through serial port.

For Index = 0 To Len(txtWrite.Text) – 1
sendArr(Index) = Asc(Mid(txtWrite.Text, Index + 1, 1))
           sendArr(Index) = &HD
           sendArr(Index + 1) = &HA
           strRx = ""
            MSComm1.Output = sendArr
Do While True
        If MSComm1.InBufferCount > 0 Then
strRx = strRx + MSComm1.Input
            If Len(strRx) > 2 Then
 If Asc(Mid(strRx, Len(strRx) - 1, 1)) = &HD And Asc(Mid(strRx, Len(strRx), 1)) = &HA Then
                    Text1.Text = Mid(strRx, 1, Len(strRx) - 2)
                    Exit Do
                End If
            End If


Fig 5 shows GUI developed using VB and results of serial communication between DVP14SS PLC and PC.

The main idea was to interface Visual Basic 6.0 and Delta PLC DVP14SS for moreeffective and efficient process control.  This project ofinterfacing establishes communication between two powerful  technologies used in industries. Visual Basic provides a platform where new solutions or highly customized  SCADA's can be created with a richer experience than those that may be provided by standard SCADA offerings.  By using Visual Basic it offers many advantages over   SCADA packages as it comes free and not expensive. Also SCADA packages cost depend on the tag count and runtime licenses needs to be purchased. Thus for OEM Visual Basic offers the optimum solution.
Thus the PLC has been interfaced with Visual Basic 6.0 and several real time processes have been controlled.

[1]           “Modbus communication Manual,” MTL 8000 process control for process I/O ,The MTL Instruments Group PLC, England
[2]           NaregalkarAkshay.,Real Time Automated Control of Industrial Pocesses with PLC –LABVIEW Communication,.Ibrahimpatnam, Hyderabad, India, Issue-1, Volume-1 ,035-038
[3]           “DVP PLC communication Protocol,” Delta Electronics Inc,
[4]            “DVP PLC Application Manual,” Delta Electronics Inc,
[5]           T.Kalaiselvi, R.Praveena ,Aakanksha.R,, Dhanya.S, “PLC Based Automatic Bottle Filling and Capping System With User Defined Volume Selection,” IJETAE., Volume 2, Issue 8, August 2012.


Blog Widget by LinkWithin


Subscribe To Get FREE Tutorials! And More....


PLC Ladder PLC Practice Problem PLC Ladder Programming training & tutorials Free Training on PLC Ladder Programming training & tutorials PLC Ladder Logic PLC Timer SCADA Basic PLC Ladder Programming Examples Delta PLC PLC & Visual Basic Communication PLC Definition Introduction PLC Error PLC Error LED RSLinx Tutorial Types of Timers in PLC ladder logic Programming programmable Logic Controllers AB addressing ABB AC Drive AC Drive training cource Actuators Advantages and Disadvantages Addressing of Allen Bradley PLC Micrologix 1000 Addressing of Delta PLC DVP SS/ES/EX Addressing of Mitsubishi PLC FX2N Addressing of Modicon PLC Micro TSX 3722 Addressing of Siemens PLC S7 200 Advantages & Disadvantages of RTD Advantages & Disadvantages of all types Sensors Advantages of SCADA Allen Bradley PLC PWM (Pulse Width Modulation) error codes Allen Bradley SLC Controller Error Codes Ampere Voltage Ratings of circuit brakers Analog addressing Allen bradley Analog input in Allen Bradley PLC Applications of Sensors Capacitive Proximity Sensors blck diagram Capacitive proximity sensors Circuit brakers Circuit diagram of motor starter Communication Between two E1000 HMI and mitsubishi Fx2n PLC Communication between FX3U PLC and SCADA via RS485BD Configuring the DF1 Driver using RSLinx Configuring the Ethernet Driver Connection between 2 E-Terminals and FX2N PLC. DOL Motor Starter PLC logic DOP Series Human Machine Interface DVP14ss Delta HMI Delta HMI Program Download.Delta HMI Communication Cable Delta HMI and RS485 Communication Delta MMI Delta PLC Projects Delta PLC input output addressing Different types of Special motor Diffrence between PLC and DCS Ebook on Basics of Allen Bradley PLC pdf Ebook on Basics of Siemens PLC pdf Ebook on Basics of VFD PDF download Electrical maintenannce tips Electromagnetic relay Error Messages from RSLogix Emulate 500 Failsafe meaning Features of Delta HMI/MMI Following are the Free PLC Software's available from all leading brands such as Allen Bradley Free PLC Ebooks Free PLC SCADA TRAINNING & TUTORIAL Free PLC Training Full form of HART HART OSI reference model HART protocol structure HMI & ZIGBEE How Capacitive Proximity Sensors Works? How Inductive Proximity Sensor Works? How Ultrasonic Sensors Works? How to Select a Suitable Motor How to Select the Right VFD (Inverter) or AC Motor Drive Ladder Logic for AND Ladder Program for Automatic Door open close Ladder Programs for Gates List of Top Most Widely used PLC’s in the Industry List of Widley used PLC Companies. Low cost Wireless I/O’s using PLC Mitsubishi Mitsubishi PLC FX2N & HMI E1000 Networking using BDTP Technology Mitsubishi PLC input output addressing Modbus Communication Modbus Ethernet Modbus Serial Modbus.dll for Visual Basic Mormally open Contact Normally Close Contact Explained Motion Actuators Motor starter in control circuit NAND NO NC Explained NOR Gates with Truth Tables Nashik Nexgenie PLC Features Nexgenie PLC Port Nexgenie PLC input output OFF Delay Timer OLE for Process and Control ON Delay Timer OR Omron On line Ladder Program Editing for RSLogix 500 On line Ladder changes Online Editing Ladder Program Online Servo tuning PID Control Instruction PID PLC PID instruction in Allen Bradley PLC PLC & VB PLC Counter PLC Error Allen Bradley PLC Error messages in Allen Bradley PLC FBD PLC Fault PLC Industrial Automation Training Institute PLC ON Delay Timer PLC Run Led PLC SCADA Communication PLC SCADA DCS Training Centers PLC SCADA Driver PLC SCADA Training Chennai PLC and ZIGBEE PLC application PLC based Automated Guided Vehicle PLC based Final year Project PLC based Line follower robot PLC based Project Report PLC functional Block Diagram PLC input wiring PLC interview Question PLC interview questions PLC maiintence PLC power LED PLC program for star delta starter PLC retentive timer PLC training in Delhi PLC training in Mumbai PLC training in Pune PTO Allen Bradley PTO [Pulse Train Output] Instruction in Allen Bradley PLC Photoelectric Sensor Applications Photoelectric Sensor Applications in Automation industry Power cable Selection Proficy HMI/SCADA Cimplicity 8.1 Programming Languages for PLC Proximity sensor application Push to ON PUSH to OFF PLC program using NO NC and Coil Pwm RSLinx Tutorial | Configuring the DF1 Driver RSLinx Tutorial | Configuring the Ethernet Driver Scaling Analog Input using SCL Instruction in PLC [Scale Data] Schneider Schneider PLC addressing Selction of Servo Motor Selction of Stepper Motor Selection of AC Motor Selection of VFD Selection of stepper or Servo Motor Sensor applications Servo Motor Servo auto tuning Parameters Siemens Siemens input output addressing Signal Cables selection Simatic Wincc SCADA Single Push button to on and off motor Sinking and sourcing operations Softwares used in SCADA Solid State Relay construction Solid State Relay uses and Advantages Sourcing and Sinking Concept in PLC Standard Wiring Color Codes Stepper Motor Applications and Advantages Disadvantages Stepper application Stepper motor Selection Stepper motor and PLC Tag in SCADA Temperature sensors used with PLC Theory of Capacitive Proximity Sensors Theory of Ultrasonic Sensors Theory or Operation of Inductive Proximity Sensors Thermistor & Temp IC Sensors Thermocouple Trial Run of PLC Troubleshooting Allen Bradley PLC with RSLogix Emulate 500 Troubleshooting Tips for Electrical /Electronic Maintenance Tutorial on PLC Types of Actuators Types of Actuators used for Motion in Automation with Advantages & Disadvantages Types of Sensors Types of Timers in PLC | ON Delay Timer (TON) Typical circuit diagram of Star Delta starter Ultrasonic Sensor Applications Ultrasonic sensors Unitronics VB 6.0 and PLC VIsual Basic as SCADA What is HART What is SCADA (Supervisory Control And Data Acquisition) What is SMART Communication What is a PLC ? What is DCS? What is the difference between PLC and Microcontroller? XIO [Examine if Open] & XIC [Examine if Closed] Explained advantages & disadvantages of Servo Motors anlog input addressing DELTA PLC anlog input addressing Mitsubishi PLC anlog input addressing siemens automation training comparison of PLC and DCS connecting field devices to Programmable Logic Controllers contact reting of relay design of fail safe systems digital common ground connections distributed control system drawbacks of Servo Motor fail safe PLC Redundancy modbus examples noise in cables one input one output PLC program using NO NC logic opc overload relay operation photoelectric plc Response Time plc output wiring plc program for TV remote plc training programmable Logic Controllers List relay coil rating relay driving circuit relay isolation voltage selection of relay servo basics servo training star delta starter control wiring diagram types of Counter typical circuit diagram of Direct on line starter