NI VeriStand Add-Ons Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

ASAM HIL API for NI VeriStand 2012 Feedback

Welcome to the ASAM HIL API for NI VeriStand 2012 feedback forum. Please use this forum to provide feedback or ask questions.

Message 1 of 16
(10,775 Views)

Hi:

    I try to use this add-on with macosoft windows XP operation system,but failed. can this add-on surpport the XP system in the future? hope for you reply. my email gang.wang@hirain.com ,if there are any available version ,please send me a copy. thanks.(sorry for my poor english)

0 Kudos
Message 2 of 16
(4,906 Views)

Hi,

we will try to create a package that supports Windows XP and send this to you as soon as we have it.

0 Kudos
Message 3 of 16
(4,906 Views)

thanks!!

0 Kudos
Message 4 of 16
(4,906 Views)

Hi,I'm back~ now I'm trying the api in Win7 System(but look forward for your xp version).

qustion1:

I runned the two demos,and runs fun. But I want use the capture Result function, and failed. below is the code that I tried(that is the Main Method).

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

        static void Main(string[] args)
        {
            Dictionary<string, string> ConfigurationDictionary;
            MAPort NIMAPort;
            ConfigurationDictionary = new Dictionary<string, string>();
            ConfigurationDictionary.Add("ConfFilePath", "VSConfig.xml");

            //create ConfigurationDictionary
            if (!File.Exists("VSConfig.xml"))
            {
                // ERROR case
                System.Environment.Exit(-1);
            }
            else
            {
                // Create new instance of dictonary object  and write key value pair to it
                ConfigurationDictionary = new Dictionary<string, string>();
                ConfigurationDictionary.Add("ConfFilePath", Directory.GetCurrentDirectory()   "\\VSConfig.xml");
            }
            //create MAPort
            NIMAPort = new MAPort(ConfigurationDictionary);
           
            #region Abort program if no task in config file
            if (NIMAPort.TaskNames.Count < 1)   // Check if at least one task is present. Otherwise, abort program
            {
                Console.Write("No task found in config file. Hit any key to abort program ");
                Console.ReadKey();
                System.Environment.Exit(-1);    // Exit program
            }
            #endregion

            //create capture
            ASAM.HILAPI.Interfaces.Common.Capturing.ICapture capture =
                NIMAPort.CreateCapture(NIMAPort.TaskNames.ElementAt(0));
            ASAM.HILAPI.Interfaces.Common.Capturing.ICaptureResultMemoryWriter captureResultMemWriter =
                new ASAM.HILAPI.Implementation.Veristand.Capturing.CaptureResultMemoryWriter();

            // Create a list to define capture variables
            IList<string> captureVariables = new List<string>();
            captureVariables.Add("Targets/Controller/Simulation Models/Models/Engine Demo/Outports/EngineTemp");
            captureVariables.Add("Targets/Controller/Simulation Models/Models/Engine Demo/Outports/RPM");
            capture.Variables = captureVariables;

            // create durationWatcher. End capturing after 5s
            ASAM.HILAPI.Interfaces.Common.WatcherHandling.IDurationWatcher durationWatcher =
                new ASAM.HILAPI.Implementation.Veristand.WatcherHandling.DurationWatcher(5);
            capture.SetStopTriggerCondition(durationWatcher, 0);

            // Start capturing
            capture.Start(captureResultMemWriter);

            while (capture.State != ASAM.HILAPI.Interfaces.Common.Capturing.CaptureState.eFINISHED)
            {
                ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatValue valueRead =
                    (ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatValue)NIMAPort.Read("Targets/Controller/Simulation Models/Models/Engine Demo/Outports/EngineTemp");
                Console.WriteLine("readValue"   valueRead.Value);
                System.Threading.Thread.Sleep(1000);
            }

            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("capture.State=ASAM.HILAPI.Interfaces.Common.Capturing.CaptureState.eFINISHED");

            /////////////////////////////////////////////////////////////////////////////////////////////below code can throws exception

            ASAM.HILAPI.Interfaces.Common.CaptureResult.ICaptureResult captureResult = capture.CaptureResult;
            int len = captureResult.SignalGroupNames.Length;
            for (int i = 0; i < len; i  )
            {
                Console.Write(captureResult.SignalGroupNames   ",");
            }

            Console.ReadKey();
        }

---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------

I can't get the ICaptureResult in this way.can you supply a demo about how to use ICaptureResult. thanks!!!

by the way , I can get the ICaptureResult use the fetch function , but when I use the gotten ICaptureResult, it throws other exception.

qustion2:

In the VSconfig.xml , what does the <TaskList> tag mean? e.g. the Task100 set the Downsampling 100Hz? but when I check the log file,it seems having no effect.

when I use capture function with this api,I want to set down sample using capture's Downsampling function. but when I check the log file,it seems having no effect.

0 Kudos
Message 5 of 16
(4,906 Views)

Hi wulidaoxue,

in regards to question 1:

