DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

ChD works, but ChDx doesn't?

I wish to create a channel with 10 numbers. The following code will not fill the channel with numbers:

''''begin code''''
call DataDelAll(1)
call RootPropSet("Name","MyChannel")
Call ChnAlloc("Frequency",10,,DATATYPEFLOAT64)
CHDX(1,CNo("Frequency")) = 2.0
CHDX(2,CNo("Frequency")) = 2.1
CHDX(3,CNo("Frequency")) = 2.2
CHDX(4,CNo("Frequency")) = 2.3
CHDX(5,CNo("Frequency")) = 2.4
CHDX(6,CNo("Frequency")) = 2.5
CHDX(7,CNo("Frequency")) = 2.6
CHDX(8,CNo("Frequency")) = 2.7
CHDX(9,CNo("Frequency")) = 2.8
CHDX(10,CNo("Frequency")) = 2.9

But, if I replace CHDX with CHD, the channel will fill with my values correctly. I wish to use CHDX so my program will run faster.
See attachment if needed.

Thanks
0 Kudos
Message 1 of 6
(6,791 Views)
ChnAlloc doesn't set the actual channel length, only the maximum channel length. As a result, when you try to populate your channel, DIAdem thinks the channel length is 0 and therefore doesn't put the values into your channel.

Add the following line to your code after the ChnAlloc command to fix this:

CL("Frequency")=10

CL is the variable that contains the actual channel length of a channel.

Hope that helps,

Otmar
Otmar D. Foehner
0 Kudos
Message 2 of 6
(6,791 Views)

Dear Otmar,

         I have observed the same problem with ChnAlloc. However, I used to use: Call ChnPropValSet("Frequency", "length", 10). It worked before. But today I found that it was giving me the error: Invalid write-access to a variable "CHDX(2,258)"... I switched to your solution i.e., using CL. Is there any particular reason why DIAdem behaved like this? Was I wrong in the first place in using ChnPropValSet? Please share your thoughts.

 

With warm regards,

Saurav Mukherjee

0 Kudos
Message 3 of 6
(6,268 Views)
Hi Saurav Mukherjee,
 
Well, I don't see any problem with using the ChnPropValSet() function instead of the ChnLength() array.  Theoretically they should set the same channel property.  You didn't actually say in your post whether the CL() method resoved the error you were encountering with ChDX()-- did it?  Were you really trying to write to the 2nd value of the 258th channel?  It's real easy to accidentally switch the two parameters in ChD().  Also, can you remind me which DIAdem version you are using?
 
Brad Turpin
DIAdem Product Support Engineer
National Instruments
0 Kudos
Message 4 of 6
(6,255 Views)

Hi Brad,

       I am using DIAdem 10.2. CL() method solved my problem. I am still using the same statement involving ChDX(..) i.e., I am writing into the 2nd row in 258th column. The only change is CL() instead of ChnPropValSet().

       It also puzzles me that previously I could achieve the same with ChnPropValSet(). But,  now I need CL().

With warm regards,

Saurav

0 Kudos
Message 5 of 6
(6,229 Views)
Hello Saurav!
 
I had a similar problem with these commands and it was verry tricky to find the reason. In my case the problem was that that the value in ChnPropValSet for 'length' was a string (this seem no to be in your case) and the new length was higher than the maximum channel length. This is the code to reproduce it (DIAdem 10.2.1f3219 TDM):
Option Explicit
 
Call DataDelAll()
 
Call ChnAlloc("Test",1000)
 
Call ChnPropValSet("Test", "length", "2000")
 
MsgBox ChnLength( "Test" )
 
ChdX(1900, CNo("Test") ) = 123
ChnLength worked fine and also a ChnPropValSet with an integer.
 
Matthias
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 6 of 6
(6,222 Views)