Demo entry 6624376

1

   

Submitted by 2 on Jun 15, 2017 at 11:23
Language: C. Code size: 1.7 kB.

//产生波形回调函数
int CVICALLBACK waveGenerate (int panel, int control, int event,
							  void *callbackData, int eventData1, int eventData2)
{   //波形类型  周期  点数
	int wave, cycle, points;//  n = 500
	//初始相位  幅值  500个点的幅值
	double phase, amp, data[10000];
	
	switch (event)
	{
		case EVENT_COMMIT:
			GetCtrlVal(panelHandle,PANEL_AMPLITUDE,&amp);
			GetCtrlVal(panelHandle,PANEL_CYCLE,&cycle);
			GetCtrlVal(panelHandle,PANEL_POINTS,&points);
			GetCtrlVal(panelHandle,PANEL_PHASE,&phase);
			if (amp < -5 || amp >5)            //幅值范围-5~5
			{
				MessagePopup("Error Msssage","The voltage must be from -5V to +5V");
			}
			if (points < 0 || points > 10000)  //点数范围0~10000
			{
				MessagePopup("Error Msssage","The points must not below 0 or up 10000");
			}
			if (cycle < 0 || cycle > 100)	  //周期数范围0~100
			{
				MessagePopup("Error Msssage","The cycle must not below 0 or up 100");
			}
			GetCtrlVal(panelHandle,PANEL_WAVE_RING,&wave);
			switch (wave)
			{
				case 1://方波
					SquareWave(points,amp,(double)cycle/points,&phase,50.0,data);
					break;
				case 2://锯齿波
					SawtoothWave(points,amp,(double)cycle/points,&phase,data);
					break;
				case 3://三角波
					TriangleWave(points,amp,(double)cycle/points,&phase,data);
					break;
				case 4://正弦波
					SineWave(points,amp,(double)cycle/points,&phase,data);
					break;
			}
			
			DeleteGraphPlot(panelHandle,PANEL_WAVE_GRAPH,-1,VAL_IMMEDIATE_DRAW);
			SetAxisScalingMode(panelHandle,PANEL_WAVE_GRAPH,VAL_XAXIS,VAL_MANUAL,0,points);
			//作图
			PlotY(panelHandle,PANEL_WAVE_GRAPH,data,points,VAL_DOUBLE,VAL_THIN_LINE,
				  VAL_EMPTY_SQUARE,VAL_SOLID,1,VAL_YELLOW);
			break;
	}
	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).