All posts by garrys

USB to RS485 PC Adapter Installation

The USB-485M is a 2-wire USB to RS-485 serial communication adapter for RS485 use. It does not require an external power supply or complicated configuration.

It has a Type A (plug) USB connector for the computer side and a universal female RJ45/RJ12 modular connector. This will accept RJ12 and RJ45 plugs.  The USB-485M supports multiple baud rates and is USB V2.0 Compliant.

Installing the Driver
Do NOT connect the USB-485M to your PC before installing the driver file.

Go to the Automation Direct website and download the latest drivers for this device. I would not use the mini CD that came with the converter because it may be out of date.
USB-485M Serial Converter Support Resources
USB RS485 Installation 010-min

Download and extracted the zip file. (Right click on the zip file and select Extract All…. )
If you have a 64bit computer double click on the following file:
CP210xVCPInstaller_x64.exe
If you have a 32bit computer double click on this file:
CP210xVCPInstaller_x86.exe

If you are unsure as to 32 bit or 64 bit computer then go to control panel and look under system. Under System type it will display either a 32-bit Operating or 64-bit Operating system.
Alternatively on Windows 7 you can click start and right click on Computer.
USB RS485 Installation 080-min
Selecting properties will call up the system information for you.
USB RS485 Installation 090-min

This will now start the installation of the CP210x USB to UART Bridge Driver. Select Next.USB RS485 Installation 020-min

You must accept the license agreement before the software will install. Select ‘I accept this agreement’ and hit Next.USB RS485 Installation 030-min

You will now get a message that the installation is complete. The Silicon Laboratories Driver is now installed. Click Finish.USB RS485 Installation 040-min

We will now configure the device driver for our hardware.
Connect the USB-485M to your PC.
The driver software installation will begin by searching for the CP2103 USB to UART Bridge Controller. It will start by searching windows update…
USB RS485 Installation 050-min

Once the software has been configured a message will be displayed as follows. If it cannot find the driver software you can manually select the x64 (64bit) or x86 (32bit) folders from the downloaded driver files.USB RS485 Installation 060-min

You can now call up device manager and view the ports on your computer. The Silicon Labs CP210x USB to UART Bridge is on communication port 5. USB RS485 Installation 070-min

We are now ready to connect to our equipment. Since this is a serial device and is a 1 : N connection. This means that we will have a master and at least one slave unit. All communication must have the same parameters when communicating. What separates the communication is that each slave is assigned an unique number.
Example:

Device Computer ‘Master’ Solo Process Controller
‘Slave’
Do-More PLC
‘Slave’
Additional Devices
‘Slaves’
Station Address / Unit number N/A 1 2
Baud Rate 9600 9600 9600 9600
Data Bits 8 8 8 8
Parity Even Even Even Even
Stop Bits 1 1 1 1

Protocol is the actual communication (Information format that is transferred) that takes place over the network. (Master to Slaves)

Watch on YouTube : USB to RS485 PC Adapter Installation
If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.




PLC Bits Numbers and Position

People often ask “What is a PLC?” and “PLC Meaning”. A programmable logic controller (PLC) is a piece of hardware that isolates inputs from outputs. Programs are written to look at the inputs solve logic and set the outputs to perform work. Today we are going to look at the basic fundamental way we program. Every PLC company will do this…

Everything in the programmable logic controller actually boils down to bits in the memory.
Memory Bits-min
It is these bits that we manipulate in order to accomplish the work that we need done by the PLC. The instruction set is the method we use to do this. In general, there are several ways to view the bits. Discrete input and output, Numbers and Position of bits will be covered. Understanding the different ways in which we can view these bits will help in developing programs.
Bits are part of the memory of all PLC systems. The memory can be retentive or non-memory retentive. Memory retentive means that if power is lost to the PLC, the status of the bit remains the same when power is restored. If the bit is non-memory retentive, and power is lost the bit returns to the off state. Addressing refers to how the controller understands what memory location to look at. When we address memory in the PLC we can do this in two different ways:
Direct Addressing: Specify a location of the memory location
Indirect Addressing: Specify a location that contains a value to point to the memory location required.
Indirect Addressing Animation

Refer to the manual of the specific PLC that you are using for the way in which memory is addressed and if it is memory retentive or not.

Discrete bits are the basic building blocks in the PLC. When we talk of digital I/O this is referring to the individual bits that you can wire switches, pushbuttons, proximity sensors, or any other device that is either on or off. (1 or 0) They can be usually wired to the PLC as a normally open or normally closed contact. The ladder logic is written in a way that you examine the bit as either on or off.
HOW PLC INPUTS WORK
PLC Input

HOW PLC OUTPUTS WORKPLC Outputs
We also must look at the frequency (rate of change from off to on) of the input bits or output in some cases. The maximum frequency that we can read an input to the PLC will be determined by the scan of the PLC.
Example:
A 2 ms Scan (0.002 second) means that we can read the inputs and solve the logic in 2 ms. In order to ensure that the input is read in both states (on / off) we have to ensure that the input is off or on for at least 2 ms. The maximum frequency (Switching / Second) that the input could switch would be 2 ms = 1/.002 times per second = 500hz

Numbers in the PLC are all based on binary. Analog inputs and outputs are based upon the number of bits put together in order to display the range for the input. (12 bit or 16 bit) The values from the analog 12bit input will go from 000 to FFF base 16 (Hex). Hexadecimal is used to display the binary bits in the word or register. Some of the more common numbering systems in the PLC are binary, hexadecimal, BCD (binary coded decimal) and octal (based on 8 bits)
funny_counter
Additional Information on understanding numbering systems in the PLC:
What Everybody Ought to Know about PLC (Programmable Logic Controller) Numbering Systems

Position of the bits within the word, stack or accumulator can be very useful. Usually we can use this to track items. The typical example of this is to track items on a conveyor belt. The belt movement is usually a pulse input from an encoder. A sensor indicates the item on the conveyor.
PLC PROGRAMMING EXAMPLE – SHIFT REGISTER (CONVEYOR REJECT)
Conveyor Reject

Bits are the basic building blocks that we use to program programmable logic controllers. The three ways to view bits (Discrete, Number and Position) will help use to understand the different ways to program.
Here are some additional links that you may find helpful:
Five Steps to PLC Program Development
PLC Programming Example – Process Mixer
PLC Programming Example – Shift Register (Conveyor Reject)
PLC Programming Example – Paint Spraying

The Secret of Using Counters
The Secret of Using Timers

Watch on YouTube : PLC Bits Numbers and Position
If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.




Building a PLC Program That You Can Be Proud Of – Part 6

