Converting Decimal to Binary in RSView32

dennis8437

Member
Join Date
Sep 2004
Posts
19
We have an AB 1395 drive controlled by a PLC-5/40 via RIO. We are developing a monitoring computer using RSView32. This computer will poll the PLC over a dedicated DH+ link. My problem lies in converting some values in RSView32 from an integer (16 bit) to a binary string. Several drive status or fault parameters are loaded into some words and passed to the PLC. When these are passed to the RSView32 application they are passed as decimal values. I need to break out the bits that composed these decimal numbers in the RSView32 application. I suppose I could pass them bitwise from the PLC, but I am concerned with the network capacity this might consume. I welcome any thoughts about this.

Thank you,
Dennis8437
 
but I am concerned with the network capacity this might consume

How many nodes are on the DH+


If it were I... look at do the conversion in the plc then sending your message to RSView
 
dennis8437 said:
Just the PLC and the RSView32 computer.

Don't worry about over loading, I have 10plc's (SLC) 3hmi's (RSView) on one and no issues, I have heard of more from other peoples DH+'s, you should not have any problems, we do some recipe downloads that are large and still don't have issues, so if you want to bit map it should not be a issue
 
Use the bit AND, &, operator in your RSView statement.

first bit = tag & 1
second bit = tag & 2
third bit = tag & 4
fourth bit = tag & 8
fifth bit = tag & 16
sixth bit = tag & 32
seventh bit = tag & 64.
etc.
 
I apologize for my ignorance, Alaric, but i don't understand your solution. Could you show an example for me? If the tag "STATUS" reported a value 258, how would I load the 16 RSView tags with the binary equivalent 0000000100000010 ?

Thank you,
Dennis8437
 
http://en.wikipedia.org/wiki/Binary_and

In binary the value of one is 0000000000000001.
The value of 2 is 0000 0000 0000 0010.
The value of 4 is 0000 0000 0000 0100.
etc.

If you bitwise AND the binary number in your example with 1 you get

0000000100000010 & 0000000000000001 = FALSE when assigned to a digital tag in RSView

0000000100000010 & 0000000000000010 = TRUE when assigned to a digital tag.

etc.

If you still don't get it then try this:
Open a blank screen in RSView and draw two numeric input fields with integer tagA and tagB and a rectangle. Add color animation to the rectangle to turn it red when false and green when true. Enter the statement TagA & TagB for the color animation. Test run the screen using the test button on your tool bar. Now enter a value of 1 into tag A. Enter a value of 1 in Tag B. Now enter 2, 3, 4, 5, 6, 7, 8 into tag B. Compare the results of the rectangle color to the binary values of each of those numbers. Now enter 2 into tag A. Repeat the numbers above for tag B. How does the result of the rectangle color compare to the binary values? It may help you to write out the binary values for 1 through 8 on a sheet of paper for reference.
 
I had a little more time to set up an example. Download the attached zip file and extract the BinaryExample.gfx file. Add it into a RSView progject and create the TagA tag as shown. Then test run the screen. Enter values into the TagA entry field and see which indicators change to green. Each indicator corresponds to a bit in the integer word.

A62507A.JPG
 
If you want to display an integer value created in the PLC in terms of bits in RSView32, there are a couple options.

Copy the N file word to a B file word at the PLC. Link the B file word to RSView32 and you're done; just use each bit in the B file word as usual as a discrete point on the screen.

To do it the other way- i.e., create a status word in RSView32 for use at the PLC- just reverse it. So, load each bit of the RSView32 B file word with "0" or "1", then copy that B word in the PLC to the N word that the drive is using.

The extra work for the PLC in this is minimal and if you keep just the "B" words on the comm link it is the same as if the "N" words were there. Even better, if your buffer creates a bunch of contiguous "B" words just for this comm you will be as efficient as you can get.

I would guess that you can also create a tag in RSView32, describe it as a binary, then give the address as "N7:0/0" (or whatever it is.) That gets you from the PLC to the screen as well. It is probably most efficient though to buffer back and forth with dedicated words that are contiguous in PLC memory and exist only for linking the screen and the PLC.

Finally, it has been like 100 years since I've programmed a PLC 5. If you can't just MOV or COP N to B and vice versa, of course this won't work; but that seems pretty basic!
 
There is no need to make the copy as an RSView digital tag can be assigned directly to N7:0/0 just as easily as B3:0/0. However, the OP wanted to know how to access the bits of a word that is retrieved from a drive, not from a PLC. The status word from the drive can be dismantled by bitwise AND-ing the word with a mask.

Actually, your PLC processor, on the machine code level, has to perform a bitwise AND with a mask to access any single bit since the processor takes data in 16 bit or 32 bit chunks anyways.
 
Alaric, he way I read the original post Dennis has drive-to-plc communication on RIO and plc to HMI commumnication on DH+. He isn't reading directly from the drives. Everything goes through the PLC anyway. He would be able to reference at the bit level if he wanted to.


His concern seems to be with data throughput. He wants to send a single word to the HMI that contains status info for several drives. I don't think this is a valid concern in this case. However, if this is the issue, Alaric's idea works very well and is reasonably compact.

It may not matter either way. I'm not sure how RSView32 treats a tag reference to a bit inside a word. If you try to read N7:0/0 RSView32 may read all of N7:0 and apply it's own internal mask automatically.

Keith
 
kamenges said:
It may not matter either way. I'm not sure how RSView32 treats a tag reference to a bit inside a word. If you try to read N7:0/0 RSView32 may read all of N7:0 and apply it's own internal mask automatically.

I think that is what it does, It sends the whole word anyways, but only the single bit status gets applied to a digital tag.
 
Alaric,
This is KOOL! I never would have picked up on this one. I think I can make it work in my app.
Just to clarify, If I had chosen data type as "4 digit BCD" instead of "Default" would the bits be available to me?
I also would like to thank Paul T, GIT, and Kamanges for their time and input.

Thank you,
Dennis8437
 

Similar Topics

Does anyone know how to convert from a decimal number to a true binary output. For example convert the number 15 to 1111 and then be able to turn...
Replies
9
Views
14,731
Well I am trying to cleanly convert a decimal value in a DINT to the corresponding bit in a different DINT So if I have the number 11 on in...
Replies
11
Views
1,953
I am having problems expressing an ANALOG OUTPUT 16bit INT word (0-10V Proportional Valve Voltage) as a REAL decimal number. From my...
Replies
6
Views
9,127
Do any of you Excel gurus know of a VB code or function that will convert ASCII text into it's decimal equivalent? I'm not VB savy at all. I...
Replies
3
Views
5,825
How can i convert negative decimal value(-100) to hexadecimal.
Replies
3
Views
7,608
Back
Top Bottom