SlideShare a Scribd company logo
1 of 31
How To Implement
Modbus TCP Protocol Using VBA
with Excel
ACC Automation
Objectives
 Visual Basic for Applications (VBA) to
communicate to a PLC using Modbus TCP
protocol.
 Reading ten registers in the PLC and
displaying a bar graph in Excel.
Steps to be done:
1.Explain Modbus TCP protocol
2.Install OstroSoft Winsock Component –
Winsock API Calls for communication on
network
3.Develop the Excel and VBA application
(Microsoft Excel 2010)
4.Communicate to the PLC and sample code
(Do-More Simulator)
1 – Explain Modbus TCP
Modbus TCP is a Protocol that is used for
communications over TCP/IP networks.
This is done on port 502. Modbus TCP does not require
a checksum calculation as lower layers already
provide checksum protection.
You can think of this as a letter being sent and Ethernet
TCP/IP acts like an envelope for the Modbus
Commands.
Here are some links to references:
Introduction to Modbus TCP/IP
Simply Modbus – Modbus TCP
2 – Install OstroSoft Winsock
OSWINSCK.dll serves as a wrapper for the
Winsock API and helps programmers to
abstract from the complexity of API calls and
focus on application functionality. Works with
programming and scripting languages
supporting COM.
You will need to download and install the
OstroSoft Winsock Component on your
computer.
2 – Install OstroSoft Winsock
For use with .NET, Visual Basic 4 or 5, Visual
C++, ASP, VBA, VBScript, JavaScript or any
other language, supporting COM:
1. Download oswinsck.exe
2 – Install OstroSoft Winsock
2. Run downloaded file from Windows Explorer
or command-line
2 – Install OstroSoft Winsock
Hit OK
I use the default directories where the program
will be installed. Click the button to install.
2 – Install OstroSoft Winsock
Leave the program group to the default so I know what the
program is after installation. Click continue.
2 – Install OstroSoft Winsock
Click OK
The OstroSoft Winsock Component is now
installed.
3 Excel and VBA Application
(Microsoft Excel 2010)
Start Microsoft Excel.
3 Excel and VBA Application
(Microsoft Excel 2010)
Select ‘Developer’ along the top tabs.
3 Excel and VBA Application
(Microsoft Excel 2010)
If the Developer tab is not present then we must turn on
the developer tab.
Select File | Options
3 Excel and VBA Application
(Microsoft Excel 2010)
Select ‘Customize Ribbon’
3 Excel and VBA Application
(Microsoft Excel 2010)
Check the ‘Developer’ under Main Tabs.
3 Excel and VBA Application
(Microsoft Excel 2010)
Under the Developer menu. Select ‘Visual
Basic’
3 Excel and VBA Application
(Microsoft Excel 2010)
The Visual Basic Editor window will now be
displayed.
3 Excel and VBA Application
(Microsoft Excel 2010)
From the menu – Tools | References
We can now add the OstroSoft Winsock Component
to our application.
Select OK
3 Excel and VBA Application
(Microsoft Excel 2010)
Select Sheet1(Sheet1).
3 Excel and VBA Application
(Microsoft Excel 2010)
Now put the visual basic code in the
Sheet1(Sheet1)
The code can be downloaded here:
3 Excel and VBA Application
(Microsoft Excel 2010)
 Note: The program utilizes the CHR and
STR functions to convert the data from binary
to ASCII and back.
The highest value of a byte of data is 256.
This is why we have to multiply the highest
significant byte with 256
3 Excel and VBA Application
(Microsoft Excel 2010)
Interface:
Go back to Sheet1 and we can now put on
the worksheet what we would like to see.
Note the following:
IP Address = B4
MHR 1 to 10 values located at B10 to B19
‘Stop Data’ – CommandButton2
‘Retrieve Data’ – CommandButton1
3 Excel and VBA Application
(Microsoft Excel 2010)
4 Communicate to the PLC
(Do-More Simulator)
The software can be downloaded from the
following URL:
http://support.automationdirect.com/products/d
omore.html
Start the Do-More Designer software.
Under the Project Browser select ‘System
Configuration’
4 Communicate to the PLC
(Do-More Simulator)
4 Communicate to the PLC
(Do-More Simulator)
Make note of the IP address. If you are running
the simulator then this is automatically filled
in.
4 Communicate to the PLC
(Do-More Simulator)
Ensure that the Enable Modbus/TCP Server is
checked. Also make sure that the TCP Port
Number is 502.
4 Communicate to the PLC
(Do-More Simulator)
The sample PLC program will write values in the range from 0 to
4000. These values will be put in MHR 1 to MHR 10.
Here is the first couple of rungs of the PLC program. It will use
clock bit flags to increment the MHR 1 channel. When it gets to
the value above 4000, a move instruction will put a 0 back into
MHR 1.
If input X0 turns on then the value in XW0 will be moved into
MHR1 and the previous clock bit will not be in effect. Values will
be between 0 and 4096. (12 bit resolution)
This is repeated with different internal clock bit flags up to
MHR10.
4 Communicate to the PLC
(Do-More Simulator)
4 Communicate to the PLC
(Do-More Simulator)
Running the program will produce the following:
ACC Automation
Additional information can be obtained from our
website:
How to Implement Modbus TCP Protocol using
VBA with Excel - Video
Additional Information:
Excel – Conditional Movement of Data

More Related Content

What's hot

Modbus Protocol Introduction
Modbus Protocol IntroductionModbus Protocol Introduction
Modbus Protocol IntroductionPratik Vyas
 
Modbus Based Data Acquisition
Modbus Based Data AcquisitionModbus Based Data Acquisition
Modbus Based Data AcquisitionICP DAS USA, Inc.
 
Modbus Data Communication Systems
Modbus Data Communication SystemsModbus Data Communication Systems
Modbus Data Communication SystemsLiving Online
 
Ccna Presentation
Ccna PresentationCcna Presentation
Ccna Presentationbcdran
 
HART protocol for network data communication
HART protocol for network data communicationHART protocol for network data communication
HART protocol for network data communicationAmol Dudhate
 
NETWORK INTERFACE CARD™
NETWORK INTERFACE CARD™NETWORK INTERFACE CARD™
NETWORK INTERFACE CARD™UzumakiMugiwara
 
Industrial Networking - Profibus
Industrial Networking - ProfibusIndustrial Networking - Profibus
Industrial Networking - ProfibusYogesh Kumar
 
Hart - Highway Addressable Remote Transducer Protocol
Hart - Highway Addressable Remote Transducer ProtocolHart - Highway Addressable Remote Transducer Protocol
Hart - Highway Addressable Remote Transducer ProtocolVasanthan Ravichandran
 
Report on ip addresses
Report on ip addressesReport on ip addresses
Report on ip addressesAmandeep Kaur
 

What's hot (20)

Modbus Protocol Introduction
Modbus Protocol IntroductionModbus Protocol Introduction
Modbus Protocol Introduction
 
Modbus Based Data Acquisition
Modbus Based Data AcquisitionModbus Based Data Acquisition
Modbus Based Data Acquisition
 
Modbus Data Communication Systems
Modbus Data Communication SystemsModbus Data Communication Systems
Modbus Data Communication Systems
 
Ccna Presentation
Ccna PresentationCcna Presentation
Ccna Presentation
 
HART protocol for network data communication
HART protocol for network data communicationHART protocol for network data communication
HART protocol for network data communication
 
Introduction to PROFINET - Derek Lane of Wago
Introduction to PROFINET -  Derek Lane of WagoIntroduction to PROFINET -  Derek Lane of Wago
Introduction to PROFINET - Derek Lane of Wago
 
NETWORK INTERFACE CARD™
NETWORK INTERFACE CARD™NETWORK INTERFACE CARD™
NETWORK INTERFACE CARD™
 
Industrial Networking - Profibus
Industrial Networking - ProfibusIndustrial Networking - Profibus
Industrial Networking - Profibus
 
Hart - Highway Addressable Remote Transducer Protocol
Hart - Highway Addressable Remote Transducer ProtocolHart - Highway Addressable Remote Transducer Protocol
Hart - Highway Addressable Remote Transducer Protocol
 
Profibus
ProfibusProfibus
Profibus
 
Communication protocols
Communication protocolsCommunication protocols
Communication protocols
 
