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.
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.
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).
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.
Tui wrote:Thanks for your repliesFrom 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 .
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.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?
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 😉
Message Edited by rolfk on 12-18-2006 09:26 PM
Message Edited by dwisti on 12-18-2006 03:25 PM
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