⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vgraph.c

📁 rt采集卡dos下dm6430驱动源代码
💻 C
字号:
/***************************************************************************

	FILE NAME: vgraph.C

	FILE DESCRIPTION:

   This file contains graphical functions used by some example programs.

	PROJECT NAME: VGAGRAPH (Part of DM6430 DOS Driver)

	DRIVER VERSION: 1.1

	COMPILER: Borland C++ 3.1

	TARGET: Real-Mode DOS

	Copyright 2003 RTD Embedded Technologies

***************************************************************************/

#include <alloc.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <stdio.h>
#include <io.h>

unsigned BufferNumber = 1;
unsigned long Rate;
float Range;
float Slope;
unsigned NumberOfPoints;

FILE* DataFile;
int far *DataBuffer;

void ReadFile(char* FileName){


	if((DataFile = fopen(FileName, "rb")) ==NULL) {
		cprintf("File %s Not Found.");
		getch();
		exit(1);
	}

	fread(&Rate, sizeof(Rate), 1, DataFile);
	fread(&Range, sizeof(Range), 1, DataFile);
	fread(&Slope, sizeof(Slope), 1, DataFile);
	fread(&NumberOfPoints, sizeof(NumberOfPoints), 1, DataFile);

	DataBuffer = (int far *)farmalloc(NumberOfPoints*2);
	fread(DataBuffer, sizeof(int), NumberOfPoints, DataFile);

	Range = Range / 2;
}

void DisplayLabels(void) {

	char msg[80];
	float  Time;
	float StartTime,StopTime;
	// Display labels
	setcolor(1);                        // Draw in Blue
	Time = (float)NumberOfPoints / (float)Rate;
	sprintf(msg,"VIEWDAT");
	outtextxy(300,20,msg);
	sprintf(msg,"PgUp +1 volt");
	outtextxy(500,10,msg);
	sprintf(msg,"Esc to Exit");
	outtextxy(10,10,msg);
	sprintf(msg,"PgDn -1 volt");
	outtextxy(500,20,msg);
	sprintf(msg,"+%4.2f",Range);
	outtextxy(10,25,msg);
	sprintf(msg,"0");
	outtextxy(10,235,msg);
	sprintf(msg,"-%4.2f",Range);
	outtextxy(10,445,msg);
	StopTime = Time * BufferNumber;
	StartTime = StopTime - Time;
	sprintf(msg,"%8.4f",StartTime);
	outtextxy(20,455,msg);
	sprintf(msg,"Sec");
	outtextxy(310,455,msg);
	sprintf(msg,"%8.4f",StopTime);
	outtextxy(540,455,msg);
	sprintf(msg,"%d",BufferNumber);
	outtextxy(150,10,msg);

}

void MakeGrid(void){
	int i;

	setbkcolor(15); 							// Backgound Color to white.
	setcolor(8);                        // Grid in black
	for (i = 40 ;i<= 440;i= i+40){
		moveto(40, i);
		lineto(600, i);
	}
	for (i = 40;i <=640;i=i+40){
		moveto(i,40);
		lineto(i,440);
	}
}

int vgraph(char* FileName)
{
	int i,j,error;
	unsigned SkipY,SkipX;
	float Scale;
	char Key;
	/* request autodetection */
	int gdriver = DETECT, gmode, errorcode;

	ReadFile(FileName);


	/* initialize graphics and local variables */
	initgraph(&gdriver, &gmode, "");

	/* read result of initialization */
	errorcode = graphresult();
	if (errorcode != grOk) {
		printf("Graphics error: %s\n", grapherrormsg(errorcode));
		printf("Press any key to halt:");
		getch();
		exit(1);
	}
Redraw:

	setviewport(1,1,639,479,1);
	clearviewport();
	MakeGrid();
	if (NumberOfPoints < 560){
		SkipX = (int)(560/NumberOfPoints + 1)  ;// Scale Data X direction
		SkipY = 1;                           // Scale Data Y direction
	}
	else{
		SkipY = (int)(NumberOfPoints / 560);// Scale Data Y direction
		SkipX = 1;                        // Scale Data X direction
	}
	Scale = (Range/Slope)/200;          // Scale Data Y Direction

	DisplayLabels();

	setviewport(40,40,600,440,1);
	setcolor(2);								// Draw Data
	j = 0;
	cprintf(" %d %d  ",-DataBuffer[0],Scale);
	moveto(0,(-DataBuffer[0]/Scale) + 200);
	for (i = 0; i < 560; i = i + SkipX){
		j = j + SkipY;
		lineto(i,(-DataBuffer[j]/Scale)  +  200);
	}
	// Change The Range

	Key = getch();
	switch(Key){
		case 0:
			Key = getch();
			switch(Key){
				case 72:
					error = fread(DataBuffer, sizeof(int), NumberOfPoints, DataFile);
				   if (error != 0){
						BufferNumber++;
						goto Redraw;
					}
					break;
				case 73:     					// Page Up
					Range++;
					if(Range==41) Range=40;
					goto Redraw;
				case 81:Range--;  			// Page Down
					if(Range==0) Range=1;
					goto Redraw;
				default: break;
			}
		break;
	}


	/* clean up */
	fclose(DataFile);
	closegraph();
	return 0;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -