Click here to Skip to main content
15,884,998 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As mentioned in the question, i need to find a way to use
VB
system.net.sockets
to communicate with the PLC and read the data, placing it into the listbox. I have tried many samples and they so far do not work for me, only Winsock does but i am not intending to us VB6 or below. The Winsock ActiveX or any other ActiveX Control out of the question

Pls help, newbie here. Very Urgent


P.S PLC is progammable logic controller and i need to communicate via MODBUS TCP/IP


Travis
Posted
Updated 27-Aug-21 1:48am
v2
Comments
Sergey Alexandrovich Kryukov 1-Nov-11 0:30am    
Why do you think Winsock is related to ActiveX or VB6?
--SA
Sergey Chepurin 1-Nov-11 16:12pm    
Shouldn't you ask this question on OPC Foundation http://opcfoundation.org/forum/?

You are dealing with Modbus TCP/IP or Modbus over TCP (a.k.a. RTU/IP), which is not the same. This is the first thing you need to find in your documentation, If you know one you can learn another one based on Modbus RTU vs Modbus ASCII.

Start from here: http://en.wikipedia.org/wiki/Modbus[^].

This is a detailed description of Modbus TCP: and robust, it has since become one of the de facto standard communications protocols in the industry, and it is now amongst.

Your operation using C# is fairy simple: you connect to Modbus server using System.Net.Sockets.TcpClient and perform the communication using Modbus protocol. Essentially, you sequentially write/read to/from a network stream available from your instance of TcpClient after connection: send request — get response. See http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx[^]. Do it in a separate thread.

This is a C# implementation of Modbus protocol you can use. All this requires pretty good experience with basic programming techniques and some with network programming and threading, which is fairly simple.

Good luck,
—SA
 
Share this answer
 
Comments
Espen Harlinn 1-Nov-11 13:38pm    
it is now amongst the protocols that should be withdrawn - you almost have to be an automation engineer to come up with something as convoluted as this :) For something decent, have a look at http://www.omg.org/spec/DDSI/
It's extensible, sensible and efficient ... BTW: my 5
Sergey Alexandrovich Kryukov 1-Nov-11 14:26pm    
Thank you, Espen.

This looks like an interesting protocol; to my shame, I did not know anything about it. What do you know about real-like implementation of it and use in real-life control hardware?

I hope you understand that with OP the situation is very different: he needs to use what he has...

--SA
Take a look at this article:Modbus TCP class[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Nov-11 14:23pm    
Interesting reference, my 5, even though as an article it sucks, or should I say it's not an article at all?
--SA
Espen Harlinn 1-Nov-11 14:26pm    
Yes, it's about tip sized - but the writer did provide a Modbus implementation
Dear SAKryukovv,

Thanks A lot!! The information has really helped. There is a problem,I can get a connection but i can't seem to write/read data from the PLC. Your help is greatly appreciated and could you show some example code for me to get started

Travis Singh

P.S i will try to place my code online so you can take a look at it

Dear Santosh,

Thanks, it was very informative and i understood about about connecting to PLC via RTU or serial port but i am looking for a TCP/IP communication. Your help was still very useful and i understood all of it

Thanks Again

Travis Singh
 
Share this answer
 
hello friend

once i had already faced this type of problem plz check this code

use using System.IO.Ports;

C#
SerialPort port;
        string strport = String.Empty;
        int IBaudRate = 19200;
        int ITimeOut = 300;


//initialize port
C#
port = new SerialPort();
                port.PortName = portname;
                port.BaudRate = IBaudRate;
                port.DataBits = 8;
                port.StopBits = StopBits.One;
                port.Parity = Parity.None;
                port.ReadTimeout = ITimeOut;
                port.WriteTimeout = ITimeOut;
                port.Encoding = Encoding.GetEncoding("iso-8859-1");
                port.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
                port.Open();
                port.DtrEnable = true;
                port.RtsEnable = true;


//Send data

C#
port.DiscardInBuffer();
port.DiscardOutBuffer();
readnow.Reset();
port.Write(command + "\r");
recieved = receive(timeout);


//receive data
C#
private void DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (e.EventType == SerialData.Chars)
                readnow.Set();

        }
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Nov-11 0:31am    
This is serial port code, nothing to do with OP's question; voted "1", sorry.
--SA

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