Jump to content

PCOM over TCP


selim

Recommended Posts

Hi there;

I need to access MI area of a V1040 PLC through ethernet.

I had written a code that communicate with PLC via serial port before for an another project. Now, I am planning to modify my code to run under TCP.

At PC side, I am working with Delphi XE2 using Indy TCP client component. I tested these components on my network with another computers and they work properly.

At PLC side, I am using socket 1, port #20256 and Protocol is TCP Slave.. (I think these are default settings of socket 1 so I don't need to add a socket init FB to my ladder, am i right?)

PLC info mode says that card is initialized and socket is connected. In addition, when I send a PCOM string, RX counter increases which showed on info mode but the most important thing is missing: There are no replies.

The string I sent is a valid PCOM message which returns answer while I sent it over serial port and plus 6 bytes of ethernet header at the leading.

Can you please help me to figure out where is my mistake?

With my best regards

Link to post
Share on other sites

I cannot see anything wrong with what you are doing,

But without knowing what exactly you send, I cannot know if you are doing anything wrong or not.

Can you post what you send (including the ethernet header)?

It can also be usefull to post a WireShark sniffing of the packets that are transfered.

Link to post
Share on other sites

Yes Saragani, you were right! I was building correct packets but couldn't deliver them correctly to the PLC. And I figured out this just after "sniffing" the packets..

Let me explain why I can't send packets from Delphi to PLC:

Indy components are using blocking mechanism. Which means you write and read from a socket "synchronously". This simply just like a console application I/O.

I was using;

IOHandler.WriteLN()

method for sending my packet which accepts STRING as parameter. Therefore I was building my PCOM packet on a local Pascal string. And if you set a character value as zero it means your string is terminated. Although I was building correct packets, remote device had only seen first three characters because fourth character was always zero on the ethernet header..

To solve this problem, I did following:

    MsgBufferDump:  array[0..19] of byte =
   (
     $AA, $08,     // Transaction id = 2218
     101, 0,          // Protocol ID : 101 = ASCII
     14, 0,            // Payload size = 14
     47,                // STX: '/'
     48, 48,          // unit id = 00
     82, 87,          // Command: 'RW'  (Read MIs)
     0, 0, 0, 0,      // Vector base: will be filled by calling method
     53, 53,          // Vector length is fixed: 85 ($55)
     0, 0,              // checksum  : will be calculated just before sending
     13                 // ETX: <CR>
   );

Before sending, I copy this array to a stream:

sendstream:= TMemoryStream.Create;

sendstream.Write(MsgBufferDump,20);

sendstream.Position:= 0; // if you dont do this you will get an exception

IOHandler.Write(sendstream,20);

sendstream.Free;

And now it is running properly. Thank you very much for your interest.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...