We will continue the series by looking at a sequencer controlling seven cylinders that can be taught. The cylinders can be operator programmed from the AdvancedHMI screen. You will be able to select what cylinders to activate at each step and program in 500 steps. Our PLC will be the Do-More from Automation Direct.
Cylinder Teach HMI 110-min

Here is a quick review of the programming series so far. If you are new to the site, we recommend reviewing the other parts in the series first.
In part 1 we looked at writing PLC programs to control a traffic light using discrete bits and then using timed sequencing using indirect addressing.
Part 2 used indirect addressing for inputs as well as output to control the sequence of pneumatic (air) cylinders in the program. Part 3 and 4 we returned to the traffic light application and expand our program significantly. We looked at the sequence of operation using Input, output and mask tables.
In part 5 we used the AdvancedHMI software to create the game of Simon. A round in the game consists of the device lighting up one or more buttons in a random order, after which the player must reproduce that order by pressing the buttons. As the game progresses, the number of buttons to be pressed increases.

We will be using AdvancedHMI to communicate Modbus TCP to the Automation Direct Do-More Designer Software Simulator. The following is the sequence of operation:
Watch on YouTube : Running the Cylinder Sequence (PLC / HMI)
Note: All of the  programs used are provided free of charge and are an excellent way to learn PLC / HMI programming.

The following table is the Modbus TCP memory map to the Do-More PLC:

Coil/Register Numbers Data Addresses Type Do-More PLC Table Name
00001-09999 0000 to 270E Read-Write MC1 to MC1023 Discrete Output Coils
10001-19999 0000 to 270E Read-Only MI1 to MI1023 Discrete Input Contacts
30001-39999 0000 to 270E Read-Only MIR1 to MIR2047 Analog Input Registers
40001-49999 0000 to 270E Read-Write MHR1 to MHR2047 Analog Output Holding Registers

Cylinder Teach HMI 100-min
Here are the inputs and outputs we will be using for our program:

Device Data Addresses Type Do-More PLC Description
Start Pushbutton 00011 Input MC11
Stop Pushbutton 00012 Input MC12
Jog Pushbutton 00013 Input MC13
Reset Pushbutton 00014 Input MC14
Run/ Jog Selector 00008 / 00015 Input/ Output MC8 / MC15  MC8 is the value and MC15 is the click
Light Stack 00010 / 00009 / 00008 Output MC10 / MC9 / MC8  Red / Green / Amber
Set Pushbutton 00071 Input MC71
Jog / Teach Selector 00070 Input MC70  MC70 on is teach mode
Sequence Step (Panel Meter) 40001 Output MHR1  Current step in the sequence
Inputs Actual 40002 Input MHR2  Show the actual inputs in binary format
Output Sequence 40003 Output MHR3  Show the actual outputs in a binary format
Input Sequence 40004 Input MHR4  Show the input sequence bits in a binary format
Cylinder 1 to 7 – value 00001 to 00007 Output MC1 to MC7  Determine if cylinder is on/off
Cylinder 1 to 7 – set (click) 00041 to 00047 Input MC41 to MC47  Set the cylinder button
Cylinder 1 to 7 – retract indicators 00021 to 00027 Input MC21 to MC27 Indicate cylinder has retracted
Cylinder 1 to 7 – extend indicators 00031 to 00037 Input MC31 to MC37 Indicate cylinder has extended
Cylinder 1 to 7 – extend / retract error indicators 00050 to 00063 Output MC50 to MC63 Indicate cylinder input error when jogging

The first thing we will do is design the HMI. We have three main areas on the screen. Basic Controls, Cylinder Visualization and the Sequence Step/Teach area. Please refer to the above reference chart for the inputs and outputs programmed on the screen.
Cylinder Teach HMI 130-min

Basic Controls:
This area will allow us to see what mode we are in via the stack light. Red – Stop
Yellow – Jog / Teach Mode – Troubleshooting
Green – Run
Cylinder Teach HMI 101-min

Cylinder Visualization:
Each cylinder will have indication lights to determine status of the cylinder. (Extended / Retracted)
The cylinder will also have red indication lights to reflect the differences between the current sequence and the next sequence step. This is visible when we are in jog mode.
Cylinder Teach HMI 102-min

Sequence Step/Teach:
When in jog or teach mode the sequence step is visible, which indicates the current step that we are on. The inputs and outputs are displayed as a binary value which represents the actual inputs and outputs. This is valuable when troubleshooting and finding errors in the system. The set button is visible when in teach mode. When pushed the outputs and inputs are set for that step and the sequence will then increment.
Cylinder Teach HMI 103-min

The following is the code for each of the words that the DataScribers are reading. This includes the code to change the word into a 16 bit binary value.

Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
'Label1.Text = Hex(DataSubscriber1.Value)Dim i As Integer = DataSubscriber1.Value
Label1.Text = Convert.ToString(i, 2).PadLeft(16, "0") '16 bits
End Sub
Private Sub DataSubscriber2_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber2.DataChanged
'Label2.Text = Hex(DataSubscriber2.Value)
Dim i As Integer = DataSubscriber2.Value
Label2.Text = Convert.ToString(i, 2).PadLeft(16, "0") '16 bits
End Sub
Private Sub DataSubscriber3_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber3.DataChanged
Dim i As Integer = DataSubscriber3.Value
Label3.Text = Convert.ToString(i, 2).PadLeft(16, "0") '16 bits
End Sub
Private Sub DataSubscriber4_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber4.DataChanged
If DataSubscriber4.Value = True Then
     Label1.Visible = True
     Label2.Visible = True
     Label3.Visible = True
     Label4.Visible = True
     Label5.Visible = True
Else
     Label1.Visible = False
     Label2.Visible = False
     Label3.Visible = False
     Label4.Visible = False
     Label5.Visible = False
End If
End Sub

We will now look at the PLC ladder program. The program is broken down into several parts as follows:

ACC Automation
This is the main start / stop circuit of the program.
If we are in run mode the green light will be on. (MC9)
If we are not in jog mode (MC8) this circuit will be functional.
Cylinder Teach PLC 100-min

If we are not run mode (MC9) or in jog mode (MC8) then the stop mode is active.
This will turn on the red light. (MC10)
Cylinder Teach PLC 110-min

Run / Jog – Toggle Circuit
Flip Flop circuit to set the jog function
Cylinder Teach PLC 120-min

Move the outputs to the physical outputs when we go to run mode.
Cylinder Teach PLC 130-min

Indirect Addresses for the Program
V0 – Input pointer – 100 – 499
V1 – Output pointer – 500 – 999
V2 – Input pointer last step in sequence
V3 – Output pointer last step in sequence
V10 – Inputs to the sequencer
V20 – Outputs from the sequencer
Cylinder Teach PLC 140-min

