Notifications
Clear all

Sample code for reading mesurement data


mic4m
(@mic4m)
New Member
Joined: 12 years ago
Posts: 1
Topic starter  

Dear sir,
I downloaded Spectran Programmers Guide(last version 1.4.2). I have read SPECTRAN API Documentation pdf file, but i have not found any sample code for reading mesurement data via usb.
Could you provide a sample code for it?
Regards.


Quote
stb
 stb
(@stb)
Trusted Member
Joined: 12 years ago
Posts: 84
 

Hello mic4m,

I can't provide a code example right now, but in few words the procedure can be described as follows:

Measurement data can be read synchronously and asynchronously.

The synchronous mode:
Write 1 to the USBMEAS variable
Call readcmd(NULL, SV_USBMEAS, 0)
Call readdata(target, 1)
Repeat the last two steps until all data is arrived, then write 0 to the USBMEAS variable
The readcmd doesn’t need a buffer because all measurement data are read to the internal data buffer and transferred from there with the readdata call.

The asynchronous mode:
When data arrives, the reader thread sends a message to a window. The target window and the message id can be specified with the startreader. The third parameter of startreader is poll interall, the thread will sleep for that time before it queries for new data.
At least after 100 ms the configured message is sent to the configured target window via a timer. The Message handler must call readdata(target, maxcount), which will return the number of values copied to the array. The timer is used to avoid one new data” trigger for each value. The stopreader stops the thread, the pausereader avoids callbacks.

PGP
Homepage


ReplyQuote
spdev_wb
(@spdev_wb)
Active Member
Joined: 12 years ago
Posts: 6
 

Dear Sir,

I have read SPECTRAN API Documentation pdf file, I followed also the steps as you mentioned :

The synchronous mode:
Write 1 to the USBMEAS variable
Call readcmd(NULL, SV_USBMEAS, 0)
Call readdata(target, 1)
Repeat the last two steps until all data is arrived, then write 0 to the USBMEAS variable
The readcmd doesn’t need a buffer because all measurement data is read to the internal data buffer and transferred from there with the readdata call.
But every time I obtains the same result despite that every time I modify SPECTRAN parameters.
Results :

Time = 29
Freq = 2
Minval = 0.00
Maxval = 0.00

So under my code:


ReplyQuote
stb
 stb
(@stb)
Trusted Member
Joined: 12 years ago
Posts: 84
 

Hi spdev_wb,

the Programmers Guide Documentation is wrong about readcmd()... try this:

SPECTRAN NF

		
Smeasurementvalue valbuff;
con-> writeenvironment(SV_USBMEAS, 1);
{
   con->readcmd(NULL,  UST_PHYFREQDAT, 0);
   con->readdata(&valbuff, 1);
   printf("time = %in", valbuff.time); 
   printf("unit = %in", valbuff.unit); 
   printf("freq = %in", valbuff.freq);
   printf("minval = %fn", valbuff.minval);
   printf("maxval = %fn", valbuff.maxval);
}
con-> writeenvironment(SV_USBMEAS, 0);

SPECTRAN HF

		
SmeasurementvalueHF valbuff;
con-> writeenvironment(SV_USBMEAS, 1);
{
   con->readcmd(NULL,  UST_AMPFREQDAT, 0);
   con->readdata(&valbuff, 1);
   printf("time = %in", valbuff.time); 
   printf("freq = %in", valbuff.freq);
   printf("minval = %fn", valbuff.minval);
   printf("maxval = %fn", valbuff.maxval);
}
con-> writeenvironment(SV_USBMEAS, 0);

*Scoping of course only for the imaginary outer loop :-)
**The change to the valbuff declaration is not mandatory

PGP
Homepage


ReplyQuote
spdev_wb
(@spdev_wb)
Active Member
Joined: 12 years ago
Posts: 6
 

Dear sir,

Thank you for the response. I tried with the new code the result is:
time = 34078804
freq = 1568524
minval = 0.000000
maxval = 0.000000

- That corresponds to what these fourths values, which are the unities of every value.
- How can i recover the Value of "spectre d'amplitude en dB" (in Tesla in case of magnetic).

Best Regards.


ReplyQuote
stb
 stb
(@stb)
Trusted Member
Joined: 12 years ago
Posts: 84
 

Oh you are using the SPECTRAN NF I suppose. In that case, you have to read UST_PHYFREQDAT into the Smeasurementvalue...

PGP
Homepage


ReplyQuote
spdev_wb
(@spdev_wb)
Active Member
Joined: 12 years ago
Posts: 6
 

Yes I am using the SPECTRAN NF 5030, but the variable UST_PHYFREQDAT does not exist in SPECTRAN API Documentation pdf file, which is the value of UST_PHYFREQDAT ?

