LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview to Siemens PLC via Ethernet/TCP

Hi,
I have created a simple app that uses the Labview TCP functions (as the example Simple Server/Client VI's) to write to a Siemens S400 PLC via Ethernet.
While I can see that the data arrives in the PLC, the values I send (Int 1-99) are different to what I send, and for each value sent 3 values are received.
 
Is there a document/link that can help me?
0 Kudos
Message 1 of 11
(7,871 Views)

Since you can't have a LabVIEW client running on the PLC, this would only work if you format the sent data properly. Since you didn't post any code, it's hard to understand exactly what you're doing, but I would guess that you're sending a number that's too large (for instance, a 32 bit number, which is 4 bytes, instead of a 16 bit number, which is 2 bytes).

I suggest that you try using a standard communication method like OPC or Modbus to connect to the PLC. I believe that if you search this board for "Siemens" you should find some threads.


___________________
Try to take over the world!
0 Kudos
Message 2 of 11
(7,851 Views)


@Tui wrote:
Hi,
I have created a simple app that uses the Labview TCP functions (as the example Simple Server/Client VI's) to write to a Siemens S400 PLC via Ethernet.
While I can see that the data arrives in the PLC, the values I send (Int 1-99) are different to what I send, and for each value sent 3 values are received.
 
Is there a document/link that can help me?


You have to refer to the Simens protocol documentation. They should document the exact binary data format you need to send. Quite likely the protocol you are looking for is really binary in nature, that means you can't write a number as a string but need to directly send the binary data format. Also Siemens likes to use somewhat strange number formats such as BCD or even more involved binary encoding. Your documentation should tell you what it exactly expects.

As far as LabVIEW is concerned you have two things to watch out:

- Doing binary data is best done by building a UINT8 array of data instead of using strings. Use the Byte Array To String fucntion just beofre wiring the data array to the TCP/IP functions that require a string input. Logically a string and a byte array are the same. I's just about how LabVIEW shows them to you that is really different.

- If you format data into the byte array that is bigger than one byte (words, integers, etc) you have to be aware of Endianess of the data. I order to support platform indpendant operation LabVIEW always defaults to Big Endian format meaning the highest significant byte is first. Intel CPUs and most systems Siemens has, use Little Endian which has the lowest significant byte first. Before LabVIEW 8 you had to use the Swap Bytes and Swap Words functions explicitedly to change the number format. From LabVIEW 8 onwards the Flatten and Unflatten functions allow you to select the Endianess of the data.

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
Message 3 of 11
(7,848 Views)
Thanks for your replies
 
From searching this forum I see that most are being told to use OPC or Modbus.  I don't have that option as we have several projects that will require TCP communication with Labview .
 
I am sending a 2byte number flattened to string, which is the same size Siemens use to store Ints.
 
Part of my problem is the lack of documentation on the Siemens end .
 
Rolf, wll try the array approach.  Is the Endian conversion required for any datatype that uses more than 1 byte, or only for arrays?
 
Tui
0 Kudos
Message 4 of 11
(7,820 Views)

The fact that you're using TCP does not mean that you can not use Modbus or OPC, as both allow writing to registers of the PLC and can be used over TCP/IP connections.

If you want to use the Siemens protocol, you will have to write VIs which will implement that protocol.

The TCP VIs require a string as an input, but the string is simply a way of representing a series of bytes - What Rolf was saying was that it is easier to build a 1D array of bytes (U8) and then convert that to a string by using the Byte Array to String function, but any sequence of bytes would be subject to endianess. You're probably better off looking for VIs which already implement the Siemens protocol or use Modbus or OPC. In any case, if you want to implement the protocol, you should definitely find good documentation of it before you start.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here, here, here, here and here are a few you can start with and here are some tutorial videos. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
0 Kudos
Message 5 of 11
(7,812 Views)

Tui wrote:
Thanks for your replies
 
From searching this forum I see that most are being told to use OPC or Modbus.  I don't have that option as we have several projects that will require TCP communication with Labview .
Actually as tst said using OPC or Modbus does not preclude TCP/IP connections. What might be your issue however is that both solutions usually require some extra software and cost (OPC interface server from Siemens or third party or Modbus protocol support for your Siemens controller) as that is how Siemens works.
I am sending a 2byte number flattened to string, which is the same size Siemens use to store Ints.
 
Part of my problem is the lack of documentation on the Siemens end .
This is a well known issue. Siemens does not document their protocols well or more precesily usually only in some hard to find and/or quite expensive software interfaces. What I usually had most success with is searching the web for other examples, source code etc. for the protocol in question. It might sometimes involve Pascal code or even less known code such as shell scripts but can be a tremendous starting point to go from.
Rolf, wll try the array approach.  Is the Endian conversion required for any datatype that uses more than 1 byte, or only for arrays?
 

Yes any data type contained in your stream that has more than 1 byte (words, integers, BCDs, Timers etc, will likely have Endian issues. The good news is that LabVIEW is always Big Endian and the other side always either Big Endian or Littele Endian. I have never come across a system that mixed the Endianess on its side 😉

Rolf Kalbermatter

Message Edited by rolfk on 12-18-2006 09:26 PM

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 11
(7,809 Views)
Thank you both.
 
I got the communication going by simplifying, just flatten value to string and send.  Siemens must use big Endian.
 
We are using Ethernet/TCP for cost reasons.
 
On the learning side I have spent days doing tutorials and reading on the net, and searching the forums.
While the NI site is excellent, I appreachiate your prompt support.
0 Kudos
Message 7 of 11
(7,802 Views)
As others on this site might not be aware, Siemens PLC have functions to directly get at the Ethernet port buffer. FC60 AG_LRECV and FC50 AG_LSEND can be use to create your own protocol.  Siemens protocols are usually not documented.  And yes, Siemens S7-400 is big-endian.

Message Edited by dwisti on 12-18-2006 03:25 PM

0 Kudos
Message 8 of 11
(7,799 Views)

Good day I am a student and I'm working on a project that also requires me to communicate stings to a siemens PLC via TCP/ethernet. I was hoping you could help me by telling me which connection type you used to connect to the PLC and what is the simplest way checking the connection. THanks

0 Kudos
Message 9 of 11
(6,496 Views)

Hello,

 

I know it's an old thread, but anybody have an example?

 

Thank you!

0 Kudos
Message 10 of 11
(5,002 Views)