Jog Mode – Jog Pushbutton
Cylinder Teach PLC 150-min

Reset the sequencer pointers. This will happen automatically in run mode or by hitting the reset button in jog or stop mode.
Cylinder Teach PLC 160-min

Teach Function
This first rung will activate the values so we can manually turn them off/on with the HMI screen.
Cylinder Teach PLC 170-min

This will reset the pointers when going into teach mode.
Cylinder Teach PLC 180-min

This will set the teach point and increment to the next step.
Cylinder Teach PLC 190-min

Show the current step of the sequence.
Note: 0 is the first step
Cylinder Teach PLC 200-min

Set the inputs for cylinders.
The actural physical input points would be inserted here.
HMI inputs from the cylinders have a 500ms delay to simulate the movement of the actual cylinder.
Cylinder Teach PLC 210-min Cylinder Teach PLC 220-min

Set the actual inputs / sequencer inputs / sequencer outputs so we can monitor this on the HMI.
Cylinder Teach PLC 230-min

Set the outputs for cylinders.
This will set the physical output points Y1 to Y7.
This will also set the HMI cylinders MC1 to MC7 (00001 to 00007)
Cylinder Teach PLC 240-min Cylinder Teach PLC 250-min Cylinder Teach PLC 260-min

Diagnostic Bits for indicating the difference for the inputs to the PLC. This will show up as a red indication light on the cyclinder represented on the HMI.
Cylinder Teach PLC 270-min Cylinder Teach PLC 280-min

This section of PLC logic will mimic the inputs from the cylinders.
Cylinder 1 – Retract MC21 (00021) – Extend MC31 (00031)
Cylinder 2 – Retract MC22 (00022) – Extend MC32 (00032)
Cylinder 3 – Retract MC23 (00023) – Extend MC33 (00033)
Cylinder 4 – Retract MC24 (00024) – Extend MC34 (00034)
Cylinder 5 – Retract MC25 (00025) – Extend MC35 (00035)
Cylinder 6 – Retract MC26 (00026) – Extend MC36 (00036)
Cylinder 7 – Retract MC27 (00027) – Extend MC37 (00037)

Between each funtion of the cylinder there is a time delay for the input to turn on and off of 500msec.
Cylinder Teach PLC 290-min

Cylinder 2 – Retract MC22 (00022) – Extend MC32 (00032)
Cylinder Teach PLC 300-min

Cylinder 3 – Retract MC23 (00023) – Extend MC33 (00033)
Cylinder Teach PLC 310-min

Cylinder 4 – Retract MC24 (00024) – Extend MC34 (00034)
Cylinder Teach PLC 320-min

Cylinder 5 – Retract MC25 (00025) – Extend MC35 (00035)
Cylinder Teach PLC 330-min

Cylinder 6 – Retract MC26 (00026) – Extend MC36 (00036)
Cylinder Teach PLC 340-min

Cylinder 7 – Retract MC27 (00027) – Extend MC37 (00037)
Cylinder Teach PLC 350-min

This is the end of the PLC program. You can see that the program is not very complicated once you break down the individual steps.

Download the PLC program and the Bin directory for the AdvancedHMI screen.

Watch on YouTube : Building a PLC Program that You can be Proud Of – Part 6b – Explaining the Program
If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.




Excel Conditional Movement of Data

I have been recently asked how you can move data conditionally on an excel spreadsheet once the information has been obtained from the PLC? Monthly data was being collected from the PLC and put on an excel spreadsheet using Omron CX-Server DDE. They wanted at the beginning of each month to move the data to the appropriate month so they can track the changes.

The following three blogs were posted on how to get data into the Microsoft Excel Spreadsheet from the programmable logic controller. (PLC)

HOW TO IMPLEMENT MODBUS TCP PROTOCOL USING VBA WITH EXCEL

IMPLEMENTING THE OMRON CX SERVER DDE AND EXCEL

HOW TO IMPLEMENT THE OMRON HOST LINK PROTOCOL PART 2 – VBA

The method to move the data around the spreadsheet once the data has been obtained will be done by Visual Basic for Applications. (VBA)

Make a spreadsheet in excel as follows:
Excel Conditional Movement of Data 0100-min

Operation:
When the current data in A2 or B2 changes, it will trigger a macro to execute. This macro will use the Worksheet_Change to trigger the code. The date in A2 is then compared to all of the dates located from A5 to A30. If a match is found then the value in B2 is placed beside the matching date found column. Example: A2 = A7 then B7 = B2
Here is a look at the VBA editor and code:
Excel Conditional Movement of Data 0110-min

Here is the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = “$A$2” Or Target.Address = “$B$2” Then
For x = 5 To 30
If Sheets(“Sheet1”).Range(“A2”) = Sheets(“Sheet1”).Range(“A” & x) Then
Sheets(“Sheet1”).Range(“B” & x) = Sheets(“Sheet1”).Range(“B2”)
End If
Next ‘x
End If
End Sub

Download the example excel file.

Watch on YouTube : Excel Conditional Movement of Data
If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.




Building a PLC Program That You Can Be Proud Of – Part 5

The Game of Simon
Learning all about bit manipulation and sequencers

Simon is a memory game introduced in 1978. It has four coloured buttons, each producing a particular tone when it is pressed or activated by the device. A round in the game consists of the device lighting up one or more buttons in a random order, after which the player must reproduce that order by pressing the buttons. As the game progresses, the number of buttons to be pressed increases. If the wrong button is hit the current game is over. Our game will have a high level score and a current level score.

We will be using AdvancedHMI to communicate Modbus TCP to the Automation Direct Do-More Designer Software Simulator.

Watch on YouTube : The Game of Simon Play (PLC / HMI)
Here is the end result of our program.

Note: The programs are provided free of charge and are an excellent way to learn PLC / HMI programming.

Here is a quick review of the programming series so far. If you are new to the site, we recommend reviewing the other parts in the series first. In part 1 we looked at writing PLC programs to control a traffic light using discrete bits and then using timed sequencing using indirect addressing. Part 2 used indirect addressing for inputs as well as output to control the sequence of pneumatic (air) cylinders in the program. Part 3 and 4 we returned to the traffic light application and expand our program significantly. We looked at the sequence of operation using Input, output and mask tables.

Simon Game HMI 130-min

The first thing that we will do is look at the HMI programming. Please refer to the following post for information on setting up and using AdvancedHMI software.
Create a PLC with HMI Training and Learning Environment Free

The following table is the Modbus TCP memory map to the Do-More PLC:

Coil/Register Numbers Data Addresses Type Do-More PLC Table Name
00001-09999 0000 to 270E Read-Write MC1 to MC1023 Discrete Output Coils
10001-19999 0000 to 270E Read-Only MI1 to MI1023 Discrete Input Contacts
30001-39999 0000 to 270E Read-Only MIR1 to MIR2047 Analog Input Registers
40001-49999 0000 to 270E Read-Write MHR1 to MHR2047 Analog Output Holding Registers

