📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
// 用线程部分 光谱扫描、基线扫描、时间扫描、定点测量
//
#pragma hdrstop
#include <vcl.h>
#include <stdio.h>
#include "dir.h"
#include "math.h"
#include "Printers.hpp"
#include "ThreadE.h" // 辅助线程
#include "Unit1.h" // 主窗口
#include "Unit2.h" // 参数设置窗口
#include "Unit3.h" // 输入常数窗口
#include "Unit4.h" // 关于窗口
#include "Unit5.h" // 输入检索波长值窗口
#include "Unit6.h" // 设置坐标窗口
#include "Unit7.h" // 吸收峰窗口
#include "Unit8.h" // 输入峰值高度窗口
#include "Unit9.h" // 定点测量窗口
#include "Unit10.h" // 仪器波长线性校正窗口
#include "Unit11.h" // 打印设置窗口
#include "Unit12.h" // 系统初始化窗口
#include "Unit13.h" // 改变系统提示
#include "Unit14.h" // 开机提示
#include "Unit15.h" // 关机提示
#include "Unit16.h" // 数据列表
#include "Unit17.h"
#include "Unit18.h"
#include "Unit19.h"
#include "Unit20.h"
#include "Unit24.h" // 谱线参数
#include "CH375DLL.H"
#include "IO.h"
#include "pointreport.h"
#include "delaytest.h"
typedef void (*ExecFun)(void);
void Wait_1s(int wt);
void To_baseline_scan(void);
void To_scan();
void To_BoChangJianSuo(void);
void To_SysInit(void);
void To_ScanFengZhi(void);
void To_fixed_measure(void); /*定点测量*/
void To_Scan_T(void);
void To_pp_measure(void);
#include "Fram.h"//定义了JUKUAN等
//---------------------------------------------------------------------------
#pragma package(smart_init)
//#pragma link "PCILib_OCX"
//#pragma link "PCILib_OCX"
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
void TForm1::ReadDelay(void)
{
char sdelay[20]="";
int iFileHandle;
AnsiString strFName;
strFName = MyDir + "delay.ini";
if(FileExists(strFName))
{
iFileHandle=FileOpen(strFName, fmOpenRead);
FileRead(iFileHandle,sdelay,sizeof(sdelay));
FileClose(iFileHandle);
delaypara=StrToInt(sdelay);
//Edit1->Text=sdelay;
//Label1->Caption=StrToInt(sdelay)+100;
//Label5->Caption=StrToInt(sdelay);
}
else
{
delaypara=430; //modify
}
}
//---------------------------------------------------------------------------
float TForm1::tas(int mod) //采集数据
{
int s=0, r=0, d=0;
float t=0, a, b;
tts = 0, ttr = 0; ttd = 0;
bool SAMPLE = true;
switch(mod)
{
case 0:// 返回基线
if(wn<=8000)
{
pInterface->USBDataDown(0x5C,0x10,con>>8,con&0xff);
pTimeDelay->delay_ms(10);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
r = ADC[8]<<24|ADC[9]<<16|ADC[10]<<8|ADC[11];
}
}while(SAMPLE);
tts = (float)s/con;
ttr = (float)r/con;
ttd = (float)d/con;
a = (float)tts-pp1*(float)ttd;
b = (float)ttr-pp1*(float)ttd;
pTimeDelay->delay_ms(40);
}
else if(wn<=8800)
{
pInterface->USBDataDown(0x5C,0x08,con>>8,con&0xff);
pTimeDelay->delay_ms(80);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
r = ADC[8]<<24|ADC[9]<<16|ADC[10]<<8|ADC[11];
}
}while(SAMPLE);
tts = (float)s/con;
ttr = (float)r/con;
ttd = (float)d/con;
a = (float)tts-pp1*(float)ttd;
b = (float)ttr-pp1*(float)ttd;
pTimeDelay->delay_ms(40);
}
else
{
pInterface->USBDataDown(0x5C,0x04,con>>8,con&0xff);
pTimeDelay->delay_ms(40);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
r = ADC[8]<<24|ADC[9]<<16|ADC[10]<<8|ADC[11];
}
}while(SAMPLE);
tts = (float)s/con;
ttr = (float)r/con;
ttd = (float)d/con;
a = (float)tts-pp1*(float)ttd;
b = (float)ttr-pp1*(float)ttd;
pTimeDelay->delay_ms(20);
}
if(a==0)
a=1.0;
t = b/a;
break;
case 1:
case 2:// 返回透过率
if(wn<=8000)
{
pInterface->USBDataDown(0x5C,0x10,con>>8,con&0xff);
pTimeDelay->delay_ms(10);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
r = ADC[8]<<24|ADC[9]<<16|ADC[10]<<8|ADC[11];
}
}while(SAMPLE);
tts = (float)s/con;
ttr = (float)r/con;
ttd = (float)d/con;
a = (float)tts-pp1*(float)ttd;
b = (float)ttr-pp1*(float)ttd;
pTimeDelay->delay_ms(40);
}
else if(wn<=8800)
{
pInterface->USBDataDown(0x5C,0x08,con>>8,con&0xff);
pTimeDelay->delay_ms(78);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
r = ADC[8]<<24|ADC[9]<<16|ADC[10]<<8|ADC[11];
}
}while(SAMPLE);
tts = (float)s/con;
ttr = (float)r/con;
ttd = (float)d/con;
a = (float)tts-pp1*(float)ttd;
b = (float)ttr-pp1*(float)ttd;
pTimeDelay->delay_ms(40);
}
else
{
pInterface->USBDataDown(0x5C,0x04,con>>8,con&0xff);
pTimeDelay->delay_ms(40);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
r = ADC[8]<<24|ADC[9]<<16|ADC[10]<<8|ADC[11];
}
}while(SAMPLE);
tts = (float)s/con;
ttr = (float)r/con;
ttd = (float)d/con;
a = (float)tts-pp1*(float)ttd;
b = (float)ttr-pp1*(float)ttd;
pTimeDelay->delay_ms(20);
}
if(b==0)
b=1.0;
t = a/b;
break;
case 3:// 返回能量
pInterface->USBDataDown(0x5C,0x04,con>>8,con&0xff);
pTimeDelay->delay_ms(20);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
r = ADC[8]<<24|ADC[9]<<16|ADC[10]<<8|ADC[11];
}
}while(SAMPLE);
pTimeDelay->delay_ms(10);
tts = (float)s/con;
ttd = (float)d/con;
ttr = (float)r/con;
t = (float)s/(float)con;
break;
case 4:// 返回 pp1 值
// 采集暗电流
pInterface->USBDataDown(0x5C,0x04,con>>8,con&0xff);
pTimeDelay->delay_ms(20);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
}
}while(SAMPLE);
pTimeDelay->delay_ms(10);
if(d==0)
d=1.0;
t = (float)s/d;
break;
case 5:// 返回 pp2 值
pInterface->USBDataDown(0x5C,0x04,con>>8,con&0xff);
pTimeDelay->delay_ms(20);
do
{
if(pInterface->DelUpLong(35))
{
SAMPLE = false;
s = ADC[0]<<24|ADC[1]<<16|ADC[2]<<8|ADC[3];
d = ADC[4]<<24|ADC[5]<<16|ADC[6]<<8|ADC[7];
r = ADC[8]<<24|ADC[9]<<16|ADC[10]<<8|ADC[11];
}
}while(SAMPLE);
a = (float)s-pp1*(float)d;
b = (float)r-pp1*(float)d;
pTimeDelay->delay_ms(10);
if(a==0)
a=1.0;
t = b/a;
}
return(t);
}
//---------------------------------------------------------------------------
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
MC = 1;
mIndex = 0;
strcpy(wfz25bj ," "); /*标志读入变量*/
strcpy(wfz25bj1,"WFZ-25AUVD"); /*光谱数据文件标志*/
strcpy(wfz25bj2,"WFZ-25AUVP"); /*测量参数文件标志*/
strcpy(wfz25bj3,"WFZ-25AUVC"); /*浓度参数文件标志*/
strcpy(wfz25bj4,"WFZ-25AUVB"); /*基线数据文件标志*/
strcpy(wfz25bj5,"WFZ-25AUVW"); /*波长校正文件标志*/
strcpy(wfz25bj6,"WFZ-25AUVZ"); /* pp1,pp2文件标志*/
MyDir = ExtractFilePath(Application->ExeName);// + ExtractFileName(Edit1->Text);
if ( LoadLibrary( "CH375DLL.DLL" ) == NULL ) // 加载DLL失败,可能未安装到系统中
{
Application->MessageBox("无法加载CH375的DLL", "information", MB_ICONSTOP | MB_OK );
}
else if ( CH375OpenDevice(mIndex) == INVALID_HANDLE_VALUE ) // 使用之前必须打开设备
{
Application->MessageBox("无法打开USB接口设备", "information", MB_ICONSTOP | MB_OK );
}
CH375SetBufUpload( 0, 512 ); // 设定内部缓冲上传模式
CH375SetTimeout( mIndex, 6000, 6000 ); // 设置USB数据读写的超时,超过4S未完成读写将强制返回,避免一直等待下去
CH375QueryBufUpload(mIndex);
pTimeDelay = new TimeDelay();
pInterface = new TInterface();
Form1->Scan_Time->ShortCut=NULL;
this->DoubleBuffered = true;
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
delete(pTimeDelay);
delete(pInterface);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MuSettingClick(TObject *Sender)
{//单击参数设置子菜单
SetData(); // 把数据传递给参数设置窗体
ChanShu->ShowModal(); // 显示参数设置窗体
if(ChanShu->bOK)
{
ExchangData(); // 从给参数设置窗体获取数据
Repaint(); // 主窗体刷新
parameter_set_ch(); // 调用改变系统函数
DrawBK(); // 画光谱背景
DrawQX(); // 画光谱图
}
StatusBar1->Panels->Items[0]->Text="请选择操作...";
Form1->StatusBar1->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MuOpenClick(TObject *Sender)
{// 打开光谱文件
if(OpenDialog1->Execute())
{ strcpy(file_name1,OpenDialog1->FileName.c_str());
if(OpenDialog1->FilterIndex==1)
{
file_load_a();
}
else if(OpenDialog1->FilterIndex==2)
{
file_load_option();
}
DrawBK();
DrawQX();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MuSaveClick(TObject *Sender)
{ // 光谱文件存盘
if(SaveDialog1->Execute())
{
if(SaveDialog1->FilterIndex==1)
{
strcpy(file_name1,SaveDialog1->FileName.c_str());
if(ptc.m2==0)
{
Application->MessageBox("没有光谱光谱数据!", "提示",MB_OK|MB_ICONWARNING);
}
else
file_save_a();
}
if(SaveDialog1->FilterIndex==2)
{
//strcpy(file_name1,SaveDialog1->FileName.c_str());
file_save_option();
}
if(SaveDialog1->FilterIndex==3)
{
file_save_ascii();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MuSaveAsClick(TObject *Sender)
{ //另存为
if(SaveDialog1->Execute())
{
Application->MessageBox(SaveDialog1->FileName.c_str(), "选择文件名",
MB_OKCANCEL+MB_DEFBUTTON1);
}
}
//---------------------------------------------------------------------------
void TForm1::file_save_a()
{ // 光谱数据存盘
int iFileHandle;
int i,n1,n2,ws,we;
//strcpy(ptc.samp,samp);
//strcpy(ptc.oper,oper);
strcat(file_name1, ".uvd");
if( (iFileHandle = FileCreate(file_name1))!=-1)
{
fnsplit(SaveDialog1->FileName.c_str(),0,0,filename,0);
strcat(filename, ".uvd");
FileWrite(iFileHandle,wfz25bj1,10);
FileWrite(iFileHandle,&ptc.m1,2);
FileWrite(iFileHandle,&ptc.m2,2);
FileWrite(iFileHandle,&ptc.m3,2);
FileWrite(iFileHandle,&ptc.m4,2);
FileWrite(iFileHandle,&ptc.wns,4);
FileWrite(iFileHandle,&ptc.wne,4);
FileWrite(iFileHandle,&ptc.tnh,4);
FileWrite(iFileHandle,&ptc.tnl,4);
FileWrite(iFileHandle,&ptc.lamp,2);
FileWrite(iFileHandle,&ptc.speed,2);
FileWrite(iFileHandle,&ptc.interval,2);
FileWrite(iFileHandle,&ptc.source,2);
FileWrite(iFileHandle,&ptc.slit,2);
FileWrite(iFileHandle,&ptc.vol,2);
FileWrite(iFileHandle,ptc.samp,50);
FileWrite(iFileHandle,ptc.oper,50);
FileWrite(iFileHandle,&ptc.dattim[1],2);
FileWrite(iFileHandle,&ptc.dattim[2],2);
FileWrite(iFileHandle,&ptc.dattim[3],2);
FileWrite(iFileHandle,&ptc.dattim[4],2);
FileWrite(iFileHandle,&ptc.dattim[5],2);
FileWrite(iFileHandle,&ptc.dattim[6],2);
FileWrite(iFileHandle,wfz25bj1,10);
if(ptc.m3!=3)
{
n1=0;
n2=(ptc.wne-ptc.wns)*(float)wnd0/(float)itl[ptc.interval];
for(i=n1;i<=n2;i++)
FileWrite(iFileHandle,&tc[i],4);
tnh=ptc.tnh;
tnl=ptc.tnl;
csd[0]=ptc.interval;
csd[1]=ptc.m1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -