You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old September 23rd, 2023, 01:50 PM   #1
g.mccormick
Lifetime Supporting Member
United States

g.mccormick is offline
 
Join Date: Jul 2012
Location: IN
Posts: 944
Horner Cscape Tag based. Move real to int array

I seem to be making this harder than it should be, and Its not making any sense.

I simply need to move a real variable to two integer variables that are an array.

Input is structure element real value, output to array elements [0] and [1].

If I select mov or block move I keep getting errors that the type is mismatched.

What am I supposed to select?
  Reply With Quote
Old September 23rd, 2023, 04:28 PM   #2
TheWaterboy
Lifetime Supporting Member + Moderator
United States

TheWaterboy is offline
 
TheWaterboy's Avatar
 
Join Date: May 2006
Location: State of Denial
Posts: 1,774
Use BTD command to move bit 0 (with a length of 16) into INT [0] and then another BTD moving bits starting at 16 into INT[1]
(didnt read the Horner disclaimer, perhaps there is an equivalent bit level move)
__________________
There are 2 kinds of people in the world... (1) Those that can derive answers from incomplete Data
  Reply With Quote
Old September 23rd, 2023, 05:20 PM   #3
Steve Bailey
Lifetime Supporting Member + Moderator
United States

Steve Bailey is offline
 
Steve Bailey's Avatar
 
Join Date: Apr 2002
Location: The boondocks of Western Massachusetts USA
Posts: 8,350
Quote:
I simply need to move a real variable to two integer variables that are an array.
Could you explain what you mean by that? Suppose your REAL variable has a value of 3.14159. What values would you like to see in INT[0] and INT[1]? Splitting the lower and upper 16 bits of a 32-bit REAL variable into two 16-bit integers doesn't result in any meaningful data in either of the two INTs.
  Reply With Quote
Old September 23rd, 2023, 08:58 PM   #4
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 7,296
I think that if you write the real to a %R register e.g. %R1, then it will move the real value to two consecutive 16-bit registers i.e. %R1 and %R2, like this:
Untitled.png

Untitled1.png
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (but no longer ∞ ).
vi) Hakuna matata.
vii) Bookkeeping.
viii) But I should be ignored.
  Reply With Quote
Old September 23rd, 2023, 09:58 PM   #5
g.mccormick
Lifetime Supporting Member
United States

g.mccormick is offline
 
Join Date: Jul 2012
Location: IN
Posts: 944
Quote:
Originally Posted by Steve Bailey View Post
Could you explain what you mean by that? Suppose your REAL variable has a value of 3.14159. What values would you like to see in INT[0] and INT[1]? Splitting the lower and upper 16 bits of a 32-bit REAL variable into two 16-bit integers doesn't result in any meaningful data in either of the two INTs.


Steve,
I know that it wont be meaningful in the ints. I need to move some data into registers that will be read via modbus. So I have an array of INTS starting at %R1..%R50.
I need to move the bits of my real variable into the 32bits of two consecutive array elements (ie. 32 bits into %R1 and %R2).
  Reply With Quote
Old September 23rd, 2023, 10:00 PM   #6
g.mccormick
Lifetime Supporting Member
United States

g.mccormick is offline
 
Join Date: Jul 2012
Location: IN
Posts: 944
Quote:
Originally Posted by drbitboy View Post
I think that if you write the real to a %R register e.g. %R1, then it will move the real value to two consecutive 16-bit registers i.e. %R1 and %R2, like this:
Attachment 66580

Attachment 66581


I am using the tag based, which auto assigns registers (messily I might add).

I have information in real variables at unknown register indexs (since the software automatically assigns them). I want to copy the bits from the reals into two consecutive elements of an array of INTs. This array of INTs I have created at specific registers so that the values can be read via modbus.
  Reply With Quote
Old September 23rd, 2023, 10:24 PM   #7
Steve Bailey
Lifetime Supporting Member + Moderator
United States

Steve Bailey is offline
 
Steve Bailey's Avatar
 
Join Date: Apr 2002
Location: The boondocks of Western Massachusetts USA
Posts: 8,350
I had a feeling that might be your reason.
Horner used to pretty closely follow GE Fanuc's approach. If that is still the case, then you may be able to assign the same address to different variables. You could assign the REAL variable to %R00100, which would actually use %R00100 and %R00101. Then you could create a two-element INT array with a different variable name, but assign it to a starting address of %R00100. No need to use any MOVE instructions in logic.
I don't have the latest version of CScape, so I can't set it up myself to see if validates.

Last edited by Steve Bailey; September 23rd, 2023 at 10:27 PM.
  Reply With Quote
Old September 23rd, 2023, 10:33 PM   #8
g.mccormick
Lifetime Supporting Member
United States

g.mccormick is offline
 
Join Date: Jul 2012
Location: IN
Posts: 944
Quote:
Originally Posted by Steve Bailey View Post
I had a feeling that might be your reason.
Horner used to pretty closely follow GE Fanuc's approach. If that is still the case, then you may be able to assign the same address to different variables. You could assign the REAL variable to %R00100, which would actually use %R00100 and %R00101. Then you could create a two-element INT array with a different variable name, but assign it to a starting address of %R00100. No need to use any MOVE instructions in logic.
I don't have the latest version of CScape, so I can't set it up myself to see if validates.
If I had started all of this on the register based software then I could have probably done that. As it is, I am writing in the "tag based" software. The tag based automatically assigns register values without the user needing too. It also allows structures and user defined function blocks. The reals that I am interested in are part of structures that I created.


I will try to create a real and ints at the same starting register then I can copy my structure real value to the sacrificial real. That may work!
  Reply With Quote
Old September 23rd, 2023, 11:03 PM   #9
g.mccormick
Lifetime Supporting Member
United States

g.mccormick is offline
 
Join Date: Jul 2012
Location: IN
Posts: 944
Steve thank you for the idea!

That worked. I created 2 arrays (Array of ints 0-49 and array of reals 0-24) both starting at %R1. Now I can copy real values to the real array elements or mess with copying data into the integer array and the correct bits show up at the correct registers!

Thanks Steve!
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Accessing Studio 5000 Tag Based Alarms in Red Lion Crimson einnh LIVE PLC Questions And Answers 0 October 9th, 2020 12:51 PM
Not able to understand this S7-code drspanda LIVE PLC Questions And Answers 8 November 13th, 2007 02:06 PM
Cscape Horner ocs problem Unregistered LIVE PLC Questions And Answers 1 May 10th, 2007 06:55 PM
Building an S7 Array Move Questions DesertDog LIVE PLC Questions And Answers 19 June 17th, 2004 11:51 AM
Ideas needed for Siemens S7 program tesalmin LIVE PLC Questions And Answers 12 March 4th, 2004 02:40 PM


All times are GMT -4. The time now is 12:15 PM.


.