Simon Game HMI 100-min
Add the ModbusTCPCom control and set the IP Address. Also set the PollRateOverride to 50 so the response to our PLC is quicker.

The following map will apply to our game:
(Communication between the HMI and PLC)

40002 – MHR2 – Register – Game Sounds
40001 – MHR1 – Register – Current Game Level
40003 – MHR3 – Register – Highest Game Level
00005 – MC5 – Bit – Start/Reset Game
00001 – MC1 – Bit – Green Button Input
10001 – MI1 – Bit – Green Button Set
00002 – MC1 – Bit – Red Button Input
10002 – MI1 – Bit – Red Button Set
00003 – MC1 – Bit – Yellow Button Input
10003 – MI1 – Bit – Yellow Button Set
00004 – MC1 – Bit – Blue Button Input
10004 – MI1 – Bit – Blue Button Set

Simon Game HMI 110-min
The DataSubsciber is used to read information from the PLC and manipulate the data in the visual basic code.  We will use this to determine what sounds to play.

The following is the code for the button when hit to play the sound and the DataSubscriber1 to play the sound when the playback from the PLC is required. (Console.Beep (Frequncy (Hz), Duration (msec)))

Private Sub PilotLight1_Click(sender As Object, e As EventArgs) Handles PilotLight1.Click ‘ Green Light
     Console.Beep(415, 420)
End Sub

Private Sub PilotLight2_Click(sender As Object, e As EventArgs) Handles PilotLight2.Click ‘ Red Light
     Console.Beep(310, 420)
End Sub

Private Sub PilotLight3_Click(sender As Object, e As EventArgs) Handles PilotLight3.Click ‘ Yellow Light
     Console.Beep(252, 420)
End Sub

Private Sub PilotLight4_Click(sender As Object, e As EventArgs) Handles PilotLight4.Click ‘ Blue Light
     Console.Beep(209, 420)
End Sub

Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
If DataSubscriber1.Value = “1” Then
     Console.Beep(415, 420) ‘ Green
ElseIf DataSubscriber1.Value = “2” Then
     Console.Beep(310, 420) ‘ Red
ElseIf DataSubscriber1.Value = “4” Then
     Console.Beep(252, 420) ‘ Yellow
ElseIf DataSubscriber1.Value = “8” Then
     Console.Beep(209, 420) ‘ Blue
ElseIf DataSubscriber1.Value = “10” Then
     Console.Beep(120, 1500) ‘ Losing Sound
ElseIf DataSubscriber1.Value = “20” Then
     For x = 1 To 8
          Console.Beep(600, 90) ‘ Winning Sound
          Threading.Thread.Sleep(20)
     Next ‘x
End If
End Sub

Simon Game HMI 120-min

We now have our HMI interface complete and can move onto the PLC programming.

Random sequence generator – MHR4
The first four bits of MHR4 will be used to generate the random sequence for each step of the pattern.
The first scan is to set (1) a bit in MHR0. This will also ensure that the rest of the bits in the word are reset (0).
The second rung will shift the bits left in the output word MHR0. This will happen once per scan of the PLC. When bit 04 turns on then bit 00 will then be turned on again. This way we will always have one of the first four bits turned on in the output word. (00, 01, 02 or 03) MHR0 is logically AND with Hex value 000F and the result is placed in MHR4.

Simon Game PLC 100-min

Start the Game
The game will be started n the leading edge of the reset button. (MC5)
All of the registers and pointers are reset to start the game.
1     is moved into the current level – MHR1
100 is moved into the Play Sequence Pointer – V1
100 is moved into the Input Sequence Pointer – V2
100 is moved into the Current Level Pointer – V0
The random sequence MHR5 is moved indirectly into the Current Level Pointer V0 and this pointer is then incremented by 1.
An initialization bit is then set.

Simon Game PLC 110-min

The initialization bit starts a timer for 600msec in order to give time for the HMI to respond. Once the time expires the Initialization bit is reset and the game start bit is set. (Y0)
Y0 – Game Started is used to determine if play is to continue.

Simon Game PLC 120-min

Play the Sequence

Simon Game PLC 130-min

Set the outputs to play the sequence.
This will also set the sound to play for each of the colours selected. (MHR2)

Simon Game PLC 140-min

Reset the sound during the playing of the sequence.

Simon Game PLC 150-min

Read the inputs from the HMI. (MC1 – MC4)
Set the bits in V501 so we can compare the word.

Simon Game PLC 160-min

If the wrong button is hit, then play a sound and stop the game.

Simon Game PLC 170-min

If the correct color is selected, increment to the next random colour in the sequence.

Simon Game PLC 180-min

If the correct colour sequence has been entered, then the level has been completed.
Start a delay to ensure that the HMI has finished playing all of the sounds.

Simon Game PLC 190-min

When the level is entered correctly and the time delay has expired, we will reset the play and input pointers. The level increases by 1 and  another random number is added to the sequence and the current level pointer is incremented by 1.
MHR1 – Level – Increases
V1 – 100
V2 – 100
V0 – New random number gets indirecly addressed and the pointer is incremented by 1

Simon Game PLC 200-min

Setting the Highest Level achieved
If the current level is greater than the highest level, the current level is moved into the highest level.

Simon Game PLC 210-min

If no key is hit for 45 seconds after the sequence is played a sound will be played and the game start bit will be reset.

Simon Game PLC 220-min

If the game start bit is off for more than 500ms, the sound will be reset.

Simon Game PLC 230-min

Download the PLC program and the Bin directory for the AdvancedHMI screen.

Watch on YouTube : Building a PLC Program that You can be Proud Of – Part 5 – Game of Simon

Part 6 will look at a sequencer controlling seven cylinders that can be taught. The cylinders can be operator programmed from the AdvancedHMI screen.

If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.




Create a PLC with HMI Training and Learning Environment Free

Learn PLC programming and use a powerful HMI (Human Machine Interface) easily and free. We will use the Automation Direct Do-More programming software tied into the Advanced HMI package via Modbus TCP.
PLC HMI Training Learning 0080-min

Our application will show a HMI screen with a panel meter and a reset button. The panel meter value may be changed by clicking it. This will bring up a input screen to put in a number. When the reset button is selected the input value entered will show on the panel meter.
PLC HMI Training Learning 0310-min

Since we will be communicating via Modbus TCP, the following table shows the Coil/Register Numbers and the associated Do-More PLC Addresses.

