Author Topic: DM[1]  (Read 16408 times)

artkraft

  • Newbie
  • Posts: 22
  • I'm a llama!
    • View Profile
DM[1]
« on: September 11, 2016, 06:33:03 PM »
Does anyone know why it does not read the DM[1]. I am using DM variables/constants in a more complicated program that work but I don't understand why. I am trying to understand how to right them so I can modify another program. This program works if I enter a value in the View variable table. What am I missing????

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:DM[1]
« Reply #1 on: September 11, 2016, 11:09:08 PM »
I think that you are using the #Define mechanism incorrectly.

Your code example has a single custom function named, "countvalue".  This is the contents of this CF:

setctrsv 1, value
[/font][/color]
You have defined value using the #Define as the following:

value        DM[1]=5
[/font][/color]
The #Define mechanism is a simple text substitution.  TBASIC will replace the text string "value" with "DM[1]=5"

So your CF after the text substitution would look like this:

setctrsv 1, DM[1]=5
[/font][/color]
The statement "DM[1]=5" is a relational statement that tests for DM[1] being equal to 5. This relational statement will evaluate to numeric 1 if DM[1] is equal to 5 or a numeric 0 if it is not. So your CF will assign either a 1 or a 0 to the SV (Set value) of COUNTER #1 depending on the value of DM[1].

I am betting that this is not what you intended.

I suspect that you wanted to assign the value of DM[1] to the SV of the counter.  If so, you need to change the #define to look more like this:

value        DM[1]
[/font][/color]
I would, also, suggest that you use the COUNTER's name rather than its number, so I'd change your custom function to look like this:

setctrsv pos, value
[/font][/color]
After TBASIC subsitiutes the text, "DM[1]" for "value" your CF  will look like this before it is complied by TBASIC:

setctrsv pos, DM[1]
[/font][/color]
However, even with these changes, I don't see that your program would do anything useful.

What are you trying to accomplish?  If you can answer this question, I could point you in a more useful direction.

Regards,

Gary D*ckinson


« Last Edit: September 11, 2016, 11:12:22 PM by garysdickinson »

artkraft

  • Newbie
  • Posts: 22
  • I'm a llama!
    • View Profile
Re:DM[1]
« Reply #2 on: September 12, 2016, 08:01:30 AM »
Thanks! Is the problem in the fact that I am simulating the program and there is no value applied to DM[1]? If I edit the DM and enter 5 in the variables table it still doesn't work. It's like it doesn't read the DM.
I've tried all your suggestions

This program is just a learning tool. I don't want to ruin/corrupt a very important program.

artkraft

  • Newbie
  • Posts: 22
  • I'm a llama!
    • View Profile
Re:DM[1]
« Reply #3 on: September 12, 2016, 08:10:03 AM »
Missed something. I am trying to get this to work.

Label name= value
Variable = DM[100] -1
This expression is the SetCtrSV 6, value "CuSfn"

[100]  is EosPlugs = EosLength/(PlugDiameter+KerfWidth)

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:DM[1]
« Reply #4 on: September 12, 2016, 11:02:44 AM »
The only question that I can answer has to do with the value of DM[1] when you run the simulator.  In simulation DM[1] will be initialized to a value 0 before your program starts.  

Can you tell me why you are attempting to change the Set Value of a COUNTER?

You understand that the Set Value of a COUNTER is not the same thing as the Present Value of the COUNTER.  The simulator will only display the Present Value of a COUNTER.

Gary D*ckinson


artkraft

  • Newbie
  • Posts: 22
  • I'm a llama!
    • View Profile
Re:DM[1]
« Reply #5 on: September 12, 2016, 09:12:59 PM »
 I control/set SetCtrSV 2, Eosplugs with DM[100] from HMI. I want to further manipulate this data with an expression.

If I understand the "mechanics"   The PLC program is pointed to DM[n] by a CusFN. Lable name " Value" from the define table points to DM[1]. "Value" is an easier way to say  DM[1] = DM[100] - 1.
Numerical values from HMI are PLUG DIAMETER and KERF WIDTH.
CusFN:
EosPlugs= EosLength/(PlugDiameter+Kerfwidth). // = DM[100]

Lable Name      Variable
EosPlugs            DM[100]
Value                 DM[1]

Add to CusFn
Value = EosPlugs -1
SETCTRSV 6, value //This should be a CRTSV 1 less than CTRSV 2  by DM[100].

To make this work in the sample program "simulation" I need to enter a value in the view variables table for DM[100] not DM[1]??????????              
.

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:DM[1]
« Reply #6 on: September 13, 2016, 08:49:32 AM »
Art,

I did my best to understand what you are trying to do. I have attached a simple program that might be useful.

Gary D*ickinson