03-06-2013 06:47 PM
kstylian wrote:
I understand what you are saying, but I'm having a difficult time realizing the implementation (newbie). Would you mind supplying example code to explain/clarify the logic?
Right-click the edge of your while loop to create a shift register. Wire a false constant to it. Then, where you check to see if you've reached the desired time, also check if that shift register value is false. If it is, generate the event, and set the shift register to true. Otherwise, pass the shift register value through the case structure unchanged.
As I mentioned, you'll also need to reset that shift register back to false whenever you enter a new time. You could do this with an extra button, or an event case when the time target changes.
03-07-2013 05:22 PM
>>Right-click the edge of your while loop to create a shift register. Wire a false constant to it. Then, where you check to see if you've reached the desired time, also check if that shift register value is false. If it is, generate the event, and set the shift register to true. Otherwise, pass the shift register value through the case structure unchanged.
>> As I mentioned, you'll also need to reset that shift register back to false whenever you enter a new time. You could do this with an extra button, or an event case when the time target changes.
Thanks again for your help. I got the above working fine. It only passes the Value (Signaling) property once during the minute duration when both current time and set time are equal. I did this with a nested case and some logic. I'm still using a string comparison, but this is secondary until I figure out the following.........
If I try to execute the event by with a Value Change initiated by a control ("Set Initial Resistance Grams Force"), both OldVal and NewVal appear to function correctly. OldVal = NewVal and NewVal = Value Change control value.
If I try to execute the same event with a value change initaiated by the Value Signaling property of "Resistance at Time 1", both OldVal and NewVal take on the value of "Resistance at Time 1".
What's going on here?
03-07-2013 05:46 PM
kstylian wrote:
If I try to execute the event by with a Value Change initiated by a control ("Set Initial Resistance Grams Force"), both OldVal and NewVal appear to function correctly. OldVal = NewVal and NewVal = Value Change control value.
If I try to execute the same event with a value change initaiated by the Value Signaling property of "Resistance at Time 1", both OldVal and NewVal take on the value of "Resistance at Time 1".
It took me a couple of tries, but I think I understand your problem, and it's expected behavior. NewVal and OldVal are relative to whatever control caused the event. You handle three different numeric controls in the same event case, but you seem to be under the impression that OldVal and NewVal will only apply to one of them. I'm not sure why you need to handle value change events for Control Output for Time 1 and 2 at all, since you don't seem to be doing anything with them, but if you do want to handle them perhaps you shouldn't do it in the same case where you handle Set Initial Resistance.
03-13-2013 02:45 PM
Ultimately, I need to control a stepper motor. I need to set the the initial position (Set Initial Resistance Grams Force gf), then at specific times (Set Time 1 and 2) change the position of the stepper (Resistance at Time 1 and 2). The program needs to remember the current position of the stepper, read in the new position, find the difference between new and current position, then send the correct number of steps to the motor.
>>NewVal and OldVal are relative to whatever control caused the event. You handle three different numeric controls in the same event case, but you seem to be under the impression that OldVal and NewVal will only apply to one of them.
OK. I didn't realize OldVal and NewVal stores the values for each individual control that triggers that event. I believed they were generic (control independent) and would store whatever value was passed into the event case, regardless of what control passed the value. I.E. passing in a value from control#2 would set the NewVal to the obvious new value passed, and OldVal would be whatever the previous NewVal was, regardless of what control passed it, say control#1. This is the reason I had three numeric controls for the case.
This still does not explain why when triggering an event with a value(signaling) property, OldVal and NewVal return the same result (NewVal=OldVal). I can trigger this event numberous times, with different values, and NewVal will always = OldVal.
>>I'm not sure why you need to handle value change events for Control Output for Time 1 and 2 at all, since you don't seem to be doing anything with them, but if you do want to handle them perhaps you shouldn't do it in the same case where you handle Set Initial Resistance.
Since I can't trigger an event with an indicator, Control Output for Time 1 and 2 is what triggers the one of the event cases with a Value(signaling) property. I set the control "Resistance at Time 1", then when "Current Time" = "Set Time 1", it sends "Resistance at Time 1" to indicator "Control Output at Time 1".
So, I'm still stuck or maybe I'm not understanding what you are suggesting. . I still need to pass in values based on three conditions/events (Set Initial Resistance, Resistance at Time1, Resistance at Time 2), make calculations based on current position and new position, and remember the new current position for future calculations. Is a case structure not the right tool? Can a local variable be used here instead........set the three conditions to a common variable when appropriate and trigger a case based on a change to the one vocal variable? Any help or guidance would be greatly appreciated…….
03-13-2013 03:35 PM
@kstylian wrote:
Ultimately, I need to control a stepper motor. I need to set the the initial position (Set Initial Resistance Grams Force gf), then at specific times (Set Time 1 and 2) change the position of the stepper (Resistance at Time 1 and 2). The program needs to remember the current position of the stepper, read in the new position, find the difference between new and current position, then send the correct number of steps to the motor.
This isn't shown in the VI you most recently uploaded, so I can't tell how you're doing this. However, if you were going to use NewVal and OldVal to keep track of the new and old stepper position, that's the wrong way to do it. Use a shift register to track the old position.
kstylian wrote:
This still does not explain why when triggering an event with a value(signaling) property, OldVal and NewVal return the same result (NewVal=OldVal). I can trigger this event numberous times, with different values, and NewVal will always = OldVal.
Your code writes the same value to the indicator as you write to the Value (Signaling) property. The indicator updates immediately, then the event fires. The old value in the indicator is whatever it was just before the event fired, which, not surprisingly, is the value you just wrote to it.
As an aside, usually you don't capture events on indicators.
kstylian wrote:
Since I can't trigger an event with an indicator, Control Output for Time 1 and 2 is what triggers the one of the event cases with a Value(signaling) property. I set the control "Resistance at Time 1", then when "Current Time" = "Set Time 1", it sends "Resistance at Time 1" to indicator "Control Output at Time 1".
So, I'm still stuck or maybe I'm not understanding what you are suggesting. . I still need to pass in values based on three conditions/events (Set Initial Resistance, Resistance at Time1, Resistance at Time 2), make calculations based on current position and new position, and remember the new current position for future calculations. Is a case structure not the right tool? Can a local variable be used here instead........set the three conditions to a common variable when appropriate and trigger a case based on a change to the one vocal variable? Any help or guidance would be greatly appreciated…….
Too much of your logic is missing from the code you uploaded for me to provide a helpful suggestion. I would recommend that you have a one control for Resistance Setpoint and you write to the Value (Signaling) property for that single control, instead of the unused "Control Output for Time 1" (and 2).