DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Write channel length to new channel

Would someone please help me get the channel length of Channel 1 and write that property into a new Channel 2? I can get it to come up in a message box but I really want to write it to a new channel.

 

This is what I did to write it to a message box.

A = ChnPropGet("[1]/ChannelA", "length")
Call MsgBoxDisp(A)

 

Seems this should be very easy but for some reason I cannot make it work!

 

Thank you!

0 Kudos
Message 1 of 10
(3,672 Views)

Hi Karen,

 

Have you looked at this example about add new properties to a channel : http://zone.ni.com/reference/en-XX/help/370858N-01/procauto/procauto/procauto_set_new_properties_val... ?  If in doubt, you can do it manually first with the Recording Mode enabled so that the script is generated automatically 😉

 

I hope I did not misunderstand your problem. Do not hesitate to ask if something is unclear.

CLAMaxime -- Kudos are a great way to say thank you
0 Kudos
Message 2 of 10
(3,670 Views)

Thank you however this did not help me. I'm not that experienced in scripting so that may be why! If possible would someone just provide the lines of code? I have wasted a lot of time trying to figure this out looking at info in help and on this forum...

0 Kudos
Message 3 of 10
(3,662 Views)

 

I guess that would be something like :

 

Data.Root.ChannelGroups(1).Channels(2).Properties.Add("New Property",MyPropertyValue,DataTypeString);

 

Replace MyPropertyValue by the variable you use to store the first channel length.

Once again, it is just a guess you may need to do some more edits according to the script you have.

 

If you do know how to use the script, learn step by step. Using the Recording Mode is a good way to get there : http://zone.ni.com/reference/en-XX/help/370858N-01/procscript/procscript/procscript_recording_autose...

 

😉

 

CLAMaxime -- Kudos are a great way to say thank you
0 Kudos
Message 4 of 10
(3,656 Views)

Well I can't get this to work either. I do use the recording mode a lot but for some things such as this it does not work for!

0 Kudos
Message 5 of 10
(3,643 Views)

My questions :

  1. What did you modify in the code I gave you ?
  2. What test did you do and what is the result ?
  3. What do you have in your Data Portal ?

I am unsure what you mean by "but for some things such as this it does not work for". I mean, I am pretty sure the Recording Mode works just fine when you add a new custom property to a Channel. Have you tried this ?

  1. Enable the Recording Mode in Script
  2. In  the Data Portal, right-click the group you want and create a new channel (set it as needed)
  3. In the Data Portal, right-click the new channel, then New and create a custom property (set it as Numeric with a random value)
  4. Disable the Recording Mode
  5. In Script, replace the random value from 3. by the variable you store your length to.

This method will create a new channel in the specified group and add a new property to that channel which will have the same value as "Length" in Channel1.

 

Does it do what you want ?

 

 

CLAMaxime -- Kudos are a great way to say thank you
Message 6 of 10
(3,621 Views)

Use the API to create a new channel and use the "values" attribute of the channel object.

 

Option Explicit

dim chO : set chO = data.Root.ChannelGroups(1).Channels.Add("channelLength",DataTypeFloat64)
chO.Values(chO.Size + 1) = Data.Root.ChannelGroups(1).Channels("Time").Properties("length").Value
Message 7 of 10
(3,598 Views)

Andreas, Thank you so much this did exactly what I was looking for.

 

0 Kudos
Message 8 of 10
(3,587 Views)

ML927, 

Thank you for sticking with me! Your last thread did help however I didn't really want it in a custom property. Andreas's solution worked better because I need it to be a value rather than custom. Kudos to you both for your support!

0 Kudos
Message 9 of 10
(3,585 Views)

Karen,

 

Sorry for understading your problem then 😉

Feel free to post again if you need help !

 

 

CLAMaxime -- Kudos are a great way to say thank you
0 Kudos
Message 10 of 10
(3,579 Views)