Jump to content
  • 0

Analog Discovery Pro Logger with script


Albertu95

Question

Hello,
I'm trying to make a script in order to use the logger of the Analog Discovery Pro. 
My final aim is to obtain a script that takes x measurements in an y time frame and that saves this values in a .csv file automatically. 

To be more clear I will make an example:
I would like to take 100 samples of all the 4 analogical channels equally spaced in an interval of around 2ms and then save all this values automatically in a .csv file

I tried to understand how to do it from the help but it's pretty abstract and I couldn't find anything similar to start with on the forum

I also saw that is possible to use the scope as logger but even in this case is not that clear for me how to set it up in the scrip and when it is more convenient to use one or another.

Can somebody help me?
@attila can you please help me if you have time?

Edited by Albertu95
Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Hi @Albertu95

There are many ways of doing it, depending on the exact requirements.
You could perform a long capture/record, process the data and save it, like this:

image.png

image.png

 

if(Index>Maximum) Scope.stop();
const div = 100;
for(var c = 0; c < 4; c++){
    var rgc = Scope.channel[c].data;
    var n = rgc.length;
    var rgr = [];
    var v = 0;
    for(var i = 0; i < n; i++){
        var j = i%div;
        if(j==div-1){
            rgr.push(v/div);
            v = rgc[i];
        }else{
            v += rgc[i];
        }
    }
    FileWrite("~/Desktop/test/cap"+Index+"ch"+c+".csv", rgr);
}
Index++;

 

Link to comment
Share on other sites

  • 0

Hello,

thank you for your quick answer @attila!

In the meanwhile, I wrote down a script in a different way that it works.
The only thing that does not work is the automatic export, I don't understand how can I make it work.

My code:

 

// This script adjusts the Wavegen offset based on Scope measurement.
clear()
if(!('Scope' in this)) throw "Please open Scope";

/////important/////
////open channels and math channels from the gui


Scope1.Trigger.Type.text= "edge";
Scope1.Trigger.Condition.text= "rising";
Scope1.Trigger.Level.value=0.5;
Scope1.Trigger.Hysteresis.text = "auto";//value of hysteresis



//time setup
Scope1.Time.Position.value = 0;
Scope1.Time.Rate.text = "10Hz";
Scope1.Time.Samples.text= "128";
Scope1.Time.Mode.text= "Record";
//put oversampling off

//sample mode
Scope1.Channel1.SampleMode.text= "average";
Scope1.Channel2.SampleMode.text= "average";
Scope1.Channel3.SampleMode.text= "average";
Scope1.Channel4.SampleMode.text= "average";


//"calibration" probes
Scope1.Channel1.Zero.text= "0V";
Scope1.Channel2.Zero.text= "0V";
Scope1.Channel3.Zero.text= "-0.2mV";
Scope1.Channel4.Zero.text= "16.1mV";

Scope1.Channel1.Attenuation.value= 10;
Scope1.Channel2.Attenuation.value= 10;
Scope1.Channel3.Attenuation.value= 10;
Scope1.Channel4.Attenuation.value= 10;

//range setup
Scope1.Channel1.Range.text= "2V";
Scope1.Channel2.Range.text= "2V";
Scope1.Channel3.Range.text= "100m";
Scope1.Channel4.Range.text= "100m";

//set labels for math operations
Scope1.Channel1.label= "Vin";
Scope1.Channel2.label= "Vout";
Scope1.Channel3.label= "Shuin";
Scope1.Channel4.label= "Shuout";


Scope1.Math1.Mode.text= "custom";
Scope1.Math1.Function.text= "Vin*(Shuin/1)";
Scope1.Math2.Mode.text= "custom";
Scope1.Math2.Function.text= "Vout*(Shuout/1)";

Scope.run();
Scope.wait();// wait for the capture to be done

Scope.stop();

//Scope1.Export("C:\Users\Pepyt_user\Documents\albertomeasure\output\ac.csv");

var file= ("C:\Users\Pepyt_user\Documents\albertomeasure\output\ac.csv");

Scope1.Export(file, szView = "", fComments = true, fHeader = true, fLabel = true, fHeaderAsComment = false, szNotes = "")


Can you please explain me how to export automatically the .csv file as I would do into the GUI of waveforms but using script?

Link to comment
Share on other sites

  • 0