Coil/Register Numbers Data Addresses Type Do-More PLC Table Name
00001-09999 0000 to 270E Read-Write MC1 to MC1023 Discrete Output Coils
10001-19999 0000 to 270E Read-Only MI1 to MI1023 Discrete Input Contacts
30001-39999 0000 to 270E Read-Only MIR1 to MIR2047 Analog Input Registers
40001-49999 0000 to 270E Read-Write MHR1 to MHR2047 Analog Output Holding Registers

Note: The Do More PLC uses the Modbus area to communicate. This is because having direct access to the digital I/O can be dangerous when connected via Ethernet to the internet. Data must move in and out of this area via the PLC program.

We will first start with the PLC.
Automation Direct has a powerful simulator with their Do-More PLC. It is the Do-More Designer Software. This software simulator includes the entire instruction set (Not Just Bit Logic) as well as communication protocols. It can be downloaded and installed for free from the above link.
Our PLC program will have the following addresses:
Digital Panel Meter Present Value (PV) – MHR1 – Modbus 40001
Digital Panel Meter Set Value (SV) – MHR2 – Modbus 40002
Reset Button – MC1 – Modbus 00001

The first rung of the ladder will use the 1 second pulse bit and increment the PV value of our digital panel meter. This will also compare the current value to 4000 and if greater or equal, move the value of zero into the PV value.

The second rung of the ladder will move WX0 analog value from our simulator into the PV value of our digital panel meter.

The last rung of ladder will move the SV value into the PV value of our Digital Panel Meter. This happens when the reset is hit.

PLC HMI Training Learning 0200-min

The simulator is showing X0 on and we can then use the WX0 slider to change the PV value of the Panel Meter.
PLC HMI Training Learning 0210-min

Advanced HMI is a powerful HMI/SCADA (Supervisory Control and Data Acquisition) development package that takes advantage of Visual Studio. There is no coding required and you can simply drag and drop items onto the page. The best thing is that the software is free.

Communications drivers include the following and are accessible via VB or C# code:

  • Allen Bradley DF1 RS232 Driver
  • Allen Bradley Ethernet/IP Driver for SLC,MicroLogix, ControlLogix, and CompactLogix
  • Beckhof TwinCAT Driver
  • ModbusTCP Driver
  • ModbusRTU Driver
  • Omron Ethernet FINS Driver – Ethernet for newer controllers such as CP1H with Ethernet module
  • Omron Serial FINS Driver – Serial (RS232 / RS485) for newer controller such as CP1H
  • Omron Serial HostLink Driver – Serial (RS232 / RS485) for controllers such as CQM1, C200H, K-Series (C28K), C200, etc

The power of Advanced HMI is that it works within Visual Studio. This is a program integrated development environment (IDE) that you can take advantage of to modify or create new features including data logging applications.

Advanced HMI runs on Visual Studio 2008 or higher and will need to be installed on your PC. Visual Studio Community Edition 2015 is the latest version of the software. If you do not have it installed, please download and install from the following link.

https://www.visualstudio.com/en-us/products/visual-studio-community-vsPLC HMI Training Learning 0090-min

We will now need the Advanced HMI project. Here is the link to download the zip file.

http://sourceforge.net/projects/advancedhmi/PLC HMI Training Learning 0095-min

After downloading ‘AdvancedHMIBetaV399a.zip’ extract the files from the zip file. (Right Click.. Select Extract All)
Note: Your version might be different than the one above.

Open the solution file (AdvancedHMIv35.sln) from the extracted files in the root directory.
PLC HMI Training Learning 0097-min

PLC HMI Training Learning 0100-min

Our initial screen looks like the following. The project will now need to be compiled in order to add the components to the Toolbox.
Select Build | Build Solution from the menu
The next thing to do is add the communication to the form. On the left hand side of the screen you will see the ‘Toolbox’. Click on it and under AdvancedHMIDrivers Components we will select ModbusTCPCom. To actually add a component to our form you need to drag it. Select the component and as you hold the mouse button down move to the form.PLC HMI Training Learning 0120-min

After adding the ModbusTCPCom component, it will appear at the bottom, beneath our form.
Click on the ModbusTCPCom1 at the bottom of our form. On the right hand side you will notice the properties for this communication driver. Under Communication Settings | IP Address, enter the value  of the IP Address for the PLC. (192.168.1.3) Ensure that the port number is 502. This is the default port number for Modbus TCP.PLC HMI Training Learning 0130-min

We can now add the digital panel meter. From the toolbox select and drag the DigitalPanelMeter to our form.PLC HMI Training Learning 0140-min

Resize the panel meter on the form by dragging a corner of the component.
While the panel meter is clicked, set the Properties | PLC Properties of the component:
PLCAddressValue – 40001 – MHR1 – Value to display on the meter.
PLCAddressKeypad – 40002 – MHR2 – This is the location of the stored number when the operator selects the meter and enters a number in the keypad.PLC HMI Training Learning 0150-min

Add a MomentaryButton to our form by selecting and dragging it from the toolbox.PLC HMI Training Learning 0160-min

After re-sizing the component, we can change the colour to blue under Properties | Misc. Also change the text on the button to ‘RESET’
Set the PLCAddressClick value to 00001. This is address MC1 in the Do-More PLC.PLC HMI Training Learning 0170-min

Run the application by selecting the ‘Start’ form the top menu. This also can be started by hitting ‘F5’. The form will then show in a separate window and the panel meter will be incrementing the value. Hitting the reset button will reset the value to the one entered when you click the panel meter.PLC HMI Training Learning 0310-min

When you hit the panel meter on the display a keypad will then pop up on your screen. Enter the new value and then select ‘Enter’. The new value will appear in MHR2 in the Do-More PLC.
PLC HMI Training Learning 0320-min

Watch on YouTube : Create a PLC with HMI Training and Learning Environment Free
If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.




How to Implement Modbus TCP Protocol using VBA with Excel

We will use 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. Previously we have used VB6 to communicate Modbus TCP.
The following steps will 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)

 

The Modbus TCP/IP or 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. I will not go into the details of the communication protocol but here are some links to references:
Introduction to Modbus TCP/IP
Simply Modbus – Modbus TCP

 

OstroSoft Winsock Component
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.
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
Modbus TCP using VBA Excel 001-min

2. Run downloaded file from Windows Explorer or command-line
Modbus TCP using VBA Excel 002-min
Hit OK
Modbus TCP using VBA Excel 003-min
I use the default directories where the program will be installed. Click the button to install.
Modbus TCP using VBA Excel 004-min
Leave the program group to the default so I know what the program is after installation. Click continue.
Modbus TCP using VBA Excel 005-min
Click OK
The OstroSoft Winsock Component is now installed.

Start Microsoft Excel.

