Parsing 3 nibbles into number in Siemens

JDCROCKETT724

Member
Join Date
Jun 2010
Location
Michigan
Posts
249
All right you bit jockeys. This one has me stumped. I have data coming in as two bytes. 4 bits are my channel status and I extracted those no problem. However, I cannot figure out how to get my pressure value out correctly. No problem for positive numbers, but once I enter in C18h I do not get the -100 the manual says I should. How do I get this to work in siemens with ladder or SCL. See attached image.

Screenshot 2022-05-26 175513.jpg
 
I know OP already solved it, but for posterity, here are three equivalent methods (i.e. bookkeeping):
sign_extend.png
DB1.onek_word is a 16-bit word representing the two-byte value returned from the device with

  • one nibble of status, and
  • three nibbles composing a 12-bit twos-complement integer with a value of [pressure times 10].
 
Last edited:
Minor change to what has already been posted but in SCL:


Code:
 #rPressurekPa := (#iPressureValue * 16) / 160.0;
 

Similar Topics

Hi folks, I'm trying to parse a binary string on a Red Lion DA30D using a Raw UDP/IP input port. I've done this before with ASCII strings so I do...
Replies
38
Views
877
Hello, I have a codesys controller which I am looking to communicate with an external. User interface via mqtt. I subscribe to a topic and...
Replies
6
Views
1,410
Hello all, I have string data sent from a balance to a plc. The data cycles through every second or so which is good because it is constantly...
Replies
25
Views
6,431
Has anyone had any luck parsing XML data. I am trying to get data from MTConnect adapter and am having no luck.
Replies
2
Views
2,050
Hello everybody. Currently I am doing a project for my masters degree in EE, and one of my tasks is displaying data log on a user defined web...
Replies
0
Views
2,689
Back
Top Bottom