HP美国惠普公司的HP4278电容测量仪后面有串口接口和GPIB接口等,都可以与PC机连接采集到实时测量到的电容数据,本程序自动收到数据后,进行正态分布分析,可以及时地给生产线抽检人员快速提供质检报告。
源程序如下:
- /* ======================================================================= */
- /* SQCC.C : */
- /* */
- /* Copyright (c) 1994,95 Yingte Instruments. All rights reserved. */
- /* 10-3-1993 by BXY */
- /* ======================================================================= */
- #include <ctype.h>
- #include <conio.h>
- #include <dos.h>
- #include <io.h>
- #include <memory.h>
- #include <malloc.h>
- #include <math.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <time.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #define ANSI /* Delete for UNIX version. */
- #include <graph.h>
- #include <process.h>
- #include <errno.h>
- #include "sgwindow.h"
- #include <mouse.h>
- #include <guass.h>
- #include "yp.h"
- #include <gpibc.h>
- int compcode; /* Completion code for reporting problems. This is set */
- /* by the routines below & tested in calling program. */
- #define MAXSTR 100
- char cnumbuf[MAXSTR] = { MAXSTR + 2, 0 };
- char tmpbuf[MAXSTR];
- #define MaxWidth 5
- #define MaxLength 22
- void YpGl(void);
- void ChpGl(void);
- void STATISRESULT(char *Fname);
- unsigned long LocateFrame(POPUPWINDOW *wnd,char *Fname);
- int SelectYpFile(char *Fname);
- void DataYpProcess(char *Fname);
- long MaxFrame=110;
- void DisplayTM(int x,int y);
- int autoaq(char *Fname);
- int y_n(char *Fname);
- main()
- {
- PRESSBUTTON PressButton[3];
- unsigned int exit_code;
- int i;
- int CurrPressButton,OldPressButton,Pressing;
- static long old_color_table[] = {0x000000l,0x2a0000l,0x002a00l,0x2a2a00l,
- 0x00002al,0x2a002al,0x00152al,0x2a2a2al,
- 0x151515l,0x3f1515l,0x153f15l,0x3f3f15l,
- 0x15153fl,0x3f153fl,0x153f3fl,0x3f3f3fl};
- if(!InitGwindow())
- {
- printf("ERROR : System initialize error !");
- exit(1);
- }
- mouse_off(1);
- _setcolor(VGA_BLACK);
- line(0,35,639,35);
- DisplayTM(10,3);
- ccprintf(250,10,VGA_BLUE,"生 产 过 程 质 量 检 验");
- for( i = 0;i < 3; i ++)
- {
- PressButton[i].left = 210;
- PressButton[i].top = 120+i*80;
- PressButton[i].width = 200;
- PressButton[i].height = 40;
- }
- PressButton[0].label = "银 片 质 量 检 验";
- PressButton[1].label = "成品生产过程质量检验";
- PressButton[2].label = "退 出";
- for( i = 0;i < 3;i ++)
- DisplayPressButton(&PressButton[i],0);
- mouse_on(1);
- exit_code = 0;
- button_press(0);
- button_release(0);
- do
- {
- OldPressButton = 3;
- Pressing = 0;
- while(button_state() & 0x01) /* left button is being pressed */
- {
- /* Pressing pressbutton ? */
- CurrPressButton = 3;
- for(i = 0; i < 3; i ++)
- {
- if(mouse_in_box(1,PressButton[i].left,
- PressButton[i].top,
- PressButton[i].left+PressButton[i].width-1,
- PressButton[i].top+PressButton[i].height-1))
- { /* Press a press button */
- CurrPressButton = i;
- break;
- }
- }
- if((CurrPressButton != 3)
- &&(!Pressing)
- &&(OldPressButton != CurrPressButton) )
- {
- /* Display Pressed button */
- DisplayPressButton(&PressButton[CurrPressButton],1);
- OldPressButton = CurrPressButton;
- Pressing = 1;
- continue;
- }
- if( Pressing
- &&(OldPressButton != CurrPressButton) )
- {
- /* Recover old press button */
- DisplayPressButton(&PressButton[OldPressButton],0);
- if(CurrPressButton != 3)
- {
- /* Display Pressed button ---- */
- DisplayPressButton(&PressButton[CurrPressButton],1);
- OldPressButton = CurrPressButton;
- Pressing = 1;
- continue;
- }
- else
- {
- Pressing = 0;
- OldPressButton = 3;
- continue;
- }
- } /* End Pressing && OldPressButton != CurrPressButton */
- if( Pressing && (OldPressButton == CurrPressButton))
- {
- continue;
- }
- } /* end left button is being pressed */
- /* Recover old press button */
- if(Pressing)
- {
- DisplayPressButton(&PressButton[OldPressButton],0);
- Pressing = 0;
- /* Press Pressbutton */
- if(CurrPressButton < 3)
- {
- switch(CurrPressButton)
- {
- case 0:
- YpGl();
- break;
- case 1:
- ChpGl();
- mouse_off(1);
- _setcolor(VGA_LIGHTGRAY);
- _rectangle(_GFILLINTERIOR,0,0,639,479);
- _setcolor(VGA_BLACK);
- line(0,35,639,35);
- DisplayTM(10,3);
- ccprintf(250,10,VGA_BLUE,"生 产 过 程 质 量 检 验");
- for( i = 0;i < 3;i ++)
- DisplayPressButton(&PressButton[i],0);
- mouse_on(1);
- break;
- case 2:
- exit_code = 1;
- break;
- default:
- break;
- }
- /* move_mouse(320,240); */
- } /* End of Press Pressbutton */
- continue;
- } /* End of Pressing */
- }while(exit_code == 0);
- _remapallpalette(old_color_table);
- _setvideomode(_TEXTC80); /* Return the system to text mode */
- _unregisterfonts();
- }
- void YpGl(void)
- {
- char buffer[_MAX_PATH];
- char drive[_MAX_DRIVE],dir[_MAX_DIR],file[_MAX_FNAME],ext[_MAX_EXT];
- struct find_t fileinfo;
- YpHead Yhead;
- FILE *data_pointer,*data1_pointer;
- long SampleNumb;
- _fstrcpy(buffer,"*.YP");
- if(!OpenFile(buffer,"选 择 银 片 抽 检 数 据 文 件","选 定(O)"))
- return;
- _splitpath(buffer,drive,dir,file,ext);
- ext[0] = '.';
- ext[1] = 'Y';
- ext[2] = 'P';
- ext[3] = 0;
- _makepath(buffer,drive,dir,file,ext);
- /*if(_dos_findfirst(buffer,_A_VOLID,&fileinfo) != 0) */
- if((data_pointer = fopen(buffer,"rb")) == NULL)
- {
- if((data1_pointer=fopen(buffer,"wb"))==NULL)
- {
- ErrorMessage(" 打不开数据文件 ");
- return;
- }
- Yhead.password = 0x4347;
- Yhead.label[0] = 0;
- strcpy(Yhead.time,"950619/8:30");
- Yhead.NNumb = 100000;
- Yhead.material[0] = 0;
- Yhead.standard = 1;
- Yhead.delta = 3;
- strcpy(Yhead.Unit,"pF");
- strcpy(Yhead.sob,"电容");
- Yhead.Temp = 0.0;
- Yhead.Requ = 0.0;
- SampleNumb = 0;
- fseek(data1_pointer,0l,SEEK_SET);
- fwrite(&Yhead,sizeof(YpHead),1,data1_pointer);
- fwrite(&SampleNumb,4,1,data1_pointer);
- fclose(data1_pointer);
- if(SelectYpFile(buffer)!=0)
- return;
- }
- else
- fclose(data_pointer);
- data_pointer = fopen(buffer,"rb");
- fseek(data_pointer,0l,SEEK_SET);
- fread(&Yhead,sizeof(YpHead),1,data_pointer);
- fclose(data_pointer);
- if(Yhead.password!=0x4347)
- {
- ErrorMessage(" 不是银片数据文件 ");
- return;
- }
- DataYpProcess(buffer);
- return;
- }
- int SelectYpFile(char *Fname)
- {
- char buffer[_MAX_PATH];
- char drive[_MAX_DRIVE],dir[_MAX_DIR],file[_MAX_FNAME],ext[_MAX_EXT];
- FILE *data_pointer,*data1_pointer;
- POPUPWINDOW *wnd;
- int Classid,id,Selected,CursorX,CursorY;
- long return_lpara;
- int i;
- long SampleNumb;
- char ch10[20],ch11[20],ch12[20];
- YpHead Yhead;
- unsigned long FrameX,FrameY;
- int reasonnumber,refusenumber;
- if( (data_pointer = fopen(Fname,"rb")) == NULL)
- {
- ErrorMessage(" 打不开银片数据文件 ");
- return(1);
- }
- /* Read default data file name */
- fseek(data_pointer,0l,SEEK_SET);
- fread(&Yhead,sizeof(YpHead),1,data_pointer);
- fread(&SampleNumb,4,1,data_pointer);
- fclose(data_pointer);
- if(SplitNumber(Yhead,&reasonnumber,&refusenumber)==0)
- {
- ErrorMessage("标准错误!");
- return(1);
- }
- sprintf(ch10,"%ld",Yhead.NNumb);
- sprintf(ch11,"%.3f",Yhead.Requ);
- sprintf(ch12,"%.2f",Yhead.Temp);
- mouse_off(1);
- _setviewport(0,0,639,479);
- /*
- wnd = EstablishPopupWindow(120,110,400,360,VGA_WHITE,1);
- */
- wnd = EstablishPopupWindow(120,60,400,360,VGA_WHITE,1);
- SetTitle(wnd,"银 片 抽 检 数 据 文 件");
- ccwprintf(wnd,16,6,VGA_BLACK,"应输入样品个数 : %d",reasonnumber);
- ccwprintf(wnd,16,24,VGA_BLACK,"已输入样品个数 : %d",SampleNumb);
- EstablishPressButton(wnd,250,16,120,38,"设置正确(O)",ID_OK,0xff18);
- EstablishPressButton(wnd,250,160,120,30,"取 消(C)",ID_CANCEL,0xff2e);
- EstablishPressButton(wnd,250,92,120,30,"选择文件(T)",2,0xff14);
- /*EstablishEntryField(wnd,16,41,116,22,"批 号(L):",STRING,Yhead.label,NULL,NULL,10,0xff26);*/
- EstablishEntryField(wnd,16,41,116,22,"首检日期 (L):",STRING,Yhead.time,NULL,NULL,10,0xff26);
- EstablishEntryField(wnd,16,66,116,22,"总 数 量(N):",LONG,ch10,NULL,NULL,11,0xff31);
- EstablishEntryField(wnd,16,91,116,22,"规 格(M):",STRING,Yhead.material,NULL,NULL,12,0xff32);
- EstablishEntryField(wnd,16,116,116,22,"单 位(U):",STRING,Yhead.Unit,NULL,NULL,13,0xff16);
- EstablishEntryField(wnd,16,141,116,22,"质量特性名(B):",STRING,Yhead.sob,NULL,NULL,14,NONEKEY);
- EstablishEntryField(wnd,16,166,116,22,"等效电阻值(R):",FLOAT,ch11,NULL,NULL,15,0xff13);
- EstablishEntryField(wnd,16,300,116,22,"温度 ℃ =:",FLOAT,ch12,NULL,NULL,16,0xff13);
- ccwprintf(wnd,16,186,VGA_BLACK,"检验标准AQL:");
- EstablishFrame(wnd,16,204,350,25,21,NONEKEY);
- for(i = 0;i < 4; i++)
- {
- DisplaySwitch(wnd->left+22+80*i,wnd->top+226,0);
- }
- DisplaySwitch(wnd->left+22+(Yhead.standard-1)*80,wnd->top+226,1);
- ccwprintf(wnd,40,206,VGA_BLACK,"0.65");
- ccwprintf(wnd,40+80,206,VGA_BLACK,"1.0");
- ccwprintf(wnd,40+160,206,VGA_BLACK,"1.5");
- ccwprintf(wnd,40+240,206,VGA_BLACK,"其它");
- ccwprintf(wnd,16,250,VGA_BLACK,"偏差调节系数:");
- EstablishFrame(wnd,16,268,350,25,22,NONEKEY);
- for(i = 0;i < 4; i++)
- {
- DisplaySwitch(wnd->left+22+80*i,wnd->top+290,0);
- }
- switch(Yhead.delta)
- {
- case 3:
- case 4:
- DisplaySwitch(wnd->left+22+(Yhead.delta-3)*80,wnd->top+290,1);
- break;
- case 6:
- case 8:
- DisplaySwitch(wnd->left+22+(Yhead.delta/2-3)*80,wnd->top+290,1);
- break;
- default:
- break;
- }
- ccwprintf(wnd,40,270,VGA_BLACK,"3");
- ccwprintf(wnd,40+80,270,VGA_BLACK,"4");
- ccwprintf(wnd,40+160,270,VGA_BLACK,"6");
- ccwprintf(wnd,40+240,270,VGA_BLACK,"8");
- mouse_on(1);
- move_mouse(320,240);
- Selected = 0; /* Not Selected */
- do
- {
- Dialog(wnd,
- &Selected,
- &CursorX,
- &CursorY,
- &Classid,
- &id,
- &return_lpara);
- /* Process dialoge message */
- switch(Classid)
- {
- case 1:
- switch(id)
- {
- case ID_CANCEL:
- DeletePopupWindow(wnd);
- return(1);
- case ID_OK:
- sscanf(ch10,"%ld",&Yhead.NNumb);
- sscanf(ch11,"%f",&Yhead.Requ);
- sscanf(ch12,"%f",&Yhead.Temp);
- if( (data_pointer = fopen(Fname,"r+b")) == NULL)
- {
- ErrorMessage(" 没打开银片数据文件 ");
- DeletePopupWindow(wnd);
- return(1);
- }
- /* Read default data file name */
- fseek(data_pointer,0l,SEEK_SET);
- fwrite(&Yhead,sizeof(YpHead),1,data_pointer);
- fclose(data_pointer);
- DeletePopupWindow(wnd);
- return(0);
- case 2:
- _fstrcpy(buffer,"*.YP");
- if(!OpenFile(buffer,"选 择 银 片 抽 检 数 据 文 件","选 定(O)"))
- break;
- if((data_pointer=fopen(buffer,"rb"))!=NULL)
- {
- fseek(data_pointer,0l,SEEK_SET);
- fread(&Yhead,2,1,data_pointer);
- fclose(data_pointer);
- if(Yhead.password!=0x4347)
- {
- ErrorMessage(" 不是银片数据文件 ");
- break;
- }
- }
- _splitpath(buffer,drive,dir,file,ext);
- ext[0] = '.';
- ext[1] = 'Y';
- ext[2] = 'P';
- ext[3] = 0;
- _makepath(buffer,drive,dir,file,ext);
- if((data_pointer=fopen(buffer,"rb"))==NULL)
- {
- if((data1_pointer=fopen(buffer,"wb"))==NULL)
- {
- ErrorMessage(" 未打开银片数据文件 ");
- return(1);
- }
- Yhead.password = 0x4347;
- Yhead.label[0] = 0;
- Yhead.NNumb = 10000;
- Yhead.material[0] = 0;
- Yhead.standard = 1;
- Yhead.delta = 3;
- strcpy(Yhead.Unit,"pF");
- strcpy(Yhead.sob,"电容");
- Yhead.Temp = 0.0;
- Yhead.Requ = 0.0;
- SampleNumb = 0;
- fseek(data1_pointer,0l,SEEK_SET);
- fwrite(&Yhead,sizeof(YpHead),1,data1_pointer);
- fwrite(&SampleNumb,4,1,data1_pointer);
- fclose(data1_pointer);
- }
- else
- {
- fseek(data_pointer,0l,SEEK_SET);
- fread(&Yhead,sizeof(YpHead),1,data_pointer);
- fread(&SampleNumb,4,1,data_pointer);
- fclose(data_pointer);
- }
- if(SplitNumber(Yhead,&reasonnumber,&refusenumber)==0)
- {
- ErrorMessage("标准错误!");
- return(1);
- }
- strcpy(Fname,buffer);
- ClearWindowRect(wnd,16,8,234,32);
- ccwprintf(wnd,16,6,VGA_BLACK,"应输入样品个数 : %d",reasonnumber);
- ccwprintf(wnd,16,24,VGA_BLACK,"已输入样品个数 : %d",SampleNumb);
- sprintf(ch10,"%ld",Yhead.NNumb);
- sprintf(ch11,"%.3f",Yhead.Requ);
- sprintf(ch12,"%.2f",Yhead.Temp);
- /* ModifyDataEntry(wnd,10,Yhead.label); */
- ModifyDataEntry(wnd,11,ch10);
- ModifyDataEntry(wnd,12,Yhead.material);
- ModifyDataEntry(wnd,13,Yhead.Unit);
- ModifyDataEntry(wnd,14,Yhead.sob);
- ModifyDataEntry(wnd,15,ch11);
- ModifyDataEntry(wnd,16,ch12);
- ModifyFrameSwitch(wnd,21,Yhead.standard);
- switch(Yhead.delta)
- {
- case 3:
- ModifyFrameSwitch(wnd,22,1);
- break;
- case 4:
- ModifyFrameSwitch(wnd,22,2);
- break;
- case 6:
- ModifyFrameSwitch(wnd,22,3);
- break;
- case 8:
- ModifyFrameSwitch(wnd,22,4);
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- break;
- case 6:
- wait_button_release();
- FrameX = return_lpara&0x0000ffff;
- FrameY = (return_lpara&0xffff0000)>>16;
- switch(id)
- {
- case 21:
- if((FrameX>=6)&&(FrameX<=22)&&(FrameY>=5)&&(FrameY<=21))
- {
- Yhead.standard = 1;
- DisplaySwitch(wnd->left+22,wnd->top+226,1);
- for(i = 1;i < 4; i++)
- {
- DisplaySwitch(wnd->left+22+80*i,wnd->top+226,0);
- }
- }
- if((FrameX>=86)&&(FrameX<=102)&&(FrameY>=5)&&(FrameY<=21))
- {
- Yhead.standard = 2;
- DisplaySwitch(wnd->left+22,wnd->top+226,0);
- DisplaySwitch(wnd->left+22+80,wnd->top+226,1);
- DisplaySwitch(wnd->left+22+160,wnd->top+226,0);
- DisplaySwitch(wnd->left+22+240,wnd->top+226,0);
- }
- if((FrameX>=166)&&(FrameX<=182)&&(FrameY>=5)&&(FrameY<=21))
- {
- Yhead.standard = 3;
- DisplaySwitch(wnd->left+22,wnd->top+226,0);
- DisplaySwitch(wnd->left+22+80,wnd->top+226,0);
- DisplaySwitch(wnd->left+22+160,wnd->top+226,1);
- DisplaySwitch(wnd->left+22+240,wnd->top+226,0);
- }
- if((FrameX>=246)&&(FrameX<=262)&&(FrameY>=5)&&(FrameY<=21))
- {
- Yhead.standard = 4;
- DisplaySwitch(wnd->left+22,wnd->top+226,0);
- DisplaySwitch(wnd->left+22+80,wnd->top+226,0);
- DisplaySwitch(wnd->left+22+160,wnd->top+226,0);
- DisplaySwitch(wnd->left+22+240,wnd->top+226,1);
- }
- break;
- case 22:
- if((FrameX>=6)&&(FrameX<=22)&&(FrameY>=5)&&(FrameY<=21))
- {
- Yhead.delta = 3;
- DisplaySwitch(wnd->left+22,wnd->top+290,1);
- for(i = 1;i < 4; i++)
- {
- DisplaySwitch(wnd->left+22+80*i,wnd->top+290,0);
- }
- }
- if((FrameX>=86)&&(FrameX<=102)&&(FrameY>=5)&&(FrameY<=21))
- {
- Yhead.delta = 4;
- DisplaySwitch(wnd->left+22,wnd->top+290,0);
- DisplaySwitch(wnd->left+22+80,wnd->top+290,1);
- DisplaySwitch(wnd->left+22+160,wnd->top+290,0);
- DisplaySwitch(wnd->left+22+240,wnd->top+290,0);
- }
- if((FrameX>=166)&&(FrameX<=182)&&(FrameY>=5)&&(FrameY<=21))
- {
- Yhead.delta = 6;
- DisplaySwitch(wnd->left+22,wnd->top+290,0);
- DisplaySwitch(wnd->left+22+80,wnd->top+290,0);
- DisplaySwitch(wnd->left+22+160,wnd->top+290,1);
- DisplaySwitch(wnd->left+22+240,wnd->top+290,0);
- }
- if((FrameX>=246)&&(FrameX<=262)&&(FrameY>=5)&&(FrameY<=21))
- {
- Yhead.delta = 8;
- DisplaySwitch(wnd->left+22,wnd->top+290,0);
- DisplaySwitch(wnd->left+22+80,wnd->top+290,0);
- DisplaySwitch(wnd->left+22+160,wnd->top+290,0);
- DisplaySwitch(wnd->left+22+240,wnd->top+290,1);
- }
- break;
- default:
- break;
- }
- break;
- case 2:
- switch(id)
- {
- case 11:
- sscanf(ch10,"%ld",&Yhead.NNumb);
- if(SplitNumber(Yhead,&reasonnumber,&refusenumber)==0)
- {
- ErrorMessage("标准错误!");
- return(1);
- }
- ClearWindowRect(wnd,16,8,234,16);
- ccwprintf(wnd,16,6,VGA_BLACK,"应输入样品个数 : %d",reasonnumber);
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- }while(1);
- }
- void DataYpProcess(char *Fname)
- {
- POPUPWINDOW *wnd;
- int Selected,CursorX,CursorY,Classid,id;
- FILE *fp;
- long SampleNumb;
- float value[110];
- char ch[110][15];
- long startnumb,i,lbuf,lpara;
- YpHead Yhead;
- int return_value;
- int row,col;
- int reasonnumber,refusenumber;
- mouse_off(1);
- wnd=EstablishPopupWindow(0,0,640,480,VGA_WHITE,1);
- _setviewport(0,0,639,479);
- _setcolor(VGA_LIGHTGRAY);
- _rectangle(_GFILLINTERIOR,1,20,149,473);
- _setcolor(VGA_BLACK);
- _rectangle(_GFILLINTERIOR,633,0,639,6);
- _rectangle(_GFILLINTERIOR,0,460,639,479);
- _moveto(150,20);
- _lineto(150,479);
- SetTitle(wnd,"半 成 品 、成 品 质 量 管 理");
- EstablishPressButton(wnd,20,50,80,32,"文 件(F)",1,0xff21);
- EstablishPressButton(wnd,20,120,80,32,"编 辑(E)",2,0xff12);
- EstablishPressButton(wnd,20,190,80,32,"采 集(A)",3,0xff1e);
- EstablishPressButton(wnd,20,260,80,32,"统 计(S)",4,0xff1f);
- EstablishPressButton(wnd,20,330,80,80,"退 出(X)",ID_CANCEL,0xff2d);
- if((fp = fopen(Fname,"rb"))==NULL)
- {
- ErrorMessage("没有数据文件!");
- return;
- }
- fseek(fp,0l,SEEK_SET);
- fread(&Yhead,sizeof(YpHead),1,fp);
- if(Yhead.password != 0x4347)
- {
- ErrorMessage("数据文件格式错误!");
- fclose(fp);
- return;
- }
- for(i = 0;i < MaxFrame;i++) /* clear ch[] */
- ch[i][0] = 0;
- fread(&SampleNumb,4,1,fp);
- if(SampleNumb != 0)
- fread(value,4,min(SampleNumb*2,MaxFrame),fp);
- fclose(fp);
- if(SplitNumber(Yhead,&reasonnumber,&refusenumber)==0)
- {
- ErrorMessage("AQL规格错误!");
- return;
- }
- for(i = 0;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.3f",value[i]);
- for(i = 1;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.5f",value[i]);
- startnumb = 0;
- for(row = 0;row < MaxFrame/10;row ++)
- {
- ccwprintf(wnd,152,row*20*2,VGA_RED,"%6d",row*5+1);
- ccwprintf(wnd,176,(row*2+1)*20,VGA_RED,"1/Q");
- for(col = 0;col < 5;col++)
- {
- EstablishEntryField(wnd,202+col*83,row*20*2,84,21,"",FLOAT,ch[row*10+col*2],NULL,NULL,100+row*10+col*2,NONEKEY);
- EstablishEntryField(wnd,202+col*83,row*20*2+20,84,21,"",FLOAT,ch[row*10+col*2+1],NULL,NULL,100+row*10+col*2+1,NONEKEY);
- }
- }
- EstablishVScrollBar(wnd,618,0,MaxLength*20,0,max(10,(long)(SampleNumb*2)),0,1,110,10,NONEKEY,NONEKEY,0xff49,0xff51);
- mouse_on(1);
- move_mouse(320,240);
- Selected = 0;
- do
- {
- Dialog(wnd,
- &Selected,
- &CursorX,
- &CursorY,
- &Classid,
- &id,
- &lpara);
- switch(Classid)
- {
- case 1:
- switch(id)
- {
- case ID_CANCEL:
- break;
- case 1:
- return_value = SelectYpFile(Fname);
- if((fp = fopen(Fname,"rb"))==NULL)
- {
- ErrorMessage("没有数据文件!");
- DeletePopupWindow(wnd);
- return;
- }
- fseek(fp,0l,SEEK_SET);
- fread(&Yhead,sizeof(YpHead),1,fp);
- if(Yhead.password != 0x4347)
- {
- ErrorMessage("数据文件格式错误!");
- fclose(fp);
- DeletePopupWindow(wnd);
- return;
- }
- for(i = 0;i < MaxFrame;i++)
- ch[i][0] = 0;
- fread(&SampleNumb,4,1,fp);
- if(SampleNumb != 0)
- fread(value,4,min(SampleNumb*2,MaxFrame),fp);
- fclose(fp);
- if(SplitNumber(Yhead,&reasonnumber,&refusenumber)==0)
- {
- ErrorMessage("规格错误!");
- return;
- }
- for(i = 0;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.3f",value[i]);
- for(i = 1;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.5f",value[i]);
- startnumb = 0;
- ClearWindowRect(wnd,152,0,50,439);
- for(row = 0;row < MaxFrame/10;row ++)
- {
- ccwprintf(wnd,152,row*40,VGA_RED,"%6d",row*5+1);
- ccwprintf(wnd,176,row*40+20,VGA_RED,"1/Q");
- for(col = 0;col < 10;col++)
- ModifyDataEntry(wnd,100+row*10+col,ch[(row*10+col)]);
- }
- ModifyVScrollBar(wnd,618,0,MaxLength*20,0,max(10,(long)(SampleNumb*2)),startnumb,1,110,10,NONEKEY,NONEKEY,0xff49,0xff51);
- break;
- case 2:
- Selected = 2;
- CursorX = 100;
- break;
- case 3:
- if (y_n(Fname) == 0)
- {
- autoaq(Fname);
- fp = fopen(Fname,"rb");
- fseek(fp,sizeof(YpHead),SEEK_SET);
- for(i = 0;i < MaxFrame;i++)
- ch[i][0] = 0;
- fread(&SampleNumb,4,1,fp);
- if(SampleNumb != 0)
- fread(value,4,min(SampleNumb*2,MaxFrame),fp);
- fclose(fp);
- for(i = 0;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.3f",value[i]);
- for(i = 1;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.5f",value[i]);
- startnumb = 0;
- ClearWindowRect(wnd,152,0,50,439);
- for(row = 0;row < MaxFrame/10;row ++)
- {
- ccwprintf(wnd,152,row*40,VGA_RED,"%6d",row*5+1);
- ccwprintf(wnd,176,row*40+20,VGA_RED,"1/Q");
- for(col = 0;col < 10;col++)
- ModifyDataEntry(wnd,100+row*10+col,ch[(row*10+col)]);
- }
- ModifyVScrollBar(wnd,618,0,MaxLength*20,0,max(10,(long)(SampleNumb*2)),startnumb,1,110,10,NONEKEY,NONEKEY,0xff49,0xff51);
- break;
- }
- else
- break;
- case 4:
- STATISRESULT(Fname);
- break;
- }
- break;
- case 2:
- if(ch[(id-100)][0]!=0)
- {
- if((startnumb+id-100)/2 >= reasonnumber)
- {
- ErrorMessage(" Data too many ");
- break;
- }
- if(startnumb+id-100 > SampleNumb*2)
- {
- ErrorMessage("前面数据还未输入!");
- break;
- }
- sscanf(ch[(id-100)],"%f",&value[id-100]);
- fp = fopen(Fname,"r+b");
- if(startnumb+id-100 == SampleNumb*2)
- {
- SampleNumb++;
- sscanf(ch[id-100+1],"%f",&value[id-99]);
- fseek(fp,sizeof(YpHead),SEEK_SET);
- fwrite(&SampleNumb,4,1,fp);
- fseek(fp,(startnumb+id-100)*4,SEEK_CUR);
- fwrite(&value[id-100],4,1,fp);
- fwrite(&value[id-99],4,1,fp);
- }
- else
- {
- fseek(fp,sizeof(YpHead),SEEK_SET);
- fwrite(&SampleNumb,4,1,fp);
- fseek(fp,(startnumb+id-100)*4,SEEK_CUR);
- fwrite(&value[id-100],4,1,fp);
- }
- fclose(fp);
- if(id==109)
- ModifyVScrollBar(wnd,618,0,MaxLength*20,0,max(10,(long)(SampleNumb*2)),startnumb,1,110,10,NONEKEY,NONEKEY,0xff49,0xff51);
- }
- if((Selected != 1)||(CursorX < 640)) break;
- switch(CursorX)
- {
- case 0x0f48:
- if(id > 100)
- {
- CursorX = id-1;
- Selected = 2;
- }
- else
- {
- if(startnumb > 0)
- {
- startnumb -=2;
- fp = fopen(Fname,"rb");
- fseek(fp,sizeof(YpHead)+4+startnumb*4,SEEK_SET);
- fread(value,4,min(SampleNumb*2-startnumb,MaxFrame),fp);
- fclose(fp);
- for(i = 0;i < MaxFrame;i++)
- ch[i][0] = 0;
- for(i = 0;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.3f",value[i]);
- for(i = 1;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.5f",value[i]);
- ClearWindowRect(wnd,152,0,50,439);
- for(row = 0;row < MaxFrame/10;row ++)
- {
- ccwprintf(wnd,152,row*40,VGA_RED,"%6d",startnumb/2+row*5+1);
- ccwprintf(wnd,176,row*40+20,VGA_RED,"1/Q");
- for(col = 0;col < 10;col++)
- ModifyDataEntry(wnd,100+row*10+col,ch[(row*10+col)]);
- }
- CursorX = id;
- Selected = 2;
- ModifyVScrollBar(wnd,618,0,MaxLength*20,0,max(10,(long)(SampleNumb*2)),startnumb,1,110,10,NONEKEY,NONEKEY,0xff49,0xff51);
- }
- else
- {
- Selected = 2;
- CursorX = id;
- }
- }
- break;
- case 0x0f50:
- if(startnumb+id-100<SampleNumb*2)
- {
- if(id < 209)
- {
- CursorX = id+1;
- Selected = 2;
- }
- else
- {
- startnumb += 2;
- startnumb = startnumb/2*2;
- fp = fopen(Fname,"rb");
- fseek(fp,sizeof(YpHead)+4+startnumb*4,SEEK_SET);
- fread(value,4,min(SampleNumb*2-startnumb,MaxFrame),fp);
- fclose(fp);
- for(i = 0;i < MaxFrame;i++)
- ch[i][0] = 0;
- for(i = 0;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.3f",value[i]);
- for(i = 1;i < min(SampleNumb*2,MaxFrame);i+=2)
- sprintf(ch[i],"%.5f",value[i]);
- ClearWindowRect(wnd,152,0,50,439);
- for(row = 0;row < MaxFrame/10;row ++)
- {
- ccwprintf(wnd,152,row*40,VGA_RED,"%6d",startnumb/2+row*5+1);
- ccwprintf(wnd,176,row*40+20,VGA_RED,"1/Q");
- for(col = 0;col < 10;col++)
- ModifyDataEntry(wnd,100+row*10+col,ch[(row*10+col)]);
- }
- CursorX = id;
- Selected = 2;
- ModifyVScrollBar(wnd,618,0,MaxLength*20,0,max(10,(long)(SampleNumb*2)),startnumb,1,110,10,NONEKEY,NONEKEY,0xff49,0xff51);
- }
- }
- else
- {Selected = 2;
- CursorX = id;
- }
- break;
- case 0x0f1e:
- Selected = 2;
- CursorX = 3;
- break;
- case 0x0f1f:
- Selected = 2;
- CursorX = 4;
- break;
- case 0x0f21:
- Selected = 2;
- CursorX = 1;
- break;
- case 0x0f2d:
- id = ID_CANCEL;
- break;
- default:
- break;
- }
- break;
- case 4:
- startnumb = lpara;
- startnumb = startnumb/2*2;
- for(i = 0;i < MaxFrame;i++)
- {
- ch[i][0] = 0;
- value[i] = 0.0;
- }
- fp = fopen(Fname,"rb");
- fseek(fp,sizeof(YpHead)+4+startnumb*4,SEEK_SET);
- lbuf = SampleNumb*2-startnumb;
- if(SampleNumb*2 > startnumb)
- fread(value,4,min(lbuf,MaxFrame),fp);
- fclose(fp);
- for(i = 0;i < min(lbuf,MaxFrame);i+=2)
- sprintf(ch[i],"%.3f",value[i]);
- for(i = 1;i < min(lbuf,MaxFrame);i+=2)
- sprintf(ch[i],"%.5f",value[i]);
- ClearWindowRect(wnd,152,0,50,439);
- for(row = 0;row < MaxFrame/10;row ++)
- {
- ccwprintf(wnd,152,row*40,VGA_RED,"%6d",startnumb/2+row*5+1);
- ccwprintf(wnd,176,row*40+20,VGA_RED,"1/Q");
- for(col = 0;col < 10;col++)
- ModifyDataEntry(wnd,100+row*10+col,ch[(row*10+col)]);
- }
- break;
- default:
- break;
- }
- }while(id!=ID_CANCEL);
- DeletePopupWindow(wnd);
- return;
- }
- /*----------------------------------------------------------------------*/
- /* histo: Draw a 2-D bar chart using Bar and Rectangle. */
- /*----------------------------------------------------------------------*/
- unsigned char new_fillmask[] =
- {
- 0xaa,
- 0x55,
- 0xaa,
- 0x55,
- 0xaa,
- 0x55,
- 0xaa,
- 0x55
- };
- void STATISRESULT(char *Fname)
- {
- struct stat filestat;
- FILE * printer_pointer;
- int xstep, ystep,x_axis,y_axis,x,y;
- int swidth,tall;
- int i;
- int j, h,w,x0,y0;
- float y_step0,y_value,min_y,max_y,max_y0;
- int ul_x,ul_y,dr_x,dr_y;
- unsigned int bin_number = 21;
- float lower_bound;
- float upper_bound;
- float x_step0;
- char x_name[]="容 量";
- POPUPWINDOW * wnd;
- int id,Classid;
- int Selected,CursorX,CursorY;
- long lpara;
- FILE *Data;
- float min_value,max_value,CP=0;
- long SampleNumb;
- float SampleValue,DFValue;
- int x_number;
- float value[21];
- float bad_rate,bad_rate_n,supervalue;
- float total_mean,total_ss,tp,cp,K,Z1,Z2,bad_rate1,bad_rate2;
- int below,abovenum;
- float foxX,oxfX2;
- struct dosdate_t dos_date;
- YpHead Yhead;
- char *AQL[]={ " ",
- "0.65",
- "1.0",
- "1.5"
- };
- float DF,max_DF;
- long upDF;
- int reasonnumber,refusenumber;
- char drive[_MAX_DRIVE],dir[_MAX_DIR],file[_MAX_FNAME],ext[_MAX_EXT];
- time_t ltime;
- _splitpath(Fname,drive,dir,file,ext);
- for(i = 0;i < 21;i++)
- value[i] = 0.0;
- if((Data = fopen(Fname,"rb")) == NULL)
- {
- ErrorMessage("打不开数据文件!");
- return;
- }
- fseek(Data,0l,SEEK_SET);
- fread(&Yhead,sizeof(YpHead),1,Data);
- if(SplitMaterial(Yhead,&lower_bound,&upper_bound,&DF)==0)
- {
- fclose(Data);
- ErrorMessage("规格错误!");
- return;
- }
- if(SplitNumber(Yhead,&reasonnumber,&refusenumber)==0)
- {
- fclose(Data);
- ErrorMessage("标准错误!");
- return;
- }
- total_mean = 0;
- total_ss = 0;
- below = abovenum = 0;
- upDF = 0;
- max_DF = 0;
- y_step0 = (upper_bound-lower_bound+0.001)/11;
- fread(&SampleNumb,4,1,Data);
- if(SampleNumb == 0)
- {
- fclose(Data);
- ErrorMessage("无数据存在");
- return;
- }
- for(i = 0;i < SampleNumb;i++)
- {
- fread(&SampleValue,4,1,Data);
- total_mean += SampleValue;
- total_ss += SampleValue*SampleValue;
- x_number = (int)((SampleValue-lower_bound)/y_step0);
- if(x_number < 0) below ++;
- if(x_number > 10) abovenum ++;
- x_number += 5;
- if(x_number <0) x_number = 0;
- if(x_number > 20) x_number = 20;
- value[x_number]++;
- fread(&DFValue,4,1,Data);
- if(DFValue > DF)
- {
- if(max_DF < DFValue-DF) max_DF = DFValue-DF;
- upDF ++;
- }
- }
- fclose(Data);
- supervalue = (float)(abovenum+below);
- bad_rate_n = (float)(supervalue/SampleNumb);
- /*
- bad_rate_n = (float)(supervalue/reasonnumber);
- */
- total_mean /= SampleNumb;
- if(total_ss == total_mean*total_mean*SampleNumb) total_ss = 0;
- else
- total_ss = sqrt(total_ss/SampleNumb-total_mean*total_mean);
- if(total_ss)
- cp = (upper_bound-lower_bound)/(Yhead.delta*total_ss*2);
- else cp = 1;
- K = fabs((lower_bound+upper_bound)/2-total_mean)/((upper_bound-lower_bound)/2);
- Z1 = Yhead.delta*cp*(1+K);
- Z2 = Yhead.delta*cp*(1-K);
- if(Z1 <= 3.0) bad_rate1 = 1-AccGS[(int)((Z1+0.025)*20)];
- else if(Z1 <= 4.9) bad_rate1 = AuxGS[(int)((Z1+0.05)*10-30)];
- else bad_rate1 = AuxGS[19];
- if(Z2 <= 3.0) bad_rate2 = 1-AccGS[(int)((Z2+0.025)*20)];
- else if(Z2 <= 4.9) bad_rate2 = AuxGS[(int)((Z2+0.05)*10-30)];
- else bad_rate2 = AuxGS[19];
- max_y0 = 0;
- bad_rate = bad_rate1+bad_rate2;
- for(i = 0; i < 21; i++)
- {
- value[i] = value[i]*100/SampleNumb;
- if(value[i] > max_y0) max_y0 = value[i];
- }
- max_y0 = max_y0/10*10 + 10;
- mouse_off(1);
- h = 16; /* Character height */
- w = 8; /* character width */
- ul_x = 0;
- ul_y = 0;
- dr_x = 639;
- dr_y = 479;
- _setfillmask(NULL);
- /* -------- Establist histo window -------- */
- wnd = EstablishPopupWindow(ul_x,ul_y,dr_x-ul_x+1,dr_y-ul_y+1,
- VGA_DARKWHITE,1);
- SetTitle(wnd,"CWT成品质检抽样频数分布图 ");
- DisplayTM(10,425);
- /* Return button */
- EstablishPressButton(wnd,460,400,74,40,"返 回(R)",ID_OK,0xff13);
- /* Print histogram button */
- EstablishPressButton(wnd,320,404,74,32,"打 印(P)",5,0xff19);
- ccprintf(ul_x+16*27,ul_y+2,VGA_BLACK,"应抽样数:%d",reasonnumber);
- ccwprintf(wnd,10,5,VGA_BLACK,"批号:%-s",file);
- /* Get UNIX-style time and display as number and string. */
- time( <ime );
- ccwprintf(wnd,160+16*9,8,VGA_BLACK,"%s", ctime( <ime ) );
- /*
- printf( "Time in seconds since GMT 1/1/70:\t%ld\n", ltime );
- printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) );
- */
- switch(ext[1])
- {
- case 'y':
- case 'Y':
- if( !stat( Fname, &filestat ) )
- {
- ccwprintf(wnd,160,5,VGA_BLACK,"银片来料抽检时间:");
- ccwprintf(wnd,160+16*9,0,VGA_BLACK,"%s", Yhead.time );
- }
- break;
- case '2':
- if( !stat( Fname, &filestat ) )
- {
- ccwprintf(wnd,160,5,VGA_BLACK,"焊锡后抽检时间:");
- ccwprintf(wnd,160+16*9,0,VGA_BLACK,"%s", ctime( &filestat.st_atime ) );
- }
- break;
- case '3':
- if( !stat( Fname, &filestat ) )
- {
- ccwprintf(wnd,160,5,VGA_BLACK,"固化后抽检时间");
- ccwprintf(wnd,160+16*9,0,VGA_BLACK,"%s", ctime( &filestat.st_atime ) );
- }
- break;
- case '4':
- if( !stat( Fname, &filestat ) )
- {
- ccwprintf(wnd,160,5,VGA_BLACK,"测试工序抽检时间:");
- ccwprintf(wnd,160+16*9,0,VGA_BLACK,"%s", ctime( &filestat.st_atime ) );
- }
- break;
- case '5':
- if( !stat( Fname, &filestat ) )
- {
- ccwprintf(wnd,160,5,VGA_BLACK,"包装入库抽检时间:");
- ccwprintf(wnd,160+16*9,0,VGA_BLACK,"%s", ctime( &filestat.st_atime ) );
- }
- break;
- default:
- break;
- }
- /*
- ccwprintf(wnd,350,5,VGA_BLACK,"公差幅度:%f,%-f",lower_bound,upper_bound);
- */
- ccwprintf(wnd,10,35,VGA_BLACK," 组 界 组中值 已抽样数:%-ld",SampleNumb);
- ccwprintf(wnd,10+26*w+8+21*11,35,VGA_BLACK,"频数");
- tall = 21*11 ;
- /* original pointer */
- x0 = 10+26*w + ul_x;
- y0 = ul_y +55 + 20;
- /* swidth : histogram width */
- /* ---- X step & swidth ---- */
- swidth = 21*11;
- ystep = 11;
- /* ---- histo area ---- */
- _setcolor(VGA_WHITE);
- _rectangle(_GFILLINTERIOR,x0,y0 ,swidth+x0,y0+tall);
- _setcolor(VGA_BLACK);
- _rectangle(_GBORDER,x0,y0 ,swidth+x0,y0+tall);
- line(ul_x,dr_y-66,dr_x,dr_y-66);
- /* ---- unit ---- */
- /* if( *Unit)
- {
- x = x0+bin_number*xstep/2,
- y = y0+h+h/2;
- ccprintf(x+8,y,VGA_BLACK,"单位:(%s)",Unit);
- }
- */
- /* ---- Ver dot line ---- */
- _setcolor(VGA_DARKGRAY);
- y_axis = ystep*5+y0;
- _setlinestyle(0xaaaa);
- line(x0,y_axis,x0+tall-1,y_axis);
- line(x0,y_axis+ystep*11,x0+tall-1,y_axis+ystep*11);
- _setlinestyle(0xffff);
- j = x0;
- /* ---- Her dot line ---- */
- x_step0 = 10;
- xstep = (int)(tall*x_step0/ max_y0) ;
- while( xstep > 100)
- {
- x_step0 /= 5.0;
- xstep = (int)(tall*x_step0/ max_y0);
- }
- /* ---- Y - axis ----- */
- x_axis = x0;
- i = 0 ;
- while( x_axis <= (x0+tall) )
- {
- line( x_axis,y0+tall, x_axis, y0+tall+4 );
- x = x_axis-8;
- y = y0+tall;
- ccprintf(x,y,VGA_BLACK,"%-3d",(int)(x_step0 *((float) i)));
- _setlinestyle(0xaaaa);
- line(x_axis,y0,x_axis,ystep*bin_number + y0);
- _setlinestyle(0xffff);
- i ++;
- x_axis = (int) (x0 +((int) i*x_step0/ max_y0)*tall + 0.5 );
- }
- x_axis = x0;
- i = 0;
- while( x_axis <= (x0+tall))
- {
- line(x_axis,y0+tall, x_axis, y0+tall+2 );
- i ++;
- x_axis = (int)(x0 + i*tall*x_step0/ max_y0/2 + 0.5);
- }
- x = x0 +tall+4+10;
- y = y0 +tall;
- ccprintf(x,y,VGA_BLACK,"%%");
- /* ---- histo bins ---- */
- j = y0;
- for( i=0 ; i < bin_number ; ++i )
- {
- y_value = value[i];
- x_axis = (int)(x0 + y_value/max_y0 * tall + 0.5);
- _setcolor(VGA_WHITE);
- _setfillmask(NULL);
- _rectangle(_GFILLINTERIOR, x0, j, x_axis, j+ystep);
- _setcolor(VGA_DARKGRAY);
- _setfillmask(new_fillmask);
- _rectangle(_GBORDER, x0,j,x_axis, j+ystep);
- if(x_axis > x0 + 1)
- {
- _floodfill(x0+1,j+1,VGA_DARKGRAY);
- }
- ccprintf(0,y0+11*i-6,VGA_BLACK,"%9.2f-%-9.2f",lower_bound+(i-5)*y_step0,lower_bound+(i-4)*y_step0);
- ccprintf(90+48,y0+11*i-6,VGA_BLACK,"%9.2f",lower_bound+(i-4.5)*y_step0);
- ccprintf(x0+tall+2,y0+11*i-6,VGA_BLACK,"%-d",(int)(value[i]*SampleNumb/100+0.1));
- line( x0-2,j, x0, j );
- j += ystep;
- } /* all bins */
- _setfillmask(NULL);
- line( x0-4, y0, x0, y0 );
- line( x0-4,j, x0, j );
- ccwprintf(wnd,x0+tall+w*7,35,VGA_BLUE,"公差幅度:");
- ccprintf(x0+tall+w*7,y0+ystep*5+8,VGA_BLUE,"下限:%-.2f",lower_bound);
- ccprintf(x0+tall+w*7,y0+ystep*5-8,VGA_BLUE,"超下数:%-d",below);
- ccprintf(x0+tall+w*7,y0+ystep*16+8,VGA_BLUE,"超上数:%-d",abovenum);
- ccprintf(x0+tall+w*7,y0+ystep*16-8,VGA_BLUE,"上限:%-.2f",upper_bound);
- ccprintf(10,y0+tall+h,VGA_BLACK,"规格: %s",Yhead.material);
- ccprintf(160,y0+tall+h,VGA_BLACK,"质量特性名:%s 单位:%s",Yhead.sob,Yhead.Unit);
- ccprintf(365,y0+tall+h,VGA_BLACK,"AQL = %s",AQL[Yhead.standard]);
- ccprintf(460,y0+tall+h,VGA_RED,"总超限数应小于 %d",refusenumber);
- /*
- ccprintf(350,y0+tall+h,VGA_BLACK,"应抽样数:%d",reasonnumber);
- */
- ccprintf(10,y0+tall+h*2+2,VGA_BLACK,"合格品率:%-.2f%%",100-bad_rate_n*100);
- ccprintf(10+142,y0+tall+h*2+2,VGA_BLACK,"不合格品率:%-.2f%%",bad_rate_n*100);
- ccprintf(10+290,y0+tall+h*2+2,VGA_BLACK,"方差:%-f",total_ss);
- ccprintf(10+450,y0+tall+h*2+2,VGA_BLACK,"偏差调节系数: %d",Yhead.delta);
- ccprintf(10,y0+tall+h*3+4,VGA_BLACK,"最大容量:%-.4f",CP);
- ccprintf(10+142,y0+tall+h*3+4,VGA_BLACK,"均值:%-.4f",total_mean);
- ccprintf(10+290,y0+tall+h*3+4,VGA_BLACK,"最小容量:%-.4f",CP);
- ccprintf(10+435,y0+tall+h*3+4,VGA_BLACK,"总数量: %ld",Yhead.NNumb);
- ccprintf(10,y0+tall+h*4+6,VGA_BLACK,"标准损耗:%-.5f",DF);
- ccprintf(10+142,y0+tall+h*4+6,VGA_BLACK,"超标数:%-ld",upDF);
- ccprintf(10+290,y0+tall+h*4+6,VGA_BLACK,"最大差值:%-.5f",max_DF);
- ccprintf(10+435,y0+tall+h*4+6,VGA_BLACK,"温度: %-.2f",Yhead.Temp);
- ccprintf(10,y0+tall+h*5+8,VGA_BLACK,"最大损耗:%-.5f",DF);
- ccprintf(10+142,y0+tall+h*5+8,VGA_BLACK,"平均值:%-.5f",total_mean);
- ccprintf(10+290,y0+tall+h*5+8,VGA_BLACK,"最小损耗:%-.5f",DF);
- /* ccprintf(10+435,y0+tall+h*5+8,VGA_BLACK,"工程能力指数:%-.4f",cp);*/
- ccprintf(10+435,y0+tall+h*5+8,VGA_BLACK,"等效电阻:%-.2f",Yhead.Requ);
- mouse_on(1);
- Selected = 0;
- do
- {
- Dialog(wnd,
- &Selected,
- &CursorX,
- &CursorY,
- &Classid,
- &id,
- &lpara);
- switch(id)
- {
- case 5:
- print_screen(1,1,dr_y-68,dr_x-7);
- break;
- default:
- break;
- }
- }while(id != ID_OK);
- DeletePopupWindow(wnd);
- }
- /* -----------------------------------------------------------------------
- DisplayTM : Display "CWT Co." Trade Mark
- -------------------------------------------------------------------------- */
- void DisplayTM(int x,int y)
- {
- int old_color;
- old_color = _getcolor();
- _setviewport(x,y,x+285,y+31);
- _clearscreen(_GVIEWPORT);
- _setcolor(VGA_LIGHTGRAY);
- _rectangle(_GFILLINTERIOR,0,0,322,32);
- _setcolor(VGA_BLUE);
- _ellipse(_GFILLINTERIOR,0,0,28,28);
- _setcolor(VGA_WHITE);
- line(0,10,28,10);
- line(0,11,28,11);
- line(0,12,28,12);
- line(0,13,28,13);
- line(0,14,28,14);
- line(0,15,28,15);
- line(0,16,28,16);
- line(0,17,28,17);
- line(0,18,28,18);
- line(0,19,28,19);
- line(0,20,28,20);
- ccprintf(0,4,VGA_BLUE,"C");
- ccprintf(10,4,VGA_BLUE,"W");
- ccprintf(20,4,VGA_BLUE,"T");
- ccprintf(34,6,VGA_BLACK,"中伟达电子实业公司");
- /*
- ccprintf(34,0,VGA_BLACK,"C W T Electronic");
- ccprintf(34,10,VGA_BLACK,"Industry & Commerce Co.");
- */
- /* recover old viewport */
- _setviewport(0,0,639,479);
- /* recover old color */
- _setcolor(old_color);
- return;
- }
- int autoaq(char *Fname)
- {
- char buffer[_MAX_PATH];
- char drive[_MAX_DRIVE],dir[_MAX_DIR],file[_MAX_FNAME],ext[_MAX_EXT];
- struct find_t fileinfo;
- YpHead Yhead;
- FILE *data_pointer,*data1_pointer;
- long SampleNumb;
- int i;
- int num, len,len3, ttt, dly;
- char buf[230];
- char *strng1,c; /* pointer to the character string */
- int key;
- unsigned char juk;
- float cp,cpt;
- float d;
- float value[110];
- char CP[61];
- char DF[61];
- char *pdest, *newstring;
- int pos;
- POPUPWINDOW *wnd;
- int Classid,id,Selected,CursorX,CursorY;
- long return_lpara;
- char ch10[20],ch11[20],ch12[20];
- unsigned long FrameX,FrameY;
- int reasonnumber,refusenumber;
- int primadd, KeyPlay;
- if( (data_pointer = fopen(Fname,"rb")) == NULL)
- {
- ErrorMessage(" 打不开银片数据文件 ");
- return(1);
- }
- /* Read default data file name */
- fseek(data_pointer,0l,SEEK_SET);
- fread(&Yhead,sizeof(YpHead),1,data_pointer);
- fread(&SampleNumb,4,1,data_pointer);
- fclose(data_pointer);
- if(SplitNumber(Yhead,&reasonnumber,&refusenumber)==0)
- {
- ErrorMessage("标准错误!");
- return(1);
- }
- primadd = 17;
- if (!opengpib()) {
- printf ("\n\n Drivers not present.\n");
- exit ( 10 );
- }
- buf[0] = RENT;
- buf[1] = TOSET;
- buf[2] = 100;
- buf[3] = TOEN;
- num = writecom (buf, 4);
- if (num != 4) {
- printf ("\n IEEE command error \n");
- }
- sendcom ( LAD + primadd );
- sendcom ( EOIEN );
- strng1 = "TRIG2";
- len = strlen (strng1);
- num = writedat (strng1, len); /* send data bytes */
- sendcom ( EOIEN ); /* send Primary Talk Addrs */
- if((data1_pointer=fopen(Fname,"wb"))==NULL)
- {
- ErrorMessage(" 打不开数据文件 ");
- return;
- }
- SampleNumb = 0;
- fseek(data1_pointer,94l,SEEK_SET);
- fwrite(&SampleNumb,4,1,data1_pointer);
- mouse_off(1);
- _setviewport(0,0,639,479);
- wnd = EstablishPopupWindow(120,60,400,360,VGA_WHITE,1);
- SetTitle(wnd,"银 片 抽 检 数 据 文 件");
- ccwprintf(wnd,30,10,VGA_BLACK,"应输入样品个数 : %d",reasonnumber);
- ccwprintf(wnd,30,30,VGA_BLACK,"已经输入 个样品");
- ccwprintf(wnd,30,130,VGA_BLACK,"插上电容时按[更正]键,当4278A显示值正确后,");
- ccwprintf(wnd,30,148,VGA_BLACK,"再按左边的[Ese]键,测量值则存于您在计算机中");
- ccwprintf(wnd,30,166,VGA_BLACK,"指定的文件内.按大键盘左上角的[Esc]键,即退出");
- ccwprintf(wnd,30,184,VGA_BLACK,"联机测量状态.这时4278A可照常使用.");
- ccwprintf(wnd,30,250,VGA_RED,"退出 -- 按 Esc 键");
- mouse_on(1);
- move_mouse(630,470);
- do
- {
- _asm
- {
- mov ax,0
- mov dx,201h
- in al,dx
- mov juk,al
- }
- if(juk == 0xe0)
- {
- sendcom ( LAD + primadd ); /* send Primary Talk Addrs */
- strng1 = "DATA?";
- len = strlen (strng1);
- num = writedat (strng1, len); /* send data bytes */
- sendcom ( EOIEN ); /* send Primary Talk Addrs */
- while( 1 )
- {
- _asm
- {
- mov ax,0
- mov dx,201h
- in al,dx
- mov juk,al
- }
- if(juk == 0xf0)
- break;
- }
- for( i=0 ; i < 10000; ++i );
- SampleNumb = SampleNumb + 1;
- sendcom ( TAD + primadd ); /* send Primary Talk Addrs */
- num = readdat ( buf, 25 ); /* READ DATA */
- buffer[26] = '\0';
- pdest = memccpy( CP, buf, ',', 60 );
- pdest = pdest - 1;
- *pdest = '\0';
- pdest = pdest + 1;
- cp = (float)atof( CP );
- cpt = cp * 1E+12;
- if(cpt >= 1000)
- {
- cp = cp * 1E+9;
- ClearWindowRect(wnd,30,70,260,25);
- ccwprintf(wnd,30,70,VGA_BLUE,"电容值Cp = %.4f nF",cp);
- }
- else
- {
- cp = cp * 1E+12;
- ClearWindowRect(wnd,30,70,260,25);
- ccwprintf(wnd,30,70,VGA_BLUE,"电容值Cp = %.4f pF",cp);
- }
- pos = pdest - CP;
- pdest = memccpy( DF, buf + pos, '+', 60 );
- pdest = pdest - 1;
- *pdest = '\0';
- d = (float)atof( DF );
- ClearWindowRect(wnd,30,30,150,25);
- ccwprintf(wnd,30,30,VGA_BLACK,"已经输入%-4d 个样品",SampleNumb);
- ClearWindowRect(wnd,30,100,260,25);
- ccwprintf(wnd,30,100,VGA_BLUE,"损耗值 D = %.5f ",d);
- fwrite(&cp,4,1,data1_pointer);
- fwrite(&d,4,1,data1_pointer);
- _setcolor(VGA_WHITE);
- }
- if(kbhit())
- {
- KeyPlay = get_char();
- if(KeyPlay != 27) KeyPlay = 0;
- }
- } while(KeyPlay != 27);
- KeyPlay = 0; /* must change the "KeyPlay",so that KeyPlay != 27 */
- sendcom ( LAD + primadd );
- strng1 = "*RST";
- len = strlen (strng1);
- num = writedat (strng1, len); /* send data bytes */
- sendcom ( EOIEN ); /* send Primary Talk Addrs */
- fseek(data1_pointer,94l,SEEK_SET);
- fwrite(&SampleNumb,4,1,data1_pointer);
- Yhead.password = 0x4347;
- Yhead.label[0] = 0;
- strcpy(Yhead.time,"950619/8:30");
- Yhead.NNumb = 100000;
- /*
- Yhead.material[0] = 0;
- */
- strcpy(Yhead.material,"4Z/Z5V");
- Yhead.standard = 1;
- Yhead.delta = 3;
- if(cpt >= 1000)
- {
- strcpy(Yhead.Unit,"nF");
- }
- else
- {
- strcpy(Yhead.Unit,"pF");
- }
- strcpy(Yhead.sob,"电容");
- Yhead.Temp = 0.0;
- Yhead.Requ = 0.0;
- fseek(data1_pointer,0l,SEEK_SET);
- fwrite(&Yhead,sizeof(YpHead),1,data1_pointer);
- fclose(data1_pointer);
- buf[0] = RENF; /* Send */
- buf[1] = 17 + LAD; /* make primary listen addrs */
- num = writecom (buf, 2); /* send command bytes */
- if(num != 2)
- {
- ErrorMessage("IEEE 命令错误!");
- }
- sendcom (UNL); /* send untalk command */
- closegpib (); /* close drivers at end */
- DeletePopupWindow(wnd);
- return;
- }
- int y_n(char *Fname)
- {
- int curr_da_image_bank;
- POPUPWINDOW *wnd;
- int id,Selected,CursorX,CursorY;
- /* Establish verify window */
- wnd = EstablishPopupWindow(180,150,280,180,VGA_NEWWHITE,1);
- SetTitle(wnd,"选 中 文 件 确 认 窗");
- /* OK & Cancel pressbutton */
- EstablishPressButton(wnd,40,100,74,40,"确 认(O)",ID_OK,0xff18);
- EstablishPressButton(wnd,166,104,74,32,"取 消(C)",ID_CANCEL,0xff2e);
- ccwprintf(wnd,10,12,VGA_BLACK,"现将使用文件 %s ",Fname);
- ccwprintf(wnd,10,30,VGA_BLACK,"存贮新数据.如果确认,");
- ccwprintf(wnd,10,48,VGA_BLACK,"文件内容将被清除并更新.");
- ccwprintf(wnd,10,66,VGA_BLACK,"若不愿更新,则按取消键.");
- Selected = 0;
- Dialog(wnd,
- &Selected,
- &CursorX,
- &CursorY,
- NULL,
- &id,
- NULL);
- DeletePopupWindow(wnd);
- if(id == ID_CANCEL)
- {
- return (1);
- }
- return (0);
- }
- \032
复制代码
所有资料51hei提供下载:
CWTSQ1.zip
(11.39 KB, 下载次数: 5)
|