Profibus
ProfibusProfibus
Profibus
 
NETWORK INTERFACE CARD
NETWORK INTERFACE CARDNETWORK INTERFACE CARD
NETWORK INTERFACE CARD
 
C1 profinet design, pete brown
C1 profinet design, pete brownC1 profinet design, pete brown
C1 profinet design, pete brown
 
CPLDs
CPLDsCPLDs
CPLDs
 
IoT Wireless Technologies
IoT Wireless TechnologiesIoT Wireless Technologies
IoT Wireless Technologies
 
Introduction to PROFIBUS and PROFINET - andy verwer
Introduction to PROFIBUS and PROFINET -  andy verwerIntroduction to PROFIBUS and PROFINET -  andy verwer
Introduction to PROFIBUS and PROFINET - andy verwer
 
Hard ip based SoC design
Hard ip based SoC designHard ip based SoC design
Hard ip based SoC design
 
Report on ip addresses
Report on ip addressesReport on ip addresses
Report on ip addresses
 
As 0201-gauge-valves-and-pressure-gauge-accessories-en
As 0201-gauge-valves-and-pressure-gauge-accessories-enAs 0201-gauge-valves-and-pressure-gauge-accessories-en
As 0201-gauge-valves-and-pressure-gauge-accessories-en
 

Similar to How to Implement Modbus TCP Protocol using VBA with Excel

Interfacing of Any PLC to Lab VIEW using Modbus Protocol
Interfacing of Any PLC to Lab VIEW using Modbus ProtocolInterfacing of Any PLC to Lab VIEW using Modbus Protocol
Interfacing of Any PLC to Lab VIEW using Modbus ProtocolIRJET Journal
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Rich Helton
 
Lab jam websphere message broker labs
Lab jam   websphere message broker labsLab jam   websphere message broker labs
Lab jam websphere message broker labsEng Binary
 
Cloud and computing
Cloud and computingCloud and computing
Cloud and computingAneesSaka
 
Mfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-stepMfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-stepnamtranvanpt
 
communicate with instrument by using lan
communicate with instrument by using lancommunicate with instrument by using lan
communicate with instrument by using lanAbdosalam Arif
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basicTechglyphs
 
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...Yenlo
 
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...WSO2
 