Modbus TCP using VBA Excel 010-min
Select ‘Developer’ along the top tabs.
Modbus TCP using VBA Excel 020-min

If the Developer tab is not present then we must turn on the developer tab.
Select File | Options Modbus TCP using VBA Excel 021-minSelect ‘Customize Ribbon’Modbus TCP using VBA Excel 022-minCheck the ‘Developer’ under Main Tabs. Modbus TCP using VBA Excel 023-min

Under the Developer menu. Select ‘Visual Basic’
Modbus TCP using VBA Excel 030-minThe Visual Basic Editor window will now be displayed. Modbus TCP using VBA Excel 040-min
From the menu – Tools | References
We can now add the OstroSoft Winsock Component to our application.
Select OK
Modbus TCP using VBA Excel 050-minSelect Sheet1(Sheet1). Modbus TCP using VBA Excel 060-min

Now put the visual basic code in the Sheet1(Sheet1)
Here is the code:

‘This example uses OstroSoft Winsock Component
‘http://www.ostrosoft.com/oswinsck.asp

Option Explicit

Dim bytesTotal As Long
Dim sPage As String
Dim MbusQuery
Dim returnInfo
Dim wsTCPgdb
Dim WithEvents wsTCP As OSWINSCK.Winsock
Dim SetObject
Dim RetrieveData

Private Sub CommandButton1_Click() ‘ Retrieve Data
On Error GoTo ErrHandler
  Dim sServer As String
  Dim nPort As Long
  Dim StartTime
 
  DoEvents
  nPort = 502 ‘ See configuration in Do-More Designer
  ‘ Set the IP address of the PLC
  sServer = Sheets(“Sheet1”).Range(“B4″) ‘”192.168.1.3”
  RetrieveData = 1
  CommandButton1.BackColor = “&H0000FF00” ‘ Set colour to Green

‘Check to see if the object has been created. If not set wsTCP.
If SetObject = “” Then
Set wsTCP = CreateObject(“OSWINSCK.Winsock”)
wsTCP.Protocol = sckTCPProtocol
SetObject = 1
  End If

‘ Check the state of the TCP connection
‘0 sckClosed connection closed
‘1 sckOpen open
‘2 sckListening listening for incoming connections
‘3 sckConnectionPending connection pending
‘4 sckResolvingHost resolving remote host name
‘5 sckHostResolved remote host name successfully resolved
‘6 sckConnecting connecting to remote host
‘7 sckConnected connected to remote host
‘8 sckClosing Connection Is closing
‘9 sckError error occured

‘ If TCP is not connected, try to connect again.
If wsTCP.State <> 7 Then
    If (wsTCP.State <> sckClosed) Then
      wsTCP.CloseWinsock
    End If
    ‘ Open the connection
    wsTCP.Connect sServer, nPort
    StartTime = Timer ‘ Use the timer to determine if a connection cannot be made
    Do While ((Timer < StartTime + 2) And (wsTCP.State <> 7))
        DoEvents
    Loop
    If (wsTCP.State = 7) Then
    Else
       Exit Sub
    End If
End If

‘ If we are connected then request the information.
If (wsTCP.State = 7) Then
    MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(6) + Chr(0) + Chr(3) + Chr(0) + Chr(0) + Chr(0) + Chr(20)
    wsTCP.SendData MbusQuery ‘Send out the Modbus Information
    ‘ Read the information
    ‘0000:    Transaction Identifier
    ‘0000:    Protocol Identifier
    ‘0006:    Message Length (6 bytes to follow)
    ’00:      The Unit Identifier
    ’03:      The Function Code (read MHR Read Holding Registers)
    ‘0000:    The Data Address of the first register
    ‘0002:    The number of registers to write
   
    ‘ Write the information
    ‘0000:    Transaction Identifier
    ‘0000:    Protocol Identifier
    ‘0009:    Message Length (6 bytes to follow)
    ’01:      The Unit Identifier
    ’16:      The Function Code (read Analog Output Holding Registers)
    ‘0000:    The Data Address of the first register
    ‘0001:    The number of registers to write
    ’02:      The number of data bytes to follow
    ‘0030     The number to put into the register
   
    ‘ Note: Addresses are offset by 1
    ‘   Example: MHR1 = Address 0000
    ‘   Example: MHR30 = Address 0029
   
End If
  Exit Sub

ErrHandler:
  MsgBox “Error ” & Err.Number & “: ” & Err.Description
End Sub
Private Sub CommandButton2_Click() ‘ Stop the communication
RetrieveData = 0
CommandButton1.BackColor = “&H8000000F” ‘ Set the default colour
End Sub

Private Sub wsTCP_OnDataArrival(ByVal bytesTotal As Long)
  Dim sBuffer
  Dim i
  Dim MbusByteArray(500)
  Dim h As Integer
  Dim txtSource
wsTCP.GetData sBuffer
  txtSource = txtSource & sBuffer
 
Dim j As Byte
returnInfo = “”
For i = 1 To bytesTotal
    wsTCP.GetData j, vbByte
    MbusByteArray(i) = Asc(Mid(sBuffer, i, 2))
    returnInfo = returnInfo & Asc(Mid(sBuffer, i, 2))
Next
 txtSource = returnInfo
 txtSource = Val(Str((MbusByteArray(10) * 256) + MbusByteArray(11)))
 Sheets(“Sheet1”).Range(“B10”) = Val(Str((MbusByteArray(10) * 256) + MbusByteArray(11)))
 Sheets(“Sheet1”).Range(“B11”) = Val(Str((MbusByteArray(12) * 256) + MbusByteArray(13)))
 Sheets(“Sheet1”).Range(“B12”) = Val(Str((MbusByteArray(14) * 256) + MbusByteArray(15)))
 Sheets(“Sheet1”).Range(“B13”) = Val(Str((MbusByteArray(16) * 256) + MbusByteArray(17)))
 Sheets(“Sheet1”).Range(“B14”) = Val(Str((MbusByteArray(18) * 256) + MbusByteArray(19)))
 Sheets(“Sheet1”).Range(“B15”) = Val(Str((MbusByteArray(20) * 256) + MbusByteArray(21)))
 Sheets(“Sheet1”).Range(“B16”) = Val(Str((MbusByteArray(22) * 256) + MbusByteArray(23)))
 Sheets(“Sheet1”).Range(“B17”) = Val(Str((MbusByteArray(24) * 256) + MbusByteArray(25)))
 Sheets(“Sheet1”).Range(“B18”) = Val(Str((MbusByteArray(26) * 256) + MbusByteArray(27)))
 Sheets(“Sheet1”).Range(“B19”) = Val(Str((MbusByteArray(28) * 256) + MbusByteArray(29)))

DoEvents
‘ Determine if we retrieve the data again.
If RetrieveData = 1 Then
    Call CommandButton1_Click
End If
End Sub

Private Sub wsTCP_OnError(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  MsgBox Number & “: ” & Description
End Sub

Private Sub wsTCP_OnStatusChanged(ByVal Status As String)
  Debug.Print Status
End Sub

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

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

Modbus TCP using VBA Excel 070-min

 

Communication to the PLC

Start the Do-More Designer software.
Under the Project Browser select ‘System Configuration’
Modbus TCP using VBA Excel 125-min
Make note of the IP address. If you are running the simulator then this is automatically filled in.
Modbus TCP using VBA Excel 126-min
Ensure that the Enable Modbus/TCP Server is checked. Also make sure that the TCP Port Number is 502.
Modbus TCP using VBA Excel 127-min

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)
Modbus TCP using VBA Excel 150-min

This is repeated with different internal clock bit flags up to MHR10.

Running the program will produce the following:Modbus TCP using VBA Excel 120-min

As you can see the Modbus TCP protocol is easy to implement with visual basic for applications.
Download the PLC program and Excel file.

Additional Information:
Excel – Conditional Movement of Data

Watch on YouTube : How to Implement Modbus TCP Protocol using VBA with Excel
If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.




Implementing the Omron CX Server DDE and Excel

Utilizing the CX Server DDE Manager will allow us to provide a link to the information in the Omron PLC. This link can be placed on an Excel spreadsheet. Charts, graphs, etc. can be made from the data. We will create links on an excel spread sheet from a CQM1H and a CP1L PLC. The information will then be displayed as a bar graph comparing the first ten memory areas.

Dynamic Data Exchange (DDE) is a channel through which correctly prepared programs can actively exchange data and control other applications within Microsoft Windows. The DDE manager will allow us to set up all of the links.

Start the DDE Manager by clicking Start/Programs/Omron/CX-Server/DDE Manager
Omron CX-Server DDE 01-min

This will start the DDE Manager and place an icon on your toolbar at the bottom of your screen. The application will run minimized.
Omron CX-Server DDE 02-min

Right-click on the minimized DDE Manager icon and select Project/New.
Omron CX-Server DDE 03-min

Assign a filename (ACC DDE.cdm) to the CX-Server project that you will create, and save it.
Omron CX-Server DDE 04-min

The create project will minimize to the taskbar. Right-click on the minimized DDE Manager icon and select Project/Edit.
Omron CX-Server DDE 05-min

This will call up the DDE Manager Project Editor. We can now add the PLC’s (Devices) and Points that we want to display.
Omron CX-Server DDE 06-min

Select File/New/PLC, or hit the PLC Icon on the taskbar.
Omron CX-Server DDE 07-min

Under Change PLC, we can now enter the information about how we are communicating to the programmable logic controller.

Device Name: – Name in which the DDE Manager will call the PLC
Device Type: – The model of PLC that will be connected
Network Type: – This is the communication method that we will be talking with the device.

In our example we will use the following two Omron PLCs.

  • CQM1H – SYSMAC WAY (Omron Host Link Protocol) Communication Port  11, 9600, E, 7, 2. Unit #00
  • CP1L – USB

 Once we have the PLC information, we can now add points that will contain the information that we wish to retrieve from the units. Select File/New/Point  or select the point editor icon to start the point editor.
Omron CX-Server DDE 08-min

On the Logical tab you can give a name (Or Change) to the point in the PLC to get. Select the Physical tab.Omron CX-Server DDE 09-min

On the physical tab we set the following information:
PLC: – This is the list of PLCs entered in the previous step
Data Location: – The memory location that we want to read from
Internal Data Type: – This is the interpretation of the data that we are reading. (Example: Bit, Word, BCD, etc.)
Command Modifier: – This is used if we need to Force Set / Reset the data location. This can be used to override the PLC program. Use with caution.
Press OK when finished setting the address.Omron CX-Server DDE 10-min

 Our point is now programmed. You will notice the symbols before the name of the point. This tells us at a quick glance what type of data we are looking at. Please refer to the CX Server Runtime manual for all of the symbol meanings.Omron CX-Server DDE 11-min

Fill out the remaining points for our example.
CP1L – D0 to D9
CQM1H – DM0 to DM9Omron CX-Server DDE 12-min

Start Microsoft Excel.Omron CX-Server DDE 13-min

Go back to the DDE manager and the points under the Project Editor. We can now select the first ten items in the list. Click the first one and then move to the last item. Hold the shift while clicking the last item will select all of them between.
Hit the DDE Link icon.
Omron CX-Server DDE 14-min

In Excel, we now paste the information onto the worksheet. (Ctrl + V) Right click the cell and select paste. Omron CX-Server DDE 15-min

The information will now be displayed and updated  on your worksheet.
The update time will depend on the interval set in the DDE Manager. Right-click on the minimized DDE Manager icon and select Update Interval…Omron CX-Server DDE 16-min

We can also set individual point update times in the DDE link item. The default update time is set via the DDE Manager but we can also set the time in the individual points on the spreadsheet.
DDE Update Default Link:
=CDMDDE|’C:\ACC DDE.cdm’!’\CP1L D0′
5 Second Update Link:
=CDMDDE|’C:\ACC DDE.cdm’!’\CP1L D0,5′

In the Project Editor of the DDE Manager you can see the first 10 memory areas are being used. This is the yellow triangle with the lightning bolt symbol. (You will not be able to delete the point if it is in use.)Omron CX-Server DDE 17-min

Calling up an excel file with the links embedded, will give you a Security Alert – Links warning. Select ‘Enable the content’ and then hit OK.Omron CX-Server DDE 18-min

Here is an example of the finished excel file. We have 10 memory locations from each PLC listed. We have inserted a graph that will dynamically change when the values are read.
Download the excel file here.
Omron CX-Server DDE 19-min

 As you can see implementing the CX Server DDE Manager is not a difficult task. It provide a quick and efficient way to view the information that we need.

Additional Information:
Excel – Conditional Movement of Data

Watch on YouTube : Implementing the Omron CX Server DDE and Excel
If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.




How to Implement the Omron Host Link Protocol Part 2 – VBA

ACC Omron Host Link VBA

In Part 1, we used VB6 to communicate from the computer to the PLC. We will now use Visual Basic for Applications (VBA) to accomplish the same task. NETComm will be the serial driver and Excel will be the program that we will use. Using Excel we will have access to the Excel Object Model so we can utilize worksheets, ranges etc.

Please refer to Part 1 (How to Implement the Omron PLC Host Link Protocol) for the details of the wiring of the serial port and protocol sequence.

The first step in using VBA is to download and register NETComm.ocx. To use serial communications with VBA you must register the NETComm.ocx driver.

