Click here to Skip to main content
15,879,490 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I need to make a system in Visual Studio (C #) that allows me to communicate with the PLC, I am using Delta PLC DVP28SV and Delta module DVPEN01.


I was reading the MODBUS TCP / IP communication, I can not understand.

How would you send the information to a specific PLC register from C # and how to identify that registry?

I would appreciate if someone could guide me on the subject.

Greetings.


What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ModbusTcp;


namespace Console_ping_Sr2_Electronico
{
    class Program
    {
        static void Main(string[] args)
        {

            System.Net.NetworkInformation.Ping Pings = new System.Net.NetworkInformation.Ping();
            int timeout = 1000;
            int i = 0;
            while (i != 1)
            {
                {
                    if (Pings.Send("192.168.178.111", timeout).Status == IPStatus.Success)
                    {
                        Console.WriteLine("Exito");
                        Thread.Sleep(2000);
                        Console.Clear();
                    }
                    else
                    {
                        
                            Console.WriteLine("Error");
                        Thread.Sleep(2000);
                        Console.Clear();

                    }
                }
            }
        }
Posted
Updated 13-Aug-18 8:16am
Comments
Richard MacCutchan 13-Aug-18 12:09pm    
The only way to find the answer is to study the documentation for the device, to see what commands and responses it uses.

Modbus TCP/IP is a very, very simple protocol. It does not require an explicit, app-level connection - only a socket level connection. This means you can send it a message and it responds to that message and that is really all you have to worry about. Of course, if the connection is dropped you have to reconnect but that is the same with every socket.

There is also quite a bit of sample code available, some of which is here too. Just search the articles for the keyword "modbus" and here is what it finds : Search[^]
 
Share this answer
 
Comments
Member 13937256 14-Aug-18 12:22pm    
I am using the EASYmodbus library
You are giving me a mistake I would like you to help me to be referred.

EasyModbus.Exceptions.FunctionCodeNotSupportedException
HResult=0x80131500
Message=Function code not supported by master
Rick York 14-Aug-18 16:59pm    
No, I am not giving you a mistake. Your code has a mistake in it and the description tells you exactly what it is. You are asking the PLC for a type of data communication that it does not support. That is what the function code does - it specifies the type of data and what to do with it (read or write.)
Member 13937256 15-Aug-18 11:57am    
The code that I am using is this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyModbus;




namespace comunicacion_tcp
{
class Program
{
private string IpAddress = "192.168.178.111";
private int port = 502;
private ushort startAddres = 258;
private ushort quantity = 1;
private ModbusClient modbustcp;
public Program()
{
modbustcp = new ModbusClient(IpAddress, port);
modbustcp.Connect();

int[] response = modbustcp.ReadInputRegisters(startAddres, quantity);
modbustcp.Disconnect();
Console.WriteLine("value of input register 1" + response[0].ToString());
Console.WriteLine("value of input register 2" + response[1].ToString());
}
static void Main(string[] args)
{
Program _program = new Program();
Console.ReadKey();
}
}
}
Member 13937256 15-Aug-18 12:29pm    
In this area of the code I ask for the address of the record that I am going to use and the number:
int[] response = modbustcp.ReadInputRegisters(startAddres, quantity);
Any suggestions.
Rick York 15-Aug-18 17:01pm    
I see a call to ReadInputRegisters and that should do it for you but apparently it isn't. The next step is to dig into Delta's documentation and see what function codes their PLC actually supports. It might be that it does not support reading of input registers. If it does in fact support that then there might be an error with the library. At this point I would fire up WireShark and see what the packets look like. Modbus TCP/IP is documented really well and I think WireShark has a filter for it built-in so you should be able to see what is going. I have never used this library so I can't help you with details on it.
You should talk to the people who created it - Delta[^] - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!
Chances are they already have working sample code you can use as a basis.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900