Hello Attila I'm sorry to contact you this way but I can't send you any messages directly. I am looking for someone who can help me to use the trigger of an adp340. I wrote in project vault but my message disappeared. Maybe it was not in the right box. Is it possible to contact you ?

Link to comment
Share on other sites

  • 0

Hi @attila!

I'm trying to give the export acquired from the previous code the name of the date and hour. I tried something like:

 

import java.text.SimpleDateFormat;  
import java.util.Date;  
clear()
if(!('Scope' in this)) throw "Please open Scope";

/////important/////
////open channels and math channels from the gui


Scope1.Trigger.Type.text= "edge";//
Scope1.Trigger.Condition.text= "rising";
Scope1.Trigger.Level.value=0.5;// it could be used also auto for this purpose
Scope1.Trigger.Hysteresis.text = "auto";//value of hysteresis



//time setup
Scope1.Time.Position.value = 0;
Scope1.Time.Rate.text = "10Hz";// 1 sample every 100ms
Scope1.Time.Samples.value= 128;//number of samples
Scope1.Time.Mode.text= "Record";//record setting of the scope so that the values can be saved
//put oversampling off

//sample mode
Scope1.Channel1.SampleMode.text= "average";//write down the other options
Scope1.Channel2.SampleMode.text= "average";
Scope1.Channel3.SampleMode.text= "average";
Scope1.Channel4.SampleMode.text= "average";



Scope1.Channel1.Zero.text= "0V";//"calibration" probes, mandatory to set in order to obtaing better measurements
Scope1.Channel2.Zero.text= "0V";
Scope1.Channel3.Zero.text= "0mV";
Scope1.Channel4.Zero.text= "1mV";

Scope1.Channel1.Attenuation.value= 1;//probe setting attenuation
Scope1.Channel2.Attenuation.value= 1;
Scope1.Channel3.Attenuation.value= 1;
Scope1.Channel4.Attenuation.value= 1;

Scope1.Channel1.Range.text= "5V";//range setup v/div
Scope1.Channel2.Range.text= "5V";
Scope1.Channel3.Range.text= "100m";
Scope1.Channel4.Range.text= "100m";

Scope1.Channel1.label= "Vin";//set labels for math operations
Scope1.Channel2.label= "Vout";
Scope1.Channel3.label= "Shuin";
Scope1.Channel4.label= "Shuout";


Scope1.Math1.Mode.text= "custom";
Scope1.Math1.Function.text= "Vin*(Shuin/1)";
Scope1.Math2.Mode.text= "custom";
Scope1.Math2.Function.text= "Vout*(Shuout/1)";

Scope.run();
Scope.wait();// wait for the capture to be done

Scope.stop();

SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm");  
Date date = new Date();  
String newDate=formatter.format(date).toString();

Scope.Export("~/Documents/albertomeasure/output/"+newDate+".csv");// try to find a way to input the date as the name 

but I cannot import libraries, I guess due to the fact that they should be imported outside the class.

Is there a way to do this? Can you please help me?

 

Link to comment
Share on other sites

  • 0

Hi @Albertu95

You could use the following:

image.png

print(Scope.Time.taken.toISOString());
print(Scope.Time.taken.toISOString().replace('-','').replace('-','').replace(':','').replace(':','').replace('T','').substr(0,14));
var dt = Scope.Time.taken;
print(dt.getUTCFullYear()+""+ (dt.getUTCMonth()<9?"0":"")+(dt.getUTCMonth()+1)+ (dt.getUTCDate()<10?"0":"")+dt.getUTCDate()+ (dt.getUTCHours()<10?"0":"")+dt.getUTCHours()+ (dt.getUTCMinutes()<10?"0":"")+ dt.getUTCMinutes()+(dt.getUTCSeconds()<10?"0":"")+dt.getUTCSeconds()); 

// or yyyy-MM-ddTHH.mm.ss.fffZ
Scope.Export("~/Documents/albertomeasure/output/"+(Scope.Time.taken.toISOString().replace(':','.').replace(':','.'))+".csv");

 

Link to comment
Share on other sites

  • 0

Hi @attila! Thank you for your time as always.

I was trying the code that you wrote but for me it seems not working:

Untitled.thumb.jpg.375cb40f18e82a50686adcf649b691cb.jpgUntitled2.thumb.jpg.8b256b8fef8a50d9a3b21d514fe417fb.jpg

Both in my code and in your example waveforms returns the same error, what could be the problem?

I even tried to put the code between scope.run() and scope.stop() but nothing changed.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...