PLC and PC Communication Via SLMP Protocol
PLC and PC Communication Via SLMP Protocol
Modifications 16
You can also select Online → Read Module Configuration from PLC.
Ethernet Port
To start using SLMP Protocol set parameters as follow:
Set External Device Configuration by double click on <Detailed Settings> next to this parameter.
Add SLMP Connection Module from Ethernet Devices by drag and drop it → set TCP protocol → set
Port No. on 2000 → Close with Reflecting the Setting.
Write to PLC...
To write your project to PLC select Online →click Write to PLC... → select Parameter + Program(F)
→ Execute
If you don’t have the application installed yet, here there is a link to the website with the software:
https://www.hw-group.com/software/hercules-setup-utility
Make sure that IP address and Port No. are the same as those set in GX Works3.
After this operation you should be able to start communication. To do this, press Connect.
Connection operation status will be displayed in Received data: Connected to 192.168.3.250 (PLC
address).
Sending request to PLC
“50 00 00 FF FF 03 00 0C 00 10 00 01 04 00 00 C8 00 00 A8 01 00”
Request 50 00 00 FF FF 03 00 0C 00
Subheader Request Request Request destination Request destination Request data
(without serial No.) destination destination module I/O No. multidrop station No. length
network No. station No.
Response D0 00 00 FF FF 03 00 04 00
10 00 01 04 00 00 C8 00 00 A8 01 00
Monitoring timer Comand Subcommand Head Device No. Device code No. of device
(0401:Read) (0xC8 => 200DEC) (D register) points
00 00 BE DC
Data from the PLC are received and displayed in hexadecimal form in Received data section.
Observing this register in Watch window in GX Works3 you can confirm that data was sent
properly.
using System;
using System.Net.Sockets;
using System.Net;
using System.Net.NetworkInformation;
namespace SLMP_SampleFrame
{
class Program
{
static TcpClient tcpC = new TcpClient(); // Global TcpClient object
static void Main(string[] args)
{
byte[] byAdres = new byte[4];
// set IP address of PLC
byAdres[0] = 192; byAdres[1] = 168; byAdres[2] = 3; byAdres[3] = 250;
IPAddress ipAdress = new IPAddress(byAdres);
ConnectTCP(ipAdress, 2000); //connection for set IP address and Port No.
Read_D200(); // read D200 register
Console.ReadKey();
}
}
}
Main program
In “Part of code for read D200 register” section, put the request into payload variable:
“0x50, 0x00, 0x00, 0xff, 0xff, 0x03, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x01, 0x04, 0x00, 0x00, 0xC8,
0x00, 0x00, 0xA8, 0x01, 0x00”
Request 50 00 00 FF FF 03 00 0C 00
Subheader Request Request Request destination Request destination Request data
(without serial No.) destination destination module I/O No. multidrop station No. length
network No. station No.
Response D0 00 00 FF FF 03 00 04 00
00 00 BE DC
Caution!
Presented code is only a sample program, so it should not be run directly on a real object!
Customize the created application to your needs.
The number of sent and receive data can vary. In presented example, the number of frame
elements is static.
3.2. SelfTest
You can also add function that will check the correctness of the sent data frame. This
function compares sent and received data (in this case the test is performed on a 5-element
set). If data match, then data can be exchanged between devices and communication starts.
#region Part of code used to verify whether the communication function operates
normally or not
static bool SelfTest()
{
bool loopTestAns = false;
byte[] payload = new byte[] { 0x50, 0x00, 0x00, 0xff, 0xff, 0x03, 0x00,
lowByte, highByte, 0x10, 0x00, 0x19, 0x06,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00 };
// loopack data
for (int i = 0; i < loopMessage.Length; i++)
{