From 01:00 AM CDT Saturday, June 10 - 04:00 AM CDT Saturday, June 10, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 01:00 AM CDT Saturday, June 10 - 04:00 AM CDT Saturday, June 10, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
11-13-2015 09:15 AM
Can someone please help me with this block of code that I have? I do not understand why on the first execution it works fine with no daq Exception errors, but on the second execution I get an error.
More detailed, I am creating a virual channel in one Sub with a button click event. That virtual channel is set to default values (MIN = -10, MAX = +10, Linear Scale with Scale and Offset at 1 and 0 respectively).
In the other Sub click event, is where I am having the difficulties. In this Sub I am creating the custom scales and assigning values to them, setting the MIN and MAX values of the virtual channel to the same minimum and maximum values of the Custom Scale being used, and then finally assigning that new custom scale to the virtual channel to use. The code works for the first execution. When I change the scaling and then execute the code again for a second iteration, I get a daq Exception error.
Its appears that the MIN and MAX are getting set on the second execution but the Scaling is not being reset to a the new scale values. Can someone verify and if so, what is wrong and needs to be changed in my code?
First Execution of the "DownLoad" button click event to assign the custom scale with its values to the virtual chanel.....works fine.
Change the Scaling, in this case from 400 to 600, and then execute the same code again with the "Download" button click event and I get the daqException Error
myTask.Control(TaskAction.Stop) PreScaledVals.TrimExcess() : PreScaledValsArray = PreScaledVals.ToArray ScaledVals.TrimExcess() : ScaledValsArray = ScaledVals.ToArray If chkBoxTblScale.Checked = True Then Try min = ScaledValsArray.First max = ScaledValsArray.Last Catch ex As Exception MessageBox.Show(ex.Message & " Table Scale must contain at least two prescaled values and two scaled values.") Return End Try ElseIf chkBoxLinScale.Checked = True Then min = numEdtMIN.Value max = numEdtMAX.Value ElseIf chkBoxMapScale.Checked = True Then min = numEdtSMin.Value max = numEdtSMax.Value End If LinScale = New DAQmx.LinearScale("Linear Scale", scale, offset) RMPScale = New DAQmx.RangeMapScale("Ranged Map Scale", prescaledMin, prescaledMax, scaledMin, scaledMax) If chkBoxTblScale.Checked = True Then Try TblScale = New DAQmx.TableScale("Table Scale", PreScaledValsArray, ScaledValsArray) Catch ex As DaqException MessageBox.Show(ex.Message) End Try End If Try If cboBoxChannels.Text = "6" Then ChannelSelected = 6 ElseIf cboBoxChannels.Text = "7" Then ChannelSelected = 7 ElseIf cboBoxChannels.Text = "8" Then ChannelSelected = 8 ElseIf cboBoxChannels.Text = "9" Then ChannelSelected = 9 ElseIf cboBoxChannels.Text = "10" Then ChannelSelected = 10 ElseIf cboBoxChannels.Text = "11" Then ChannelSelected = 11 ElseIf cboBoxChannels.Text = "12" Then ChannelSelected = 12 ElseIf cboBoxChannels.Text = "13" Then ChannelSelected = 13 ElseIf cboBoxChannels.Text = "14" Then ChannelSelected = 14 Else : ChannelSelected = 15 End If Select Case ChannelSelected Case 6 myTask.AIChannels(lblCh6Wfg.Text).Minimum = min myTask.AIChannels(lblCh6Wfg.Text).Maximum = max If chkBoxLinScale.Checked = True Then myTask.AIChannels(lblCh6Wfg.Text).CustomScaleName = "Linear Scale" ElseIf chkBoxTblScale.Checked = True Then myTask.AIChannels(lblCh6Wfg.Text).CustomScaleName = "Table Scale" ElseIf chkBoxMapScale.Checked = True Then myTask.AIChannels(lblCh6Wfg.Text).CustomScaleName = "Ranged Map Scale" End If TblScale = Nothing RMPScale = Nothing LinScale = Nothing
Thank you
Solved! Go to Solution.
11-13-2015 12:22 PM
Watch what you are doing with the New .
If the object doesn't exist then you want to create it, but once it is created, you should be modifying it.