Accelerating your application development with IBM BlueMix (Your dream devel...
Accelerating your application development with IBM BlueMix (Your dream devel...Accelerating your application development with IBM BlueMix (Your dream devel...
Accelerating your application development with IBM BlueMix (Your dream devel...Supal Chowdhury
 
Microsoft az-104 Dumps
Microsoft az-104 DumpsMicrosoft az-104 Dumps
Microsoft az-104 DumpsArmstrongsmith
 
Creating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisherCreating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisherSamchi Fouzee
 
First fare 2010 lab-view creating custom dashboards
First fare 2010 lab-view creating custom dashboardsFirst fare 2010 lab-view creating custom dashboards
First fare 2010 lab-view creating custom dashboardsOregon FIRST Robotics
 
March 2018 Patch Tuesday Ivanti
March 2018 Patch Tuesday IvantiMarch 2018 Patch Tuesday Ivanti
March 2018 Patch Tuesday IvantiIvanti
 
IT 200 Network DiagramBelow is the wired network configurat.docx
IT 200 Network DiagramBelow is the wired network configurat.docxIT 200 Network DiagramBelow is the wired network configurat.docx
IT 200 Network DiagramBelow is the wired network configurat.docxpriestmanmable
 
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0Thomas Conté
 
Dot Net Training Dot Net35
Dot Net Training Dot Net35Dot Net Training Dot Net35
Dot Net Training Dot Net35Subodh Pushpak
 
Charles Jardine CV reduced v21
Charles Jardine CV reduced v21Charles Jardine CV reduced v21
Charles Jardine CV reduced v21Charles Jardine
 
Tag Integration with Schneider Electric PLCs and Modbus in InduSoft Web Studio
Tag Integration with Schneider Electric PLCs and Modbus in InduSoft Web StudioTag Integration with Schneider Electric PLCs and Modbus in InduSoft Web Studio
Tag Integration with Schneider Electric PLCs and Modbus in InduSoft Web StudioAVEVA
 
William Impey CV
William Impey CVWilliam Impey CV
William Impey CVWill Impey
 

Similar to How to Implement Modbus TCP Protocol using VBA with Excel (20)

Interfacing of Any PLC to Lab VIEW using Modbus Protocol
Interfacing of Any PLC to Lab VIEW using Modbus ProtocolInterfacing of Any PLC to Lab VIEW using Modbus Protocol
Interfacing of Any PLC to Lab VIEW using Modbus Protocol
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
 
Lab jam websphere message broker labs
Lab jam   websphere message broker labsLab jam   websphere message broker labs
Lab jam websphere message broker labs
 
Cloud and computing
Cloud and computingCloud and computing
Cloud and computing
 
Mfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-stepMfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-step
 
communicate with instrument by using lan
communicate with instrument by using lancommunicate with instrument by using lan
communicate with instrument by using lan
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basic
 
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
 
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
WSO2 Guest Webinar - ESB meets IoT, a Primer on WSO2 Enterprise Service Bus (...
 
Accelerating your application development with IBM BlueMix (Your dream devel...
Accelerating your application development with IBM BlueMix (Your dream devel...Accelerating your application development with IBM BlueMix (Your dream devel...
Accelerating your application development with IBM BlueMix (Your dream devel...
 
Microsoft az-104 Dumps
Microsoft az-104 DumpsMicrosoft az-104 Dumps
Microsoft az-104 Dumps
 
Creating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisherCreating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisher
 
First fare 2010 lab-view creating custom dashboards
First fare 2010 lab-view creating custom dashboardsFirst fare 2010 lab-view creating custom dashboards
First fare 2010 lab-view creating custom dashboards
 
March 2018 Patch Tuesday Ivanti
March 2018 Patch Tuesday IvantiMarch 2018 Patch Tuesday Ivanti
March 2018 Patch Tuesday Ivanti
 
IT 200 Network DiagramBelow is the wired network configurat.docx
IT 200 Network DiagramBelow is the wired network configurat.docxIT 200 Network DiagramBelow is the wired network configurat.docx
IT 200 Network DiagramBelow is the wired network configurat.docx
 
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
 
Dot Net Training Dot Net35
Dot Net Training Dot Net35Dot Net Training Dot Net35
Dot Net Training Dot Net35
 
Charles Jardine CV reduced v21
Charles Jardine CV reduced v21Charles Jardine CV reduced v21
Charles Jardine CV reduced v21
 
Tag Integration with Schneider Electric PLCs and Modbus in InduSoft Web Studio
Tag Integration with Schneider Electric PLCs and Modbus in InduSoft Web StudioTag Integration with Schneider Electric PLCs and Modbus in InduSoft Web Studio
Tag Integration with Schneider Electric PLCs and Modbus in InduSoft Web Studio
 
William Impey CV
William Impey CVWilliam Impey CV
William Impey CV
 

Recently uploaded

Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

How to Implement Modbus TCP Protocol using VBA with Excel

  • 1. How To Implement Modbus TCP Protocol Using VBA with Excel ACC Automation
  • 2. Objectives  Visual Basic for Applications (VBA) to communicate to a PLC using Modbus TCP protocol.  Reading ten registers in the PLC and displaying a bar graph in Excel.
  • 3. Steps to be done: 1.Explain Modbus TCP protocol 2.Install OstroSoft Winsock Component – Winsock API Calls for communication on network 3.Develop the Excel and VBA application (Microsoft Excel 2010) 4.Communicate to the PLC and sample code (Do-More Simulator)
  • 4. 1 – Explain Modbus TCP Modbus TCP is a Protocol that is used for communications over TCP/IP networks. This is done on port 502. Modbus TCP does not require a checksum calculation as lower layers already provide checksum protection. You can think of this as a letter being sent and Ethernet TCP/IP acts like an envelope for the Modbus Commands. Here are some links to references: Introduction to Modbus TCP/IP Simply Modbus – Modbus TCP
  • 5. 2 – Install OstroSoft Winsock OSWINSCK.dll serves as a wrapper for the Winsock API and helps programmers to abstract from the complexity of API calls and focus on application functionality. Works with programming and scripting languages supporting COM. You will need to download and install the OstroSoft Winsock Component on your computer.
  • 6. 2 – Install OstroSoft Winsock For use with .NET, Visual Basic 4 or 5, Visual C++, ASP, VBA, VBScript, JavaScript or any other language, supporting COM: 1. Download oswinsck.exe
  • 7. 2 – Install OstroSoft Winsock 2. Run downloaded file from Windows Explorer or command-line
  • 8. 2 – Install OstroSoft Winsock Hit OK I use the default directories where the program will be installed. Click the button to install.
  • 9. 2 – Install OstroSoft Winsock Leave the program group to the default so I know what the program is after installation. Click continue.
  • 10. 2 – Install OstroSoft Winsock Click OK The OstroSoft Winsock Component is now installed.
  • 11. 3 Excel and VBA Application (Microsoft Excel 2010) Start Microsoft Excel.
  • 12. 3 Excel and VBA Application (Microsoft Excel 2010) Select ‘Developer’ along the top tabs.
  • 13. 3 Excel and VBA Application (Microsoft Excel 2010) If the Developer tab is not present then we must turn on the developer tab. Select File | Options
  • 14. 3 Excel and VBA Application (Microsoft Excel 2010) Select ‘Customize Ribbon’
  • 15. 3 Excel and VBA Application (Microsoft Excel 2010) Check the ‘Developer’ under Main Tabs.
  • 16. 3 Excel and VBA Application (Microsoft Excel 2010) Under the Developer menu. Select ‘Visual Basic’
  • 17. 3 Excel and VBA Application (Microsoft Excel 2010) The Visual Basic Editor window will now be displayed.
  • 18. 3 Excel and VBA Application (Microsoft Excel 2010) From the menu – Tools | References We can now add the OstroSoft Winsock Component to our application. Select OK
  • 19. 3 Excel and VBA Application (Microsoft Excel 2010) Select Sheet1(Sheet1).
  • 20. 3 Excel and VBA Application (Microsoft Excel 2010) Now put the visual basic code in the Sheet1(Sheet1) The code can be downloaded here:
  • 21. 3 Excel and VBA Application (Microsoft Excel 2010)  Note: The program utilizes the CHR and STR functions to convert the data from binary to ASCII and back. The highest value of a byte of data is 256. This is why we have to multiply the highest significant byte with 256
  • 22. 3 Excel and VBA Application (Microsoft Excel 2010) Interface: Go back to Sheet1 and we can now put on the worksheet what we would like to see. Note the following: IP Address = B4 MHR 1 to 10 values located at B10 to B19 ‘Stop Data’ – CommandButton2 ‘Retrieve Data’ – CommandButton1
  • 23. 3 Excel and VBA Application (Microsoft Excel 2010)
  • 24. 4 Communicate to the PLC (Do-More Simulator) The software can be downloaded from the following URL: http://support.automationdirect.com/products/d omore.html Start the Do-More Designer software. Under the Project Browser select ‘System Configuration’
  • 25. 4 Communicate to the PLC (Do-More Simulator)
  • 26. 4 Communicate to the PLC (Do-More Simulator) Make note of the IP address. If you are running the simulator then this is automatically filled in.
  • 27. 4 Communicate to the PLC (Do-More Simulator) Ensure that the Enable Modbus/TCP Server is checked. Also make sure that the TCP Port Number is 502.
  • 28. 4 Communicate to the PLC (Do-More Simulator) The sample PLC program will write values in the range from 0 to 4000. These values will be put in MHR 1 to MHR 10. Here is the first couple of rungs of the PLC program. It will use clock bit flags to increment the MHR 1 channel. When it gets to the value above 4000, a move instruction will put a 0 back into MHR 1. If input X0 turns on then the value in XW0 will be moved into MHR1 and the previous clock bit will not be in effect. Values will be between 0 and 4096. (12 bit resolution) This is repeated with different internal clock bit flags up to MHR10.
  • 29. 4 Communicate to the PLC (Do-More Simulator)
  • 30. 4 Communicate to the PLC (Do-More Simulator) Running the program will produce the following:
  • 31. ACC Automation Additional information can be obtained from our website: How to Implement Modbus TCP Protocol using VBA with Excel - Video Additional Information: Excel – Conditional Movement of Data