S7 bytes to DInt

sapoleon

Member
Join Date
Aug 2003
Location
salta, salta
Posts
315
Hi.
I have a new project, and it's in siemens S7. I can say that I'm having a hard time, because it's my first project with S7.

In the project, I read a Cognex camera through Profinet, I get a result, that is a numeric code in separate bytes. So... It's like a string.

The thing is, that I have to send to an HMI this value like a DInt, and I don't have any idea on how to begin. I started looking for the IEC FC37 but it seems that I have to make a string out of the series of bytes that i get...

I get the bytes in PIB261 to PIB269 (always 9 cyphers).

I will appreciate if someone can point me in the direction on how to make a string from the bytes, so I can try the FC37 and convert it to a DInt.

Thanks.
 
Last edited:
Create a new string in a datablock with 9 chars STRING[9] then you can simply move the data from the input area. You will also need to initialize the actual value of the string either you can write '000000000' in the inital and actual value of the datablock or write

L 9
T DB1.DBB1 //Byte containg current length of string

The first two bytes of a string contains max length and current length

Here i created a string named text STRING[9] in db 1

L PIB261
T DB1.Text[1] //If your string is named text

L PIB262
T DB1.Text[2]

......

CALL "STRNG_DI"
S :=DB1.Text
RET_VAL:=MD0
 
Last edited:
Here's another example:

fc37001.JPG
 
Thanks A LOT for the quick responses.

I see that i have to take into account 2 extra bytes in the string for max length and used lenght...

That is to say, that the string will be of 11 chars, but i still define it for 9 chars.

In the method defined by Bratt, how can I access the two first bytes of the string?
 
Absolut Like DB1.DBB 0 // Max
DB1.DBB1 //Current

Or by using the pointer version like L D [AR2,P#0.0] described but then you need to write in stl format.

If its always nine chars you can create the datablock and write '000000000' in the inital and actual value of the string then you dont need to write anything in the length bytes. The 2 length bytes will always contain nine. Actually you only ned to write the zeros in actual value but its good to write it in the inital value aswell if someone decides to initziale the datablock in the future.
 
Last edited:

Similar Topics

Hello, I have just started programming RS Logix 5000 for Compact logix. What is the proper way to split a DINT to 4 bytes?
Replies
3
Views
2,832
Hi everyone! I am working on a Siemens plc (1200/1500), and I have two instruction that i have to perform. A) data structure (40 bools, 40...
Replies
3
Views
2,491
I'm working on a project that involves updating messages on a Linx printer via ControlLogix. I'm sending and receiving data via sockets and can...
Replies
6
Views
2,123
Hello, I am new to Codesys 3.5 and I am trying to figure out how to convert a word into 2 bytes to send to another plc via ethernet/ip. Could...
Replies
5
Views
5,119
We have an AB system that is connected to several CANbus networks via HMS gateways. A CAN message is comprised of upto eight, eight-bit bytes...
Replies
0
Views
1,419
Back
Top Bottom