Download the NETComm.ocx file to the c:\ directory.

Call up a dos prompt with administrator authority. (Right click on the cmd.exe program and select run as administrator.)
Command Prompt

Type ‘regsvr32 netcomm.ocx’
RegSvr32

An information box will be shown indicating that the NETComm.ocx was registered successfully.

Now open Excel and make the following on Sheet 1.
Excel Omron Host Link 01

Select Developer and then Visual Basic. Excel Omron Host Link 02

If you do not have the Developer option to select, then do the following:
Select File : Options: Customized Ribbon
Excel Omron Host Link 03Select Developer and hit OK

Microsoft-VBA-Large

VBA – Visual Basic for Applications will open
Excel Omron Host Link 04

Insert a user form.
Excel Omron Host Link 05

Add NETComm1 to UserForm1. If it is not on your Toolbar, then select additional controls and select NETCommOCX.NETComm. Press the OK. Then drag this control onto your form.
Excel Omron Host Link 06

Create three command buttons. This can be done by going to Design Mode,  and under the Insert menu you can select Command Buttons.Excel Omron Host Link 07

Here is the entire code for the application:

Private T$ ' Modual Scope for variable
Private TRead$
Private NumWords
Private startcycle
Private Sub CommandButton1_Click()
If NumWords = "" Then
    MsgBox "Set Read String"
    Exit Sub
End If
If startcycle = 0 Then
    startcycle = 1
    CommandButton1.BackColor = "&H0000FF00"
Else
    startcycle = 0
    CommandButton1.BackColor = "&H8000000F"
    UserForm1.NETComm1.PortOpen = False ' Close Communication Port
    Exit Sub
End If
UserForm1.NETComm1.PortOpen = True ' Open Communication Port
Application.EnableEvents = True
Do
    T$ = TRead$ ' Reset the Transmitted Information
    charreturn = 11 + (NumWords * 4) ' Determine the return characters
    GoSub FCS ' Checksum
    GoSub communicate ' Get informaiton
    
    'Check returned information and Display
    If Mid(rxd$, 6, 2) = "00" And (Len(rxd$)) >= charreturn Then
        For x = 1 To Sheets("Sheet1").Range("D7")
            Sheets("Sheet1").Range("B" & x + 10 - 1) = Mid(rxd$, x * 4 + 4, 4)
        Next 'x
    End If
    DoEvents ' Do other tasks
    'Update the date and time
    Sheets("Sheet1").Range("C09") = Format(Date, "YYYY/MM/DD") + "    " + Format(Time, "HH:MM:SS")
Loop While startcycle = 1
If startcycle = 0 Then Exit Sub
communicate:
rxd$ = ""
Buffer = T$ + FCS$ + "*" + Chr$(13)
UserForm1.NETComm1.Output = Buffer
Time1 = Now
Timeout = Now + TimeValue("0:00:02")
Do
    If Timeout <= Time1 Then GoTo timeoutcom
    DoEvents
    Time1 = Now()
Loop Until UserForm1.NETComm1.InBufferCount >= charreturn
rxd$ = UserForm1.NETComm1.InputData
fcs_rxd$ = Left((Right(rxd$, 4)), 2)
If Left(rxd$, 1) = "@" Then
    T$ = Mid(rxd$, 1, (Len(rxd$) - 4))
ElseIf Mid(rxd$, 2, 1) = "@" Then
    T$ = Mid(rxd$, 2, (Len(rxd$) - 5))
    rxd$ = Mid(rxd$, 2, (Len(rxd$) - 1))
End If
GoSub FCS
If FCS <> fcs_rxd$ Then
    rxd$ = ""
End If
clearbuffer$ = UserForm1.NETComm1.InputData
Return
FCS:
    L = Len(T$)
    A = 0
    For J = 1 To L
        TJ$ = Mid$(T$, J, 1)
        A = Asc(TJ$) Xor A
    Next J
    FCS$ = Hex$(A)
    If Len(FCS$) = 1 Then FCS$ = "0" + FCS$
Return
timeoutcom:
If startcycle = 0 Then Exit Sub
clearbuffer$ = UserForm1.NETComm1.InputData
rxd$ = ""
Return
End Sub
Private Sub CommandButton2_Click()
If startcycle = 0 Then
    UserForm1.NETComm1.CommPort = Sheets("Sheet1").Range("A4")
    UserForm1.NETComm1.Settings = Sheets("Sheet1").Range("B4") & "," & Sheets("Sheet1").Range("C4") & "," & Sheets("Sheet1").Range("D4") & "," & Sheets("Sheet1").Range("E4")
    MsgBox UserForm1.NETComm1.Settings
Else
    MsgBox "Stop Reading Parameters to Set MSComm"
End If
End Sub
Private Sub CommandButton3_Click()
If startcycle = 0 Then
    Unit = Sheets("Sheet1").Range("A7")
    If Len(Unit) < 2 Then Unit = "0" & Unit
    StartADD = Sheets("Sheet1").Range("C7")
    Do
        If Len(StartADD) < 4 Then
            StartADD = "0" & StartADD
        End If
    Loop Until Len(StartADD) = 4
    NumWords = Sheets("Sheet1").Range("D7")
    Do
        If Len(NumWords) < 4 Then
            NumWords = "0" & NumWords
        End If
    Loop Until Len(NumWords) = 4
    T$ = "@" & Unit & "RD" & StartADD & NumWords
    TRead$ = T$
    MsgBox T$
    For x = 1 To Sheets("Sheet1").Range("D7")
        Sheets("Sheet1").Range("A" & x + 10 - 1) = "DM " & Sheets("Sheet1").Range("C7") + x - 1
        Sheets("Sheet1").Range("B" & x + 10 - 1) = ""
    Next 'x
    For x = Sheets("Sheet1").Range("D7") To 200
        Sheets("Sheet1").Range("A" & x + 10) = ""
        Sheets("Sheet1").Range("B" & x + 10) = ""
    Next 'x
Else
    MsgBox "Stop Reading Parameters to Set Read String"
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub

Note: The Chart on Sheet1 is just a selection of the first ten DM areas and insert a bar graph.

Running the program produces the following information:
 Excel Omron Host Link 08

Download the excel file ACC Omron Host Link VBA.XLS. This is the complete program mentioned above.

 

When you open the file it will warn you about macros. This is the VBA application. Press ‘Enable Macros’.
Security Warning

When changing the parameters on the screen, you will also get a warning about Active X. This is the NETComm.ocx which was registered above. Press ‘OK’ to run the application.
VBA Warning

Additional Information:
Excel – Conditional Movement of Data

Watch on YouTube : How to Implement the Omron Host Link Protocol Part 2 – VBA
If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.