you have to switch your capture object in the eCONFIGURED state if you want to access the CaptureResult object of your capture (see page 84 of the ASAM HiL API Programmer's guide). You can achieve this by stoping your capture.

By adding the following code before accessing the CaptureResult of your capture object will stop your capture:

          Console.WriteLine("capture.State=ASAM.HILAPI.Interfaces.Common.Capturing.Captur eState.eFINISHED");

          // stop capturing

          capture.Stop()

          /////////////////////////////////////////////////////////////////////////////// //////////////below code can throws exception

          ASAM.HILAPI.Interfaces.Common.CaptureResult.ICaptureResult captureResult = capture.CaptureResult;

concerning question 2:

The TaskList entries in the VSConfig.xml file are used to provide information about the possible log rates of the system. It has to be matched to the target rate of your NI VeriStand configuration. If you want to use downsampling, you can use the Downsampling property of your capture (e.g.: capture.Downsampling = 10). The log files are used only internally and the downsampling has no effect on them, however the captureResult will contain the "downsampled" values.

Thanks

Balazs

Message 6 of 16
(4,906 Views)

Hi Balazs,

    thanks to your reply.

    I add the code you supply and get the captureResult,but the next line's code : captureResult.SignalGroupNames throws "System.NotImplementedException".I want to get the SignalGroupNames to use the ExtractSignalValue method.

    I want to use the captureResult with its ExtractSignalValue or GetSignalGroupValue methods to get this capture's result in ISingalValue or ISingalGroupValue format.

question1:the ExtractSignalValue method need signalGroupName and variable arguments, so how can I get the signalGroupName? In fact I don't know how to use signalGroupName in NI asam hil api.

question2:how to use the GetSignalGroupValue method?

when I try the two method(maybe in wrong way),I always get the "NotImplementedException".

Thanks

wulidaoxue

0 Kudos
Message 7 of 16
(4,906 Views)

Hi wulidaoxue,

SignalGroupNames are not used for the CaptureResult object. Although it is the first parameter of the ExtractSignalValue method, but it is ignored. You should use an empty string for the SignalGroupValue. Could you please test the following code for getting the result of your capture:

          Console.WriteLine("capture.State=ASAM.HILAPI.Interfaces.Common.Capturing.Captur eState.eFINISHED");

          // stop capturing

          capture.Stop()


          // get CaptureResult

          ASAM.HILAPI.Interfaces.Common.CaptureResult.ICaptureResult captureResult = capture.CaptureResult;

          // Extract signal values

          ASAM.HILAPI.Interfaces.Common.ValueContainer.ISignalValue mySig1 = captureResult.ExtractSignalValue("",captureVariables[0]);

          ASAM.HILAPI.Interfaces.Common.ValueContainer.ISignalValue mySig2 = captureResult.ExtractSignalValue("",captureVariables[1]);

          // get the values

          ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatVectorValue time = (ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatVectorValue)mySig1.XVector;

          ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatVectorValue engineTemp = (ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatVectorValue)mySig1.FcnValues;

Thanks

Balazs

Message 8 of 16
(4,906 Views)

Hi Balazs,

    I test the code you give, and the ExtractSignalValue method works fine.

    but when I try to save the captureResult with following code , it throws "NotImplementedException"

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Console.WriteLine("capture.State=ASAM.HILAPI.Interfaces.Common.Capturing.Captur eState.eFINISHED");

    // stop capturing

    capture.Stop()


    // get CaptureResult

    ASAM.HILAPI.Interfaces.Common.CaptureResult.ICaptureResult captureResult = capture.CaptureResult;

    // Extract signal values

    ASAM.HILAPI.Interfaces.Common.ValueContainer.ISignalValue mySig1 = captureResult.ExtractSignalValue("",captureVariables[0]);

    ASAM.HILAPI.Interfaces.Common.ValueContainer.ISignalValue mySig2 = captureResult.ExtractSignalValue("",captureVariables[1]);

    // get the values

    ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatVectorValue time = (ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatVectorValue)mySig1.XVector;

    ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatVectorValue engineTemp = (ASAM.HILAPI.Interfaces.Common.ValueContainer.IFloatVectorValue)mySig1.FcnValue s;

    //create the ICaptureResultWriter

    ASAM.HILAPI.Interfaces.Common.Capturing.ICaptureResultMDF40Writer writer

          = new ASAM.HILAPI.Implementation.Veristand.Capturing.CaptureResultMDF40Writer("F\\test.MDF");

    //or create the ICaptureResultMemoryWriter

    ASAM.HILAPI.Interfaces.Common.Capturing.ICaptureResultMemoryWriter writer2

          = new ASAM.HILAPI.Implementation.Veristand.Capturing.CaptureResultMemoryWriter();

    //save it. the below code throws "NotImplementedException"

    captureResult.save(writer);

    //save it. if use below code,it also throws "NotImplementedException"

    //captureResult.save(writer2);

   

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I read the "ASAM HIL API for NI VeriStand 2012" and find out that the capture result data is saved in the TDMS file, but I don't know how to get captureResult object from the TDMS file and how to save captureResult object to TDMS file.

so, please point out how to use the captureResult' save and open methods in NI ASAM HIL API.

0 Kudos
Message 9 of 16
(4,906 Views)

Hi wulidaoxue,

there are no CaptureResultWriters implemented at the moment that could be used for saving the CaptureResult object into a file. The TDMS log files that are created by the system used only internally. If you would like to save your capture results into a file, you could use the following code for example to save the results into a csv file:

          string fileName = string.Format("{0}.csv", "MyFile");

          TextWriter my_writer = new StreamWriter(fileName);

          // Separator for the csv-File

          string cCsvFileSeparator = ";";

          my_writer.WriteLine("time ;\t EngineTemp;\t RPM");

          FloatVectorValue time = (IFloatVectorValue)mySig1.XVector; 

          FloatVectorValue engTemp = (IFloatVectorValue)mySig1.FcnValues; 

          FloatVectorValue rpm_vals = (IFloatVectorValue)mySig2.FcnValues; 

          for (int i = 0; i < time.Count; i++)

          {

               my_writer.WriteLine("{0,12:f8} ; {1,12:f8} ; {2,12:f8}", time.Value, engTemp.Value, rpm_vals.Value);

          }

Hope this helps.

Thanks

Balazs

0 Kudos
Message 10 of 16
(4,906 Views)