211 lines
5.5 KiB
C
211 lines
5.5 KiB
C
|
|
#include "main.h"
|
|||
|
|
|
|||
|
|
//==============================================================================
|
|||
|
|
//
|
|||
|
|
// Title: UCIDEMO
|
|||
|
|
// Purpose: A short description of the application.
|
|||
|
|
//
|
|||
|
|
// Created on: 2016/10/27 at 14:20:19 by admin.
|
|||
|
|
// Copyright: . All Rights Reserved.
|
|||
|
|
//
|
|||
|
|
//==============================================================================
|
|||
|
|
|
|||
|
|
//==============================================================================
|
|||
|
|
// Include files
|
|||
|
|
|
|||
|
|
#include <ansi_c.h>
|
|||
|
|
#include <cvirte.h>
|
|||
|
|
#include <userint.h>
|
|||
|
|
#include "UCIDEMO.h"
|
|||
|
|
#include "toolbox.h"
|
|||
|
|
#include "include\uci.h"
|
|||
|
|
#include "include\dso_base.h"
|
|||
|
|
#include "include\unit.h"
|
|||
|
|
//==============================================================================
|
|||
|
|
// Constants
|
|||
|
|
|
|||
|
|
//==============================================================================
|
|||
|
|
// Types
|
|||
|
|
|
|||
|
|
//==============================================================================
|
|||
|
|
// Static global variables
|
|||
|
|
|
|||
|
|
static int panelHandle;
|
|||
|
|
|
|||
|
|
static u_session g_session = INVALID_SESSION;
|
|||
|
|
|
|||
|
|
typedef struct _UCIParams{
|
|||
|
|
u_session Session;
|
|||
|
|
MeaValue Params[50];
|
|||
|
|
}UCIParams;
|
|||
|
|
|
|||
|
|
static UCIParams g_UCIParams;
|
|||
|
|
//==============================================================================
|
|||
|
|
// Static functions
|
|||
|
|
|
|||
|
|
//==============================================================================
|
|||
|
|
// Global variables
|
|||
|
|
|
|||
|
|
//==============================================================================
|
|||
|
|
// Global functions
|
|||
|
|
int HandleResult(char* tips, u_status r){
|
|||
|
|
if(UCIERR(r))
|
|||
|
|
printf("%s : r = %d, %s\n", tips == NULL ? "--" : tips, r, uci_GetLastError());
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int OpenDevice(){
|
|||
|
|
//@brief : <20><><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//@param _addr : <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD> <20><>'\0'<27><>β
|
|||
|
|
//@param _timeOut : <20><><EFBFBD>ӳ<EFBFBD>ʱʱ<CAB1><CAB1> ms
|
|||
|
|
//@return : < 0 <20><><EFBFBD><EFBFBD><EFBFBD>룻 >=0 <20>ỰID
|
|||
|
|
//@remarks : <20><><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>uci_Open<65>ļ汾<F2BBAFB0><E6B1BE>
|
|||
|
|
// u_status _UCIAPI uci_OpenX(u_cstring _addr, u_uint32 _timeOut);
|
|||
|
|
|
|||
|
|
u_status r = HandleResult(
|
|||
|
|
"Open devcie",
|
|||
|
|
uci_OpenX("[C:DSO][D:UPO2000CS][T:USB][PID:0x1234][VID:0x5345][EI:0x81][EO:0x3][CFG:3]", 2000)
|
|||
|
|
);
|
|||
|
|
if(UCISUCCESS(r))
|
|||
|
|
g_UCIParams.Session = (u_session)r;
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void InitMeasure(){
|
|||
|
|
u_status r = 0;
|
|||
|
|
|
|||
|
|
if(g_UCIParams.Session == INVALID_SESSION) {
|
|||
|
|
printf("please open device first!\n");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//@brief : <20><>ʽ<EFBFBD><CABD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//@param u_session _sesn : <20>ỰID
|
|||
|
|
//@param u_uint32 _timeOut : д<><D0B4>ʱ(<28><>λ<EFBFBD><CEBB>ms)
|
|||
|
|
//@param const u_tchar * format : <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'\0'<27><>β. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>
|
|||
|
|
//@param ... :
|
|||
|
|
//@return u_status : <20>鿴<EFBFBD><E9BFB4><EFBFBD>ļ<EFBFBD><C4BC>еġ<D0B5><C4A1><EFBFBD><EFBFBD>ڽӿڷ<D3BF><DAB7>ص<EFBFBD>״ֵ̬<CCAC><D6B5>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>
|
|||
|
|
//@remarks :
|
|||
|
|
//u_status _UCIAPI uci_FormatWrite(u_session _sesn, u_uint32 _timeOut, const u_tchar *format, ...);
|
|||
|
|
|
|||
|
|
r = HandleResult(
|
|||
|
|
"Enabel Measure",
|
|||
|
|
uci_FormatWrite(g_UCIParams.Session, 1000, "mea@ALL:1;")
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
r = HandleResult(
|
|||
|
|
"Switch to measure CH1",
|
|||
|
|
uci_FormatWrite(g_UCIParams.Session, 1000, "mea@src:0;")
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// HIFN The main entry-point function.
|
|||
|
|
int main (int argc, char *argv[])
|
|||
|
|
{
|
|||
|
|
int error = 0;
|
|||
|
|
|
|||
|
|
|
|||
|
|
/* initialize and load resources */
|
|||
|
|
nullChk (InitCVIRTE (0, argv, 0));
|
|||
|
|
errChk (panelHandle = LoadPanel (0, "UCIDEMO.uir", PANEL));
|
|||
|
|
|
|||
|
|
g_UCIParams.Session = INVALID_SESSION;
|
|||
|
|
memset(g_UCIParams.Params, 0, sizeof(g_UCIParams.Params));
|
|||
|
|
|
|||
|
|
if(OpenDevice() >= 0)
|
|||
|
|
InitMeasure();
|
|||
|
|
|
|||
|
|
/* display the panel and run the user interface */
|
|||
|
|
errChk (DisplayPanel (panelHandle));
|
|||
|
|
errChk (RunUserInterface ());
|
|||
|
|
Error:
|
|||
|
|
/* clean up */
|
|||
|
|
DiscardPanel (panelHandle);
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//==============================================================================
|
|||
|
|
// UI callback function prototypes
|
|||
|
|
|
|||
|
|
/// HIFN Exit when the user dismisses the panel.
|
|||
|
|
int CVICALLBACK panelCB (int panel, int event, void *callbackData,
|
|||
|
|
int eventData1, int eventData2)
|
|||
|
|
{
|
|||
|
|
if (event == EVENT_CLOSE)
|
|||
|
|
QuitUserInterface (0);
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int ReadMeaParams(void){
|
|||
|
|
//@brief : <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
//@param _session : <20>ỰID
|
|||
|
|
//@param _msg : <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'\0'<27><>β. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>
|
|||
|
|
//@param _timeout : <20><>ȡ<EFBFBD><C8A1>ʱ<EFBFBD><CAB1>
|
|||
|
|
//@param _data : <20><><EFBFBD>ն<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĻ<DDB5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>
|
|||
|
|
//@param _dataLen : _dataָ<61><D6B8><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>Bytes<65><73>
|
|||
|
|
//@return : <09>鿴<EFBFBD><E9BFB4><EFBFBD>ļ<EFBFBD><C4BC>еġ<D0B5><C4A1><EFBFBD><EFBFBD>ڽӿڷ<D3BF><DAB7>ص<EFBFBD>״ֵ̬<CCAC><D6B5>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>
|
|||
|
|
//@remarks : <20><><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>uci_Read<61>ļ汾
|
|||
|
|
// u_status _UCIAPI uci_ReadX(u_session _session, u_cstring _msg,
|
|||
|
|
// u_uint32 _timeout, u_byte* _data, u_size _dataLen);
|
|||
|
|
|
|||
|
|
return HandleResult(
|
|||
|
|
"Read measure result " ,
|
|||
|
|
uci_ReadX(g_UCIParams.Session, "mea:all?;", 1000, (u_byte*)g_UCIParams.Params, sizeof(g_UCIParams.Params))
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
MeaValue* GetParam(EMeaParam id){
|
|||
|
|
return &g_UCIParams.Params[id];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ShowMeaParam(char* name, EMeaParam id){
|
|||
|
|
MeaValue* p = NULL;
|
|||
|
|
if(name == NULL)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
p = GetParam(id);
|
|||
|
|
|
|||
|
|
if(p->IsExist == 0)
|
|||
|
|
printf("%s = Not exist\n", name);
|
|||
|
|
else{
|
|||
|
|
if(p->IsValid == 1){
|
|||
|
|
printf("%s = %f\n",name, p->Value);
|
|||
|
|
}else{
|
|||
|
|
printf("%s = --\n", name);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int CVICALLBACK _Read (int panel, int control, int event,
|
|||
|
|
void *callbackData, int eventData1, int eventData2)
|
|||
|
|
{
|
|||
|
|
switch (event)
|
|||
|
|
{
|
|||
|
|
case EVENT_COMMIT:
|
|||
|
|
if(ReadMeaParams() >=0 ){
|
|||
|
|
ShowMeaParam("FREQ", MP_FREQ);
|
|||
|
|
ShowMeaParam("MAX", MP_MAX);
|
|||
|
|
ShowMeaParam("AMP", MP_AMP);
|
|||
|
|
}
|
|||
|
|
// _numFreq = g_UCIParams.Params[MP_FREQ].Value;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int CVICALLBACK _timer (int panel, int control, int event,
|
|||
|
|
void *callbackData, int eventData1, int eventData2)
|
|||
|
|
{
|
|||
|
|
switch (event)
|
|||
|
|
{
|
|||
|
|
case EVENT_TIMER_TICK:
|
|||
|
|
if(ReadMeaParams() >=0 ){
|
|||
|
|
ShowMeaParam("FREQ", MP_FREQ);
|
|||
|
|
ShowMeaParam("MAX", MP_MAX);
|
|||
|
|
ShowMeaParam("AMP", MP_AMP);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
return 0;
|
|||
|
|
}
|