Also 'unit' : is not a member of 'Smeasurementvalue'
it's declared in usbconnector.h
struct Smeasurementvalue
{
unsigned int time; /* current kHz Timer value */
unsigned int freq; /* frequency / 10 */
float minval; /* minimum value of measurement point */
float maxval; /* maximum value of measurement point */
};

Best Regards.


ReplyQuote
stb
 stb
(@stb)
Trusted Member
Joined: 12 years ago
Posts: 84
 

I'm sorry, seems to be an other screw up regarding the Programmers Guide - I'll try to update its source to a more recent version soon... As for now, those are the missing defines, maybe you are lucky :-( ... The archive attached contains a different, more recent usbconnect.h/cpp - may need some fixup in order to compile....

#define UST_AMPFREQDAT	0x22		/* USB amplitude frequency data */
#define UST_PHYFREQDAT	0x23		/* USB physical meas. (freq.) data */

struct SmeasurementvalueHF {
	unsigned int time;		/* current kHz Timer value */
	unsigned int freq;		/* frequency / 10 */
	float minval;			/* minimum value of measurement point */
	float maxval;			/* maximum value of measurement point */
};

struct Smeasurementvalue {
	unsigned int time;		/* current kHz Timer value */
	unsigned short unit;
	unsigned int freq;		/* frequency / 10 (HF) or frequency / 0.10 (NF) */
	float minval;			/* minimum value of measurement point */
	float maxval;			/* maximum value of measurement point */
};

PGP
Homepage


ReplyQuote
spdev_wb
(@spdev_wb)
Active Member
Joined: 12 years ago
Posts: 6
 

I updated the api that you sent me. I launched programs so under:

Smeasurementvalue valbuff;
con-> writeenvironment(SV_USBMEAS, 1);
{
con->readcmd(NULL, UST_PHYFREQDAT, 0);
con->readdata(&valbuff, 1);
printf("time = %in", valbuff.time);
printf("unit = %in", valbuff.unit);
printf("freq = %in", valbuff.freq);
printf("minval = %fn", valbuff.minval);
printf("maxval = %fn", valbuff.maxval);
}
con-> writeenvironment(SV_USBMEAS, 0);

The result is different of the one of Aoronia Lcs Analyzer.

My program gives:

time = 1568524
unites = 61200
freq = -222297833
minval = 0,000000
maxval = 0,000000

Lcs Analyzer gives: 1.158µTesla

I want to obtain even result that Lcs Analyzer.

Best Regards.


ReplyQuote
stb
 stb
(@stb)
Trusted Member
Joined: 12 years ago
Posts: 84
 

I took half an hour and tried to obtain something meaningful from a NF SPECTRAN using the usbconnector ... I'm just forwarding you my current status as I don't have much time to spend on that matter. But, maybe you will be lucky.... and take a good look at structure alignment - right now, #pragma are gcc/g++ compatible - yet no time to checkout VC ...

PGP
Homepage


ReplyQuote
spdev_wb
(@spdev_wb)
Active Member
Joined: 12 years ago
Posts: 6
 

Dear Sir,

I updated my code and that walks, I well obtained the same frequency that the LCS Analyzer.
I put:
Start freq = 1000
stop freq = 1000
span freq = 0
center freq = 1000

The result is the same for my code and LCS Analyzer (freq = 1000).

Now how to recover M-Field measure (= 1.158µTesla for LCS Analyzer).

Best Regards.


ReplyQuote
stb
 stb
(@stb)
Trusted Member
Joined: 12 years ago
Posts: 84
 

Hello again,

For the Magnetic Field sensors, the SPECTRAN NF sends PHYFREQDAT in Tesla. If the E-Field sensor is active, Volt per Meter is sent. Finally for the Analog Input, Volt is sent. The Smeasurementvalue field "unit" contains the currently selected sensor index.

PGP
Homepage


ReplyQuote
spdev_wb
(@spdev_wb)
Active Member
Joined: 12 years ago
Posts: 6
 

Dear sir,

Thank you for response:

I have tested the code it is good for the frequency result (I obtains same result that LCS) on the other hand the result of unites seems not good I obtains at first unit = 32768 then she always gives 0 while the result on the screen of spectran and on the LSC is 515.9 nTesla.

I don't know why the result of unit always is or well 32768 or well 0.

Best Regards.


ReplyQuote
stb
 stb
(@stb)
Trusted Member
Joined: 12 years ago
Posts: 84
 

This seems to be some integer overflow / cast related issue - It should be OK if you interpret that particular value as the expected value ( 0 I guess )

PGP
Homepage


ReplyQuote
Share: