📄 iniparam.cpp
字号:
#include "stdafx.h"
#include "public.h"
BOOL IsStartTest;
BOOL IsSetSysParam;
//6130
int OutData;
int FaultCode; //故障代码
int mcou;
UINT xx[154];//40 wxl
float yy[154];//40 wxl
int AllColor;
CString AllText;
int count;
CARDPARAM SysParam;
CONTROLPARAM ControlParam;
SAMPLEPARAM SampleParam;
CArray<SPEEDSAMPLE,SPEEDSAMPLE&> array_searchcurve;
int stp=1;
int znum[10];
int zstr[10];
int secend;
int minute;
int hour;
CMutex g_mutex(FALSE,"mutex1");
CMutex ad_mutex(FALSE,"mutex2");
CMutex c_mutex(FALSE,"mutex3");
CMutex err_mutex(FALSE,"mutex5");
CMutex out_mutex(FALSE,"mutex4");; //fAULTCODE锁
char exepath[180];
CString GLastFname;
void iniparam(void)
{
AllColor=RGB(255,0,0);
AllText="(r/min) ";
IsStartTest=FALSE;
// IsStartSample=FALSE;
ControlParam.RunDataArray.str="";
SampleParam.speed_meas_t=0.;
SampleParam.speed_meas_v=0.;
// SampleParam.avg_meas_v=0.;
ControlParam.run_time=0;
//初始化I/O板HY-6130
// OutData=0xf380; // 1111-0011-1000-0000
OutData=0x0000; // 1111-0011-1000-0000
sleep(3000);
//8255初始化
_outp(SysParam.baseco+5,3); //选择8255控制口
_outp(SysParam.baseco+0,0x82); //A-输出,B-输入,C-输出 1000-0010
//8253初始化
_outp(SysParam.baseco+5,2); //选择8255-C口
_outp(SysParam.baseco+0,0); //输出门控状态:00000000(停所有定时/计数器)
_outp(SysParam.baseco+5,3);
_outp(SysParam.baseco+2,0x34); //A0-set mode2 0011-0100
_outp(SysParam.baseco+2,0x74); //A1-set mode2 0111-0100
_outp(SysParam.baseco+2,0xb4); //A2-set mode2 1011-0100
_outp(SysParam.baseco+3,0x34); //B0-set mode2 0011-0100
_outp(SysParam.baseco+3,0x76); //B1 mode2 0111-0100
_outp(SysParam.baseco+3,0xb4); //B2 mode2 1011-0100
_outp(SysParam.baseco+4,0x34); //C0 mode2 0011-0100
_outp(SysParam.baseco+4,0x74); //C1-set mode2 0111-0100
_outp(SysParam.baseco+4,0xb4); //C2-set mode2 1011-0100
//8259初始化
_outp(SysParam.baseco+5,0); //选icw1的地址
_outp(SysParam.baseco+1,0x13); //写8259控制字icw1
_outp(SysParam.baseco+5,1); //选择icw2,icw4,ocw1地址
_outp(SysParam.baseco+1,0); //将icw2设定为0
_outp(SysParam.baseco+1,1); //写8259控制字icw3
_outp(SysParam.baseco+1,0xff); //写8259控制字ocw1
// 8253-A.0:250 2M/250=8KHz
_outp(SysParam.baseco+5,0);
_outp(SysParam.baseco+2,0xfa);//送低8位 //1111-1000
_outp(SysParam.baseco+2,0);//送高8位
// 8253-A.1:66535(-计脉冲)
_outp(SysParam.baseco+5,1);
_outp(SysParam.baseco+2,0xff);
_outp(SysParam.baseco+2,0xff);
// 8253-C.1:66535(计时器)
_outp(SysParam.baseco+5,1);
_outp(SysParam.baseco+4,0xff);
_outp(SysParam.baseco+4,0xff);
// 8253-C.2:66535(计时器)
_outp(SysParam.baseco+5,2);
_outp(SysParam.baseco+4,0xff);
_outp(SysParam.baseco+4,0xff);
SampleParam.old_count_t=Get6220Counter(0);
SampleParam.old_count_l=Get6220Counter(7);
//启动8253-A.1 8253-C.2计数
_outp(SysParam.baseco+5,2); //选择8255-C口(A1A0=00)
_outp(SysParam.baseco+0,0x81); //1000-0001
//输出门控状态:c2|c1|c0|b2|b1|b0|a2|a1
return;
}
char *ftoa(double value,int nint, int ndec, char *string,BOOL space)
{
if(value<0)
value=-value;
unsigned long lvalue;
for(int i=0;i<ndec;i++)
value*=10;
lvalue=(unsigned long)value;
lvalue+=(unsigned long)((value-lvalue)/0.5);
ultoa(lvalue,string,10);
char * p=string;
int nlen=strlen(string);
while(nlen<=ndec)
{
for(i=0;i<=nlen;i++)
p[nlen+1-i]=p[nlen-i];
p[0]='0';
nlen++;
}
while(nlen<ndec+nint)
{
for(i=0;i<=nlen;i++)
p[nlen+1-i]=p[nlen-i];
p[0]=space?' ':'0';
nlen++;
}
while(nlen>ndec+nint)
{
for(i=0;i<=nlen;i++)
p[i]=p[i+1];
nlen--;
}
if(ndec==0)
return string;
for(i=0;i<=ndec;i++)
p[nlen+1-i]=p[nlen-i];
p[nlen-ndec]='.';
return string;
}
void sleep(int millsecond)
{
LARGE_INTEGER lFrequency,lPerformanceCount1,lPerformanceCount2;
QueryPerformanceFrequency(&lFrequency);//获取计数器计数频率
LONGLONG LCounter=millsecond*lFrequency.QuadPart/1000;
QueryPerformanceCounter(&lPerformanceCount1);//读取当前计数器中的计数值
do
{
QueryPerformanceCounter(&lPerformanceCount2);
}while(lPerformanceCount2.QuadPart-lPerformanceCount1.QuadPart<LCounter);
}
int GetRegisted(CWnd *parent)
{
FILE *pFile=fopen("Speed.dll","r");
if(pFile==NULL)
{
parent->MessageBox("找不到文件Speed.DLL,退出系统");
exit(0);
}
char dirpath[180];
GetSystemDirectory(dirpath,sizeof(dirpath)-15);
strcat(dirpath,"\\Run.inf");
FILE *pFile1=fopen(dirpath,"r");
int RegFlag=0;
char str1[8];
if(pFile1==NULL)
{
pFile1=fopen(dirpath,"w+");
for(int i=0;i<250;i++)
{
fread(str1,sizeof(char),8,pFile);
fwrite(str1,sizeof(char),8,pFile1);
}
}
fclose(pFile);
CTime time1,time2;
rewind(pFile1);
fread(&RegFlag,sizeof(int),1,pFile1);
fread(str1,sizeof(char),8,pFile1);
fread(str1,sizeof(char),8,pFile1);
fread(&time1,sizeof(CTime),1,pFile1);
fread(&time2,sizeof(CTime),1,pFile1);
fclose(pFile1);
CTime CurrentTime;
CurrentTime=CTime::GetCurrentTime();
switch(RegFlag)
{
case 0:
if(CurrentTime>=time1)
{
pFile1=fopen(dirpath,"r+");
RegFlag=1;
fwrite(&RegFlag,sizeof(int),1,pFile1);
fclose(pFile1);
return 1;
}
else
return 0;
case 1: return 1;
case 2: return 2;
case 3:
if(CurrentTime>=time2)
{
pFile1=fopen(dirpath,"r+");
RegFlag=2;
fwrite(&RegFlag,sizeof(int),1,pFile1);
fclose(pFile1);
return 2;
}
else
return 0;
case 4: return 0;
default: return 0;
}
}
void ftoat(double value)
{
if(value<0)
value=-value;
minute=int(value/60)%60;
hour=int(value/3600);
secend=int(value-60*(minute+60*hour));
}
char *ftoat1(int value,int nint, char *string,BOOL space)
{
ultoa(value,string,10);//整型转化为字符型
char * p=string;
int nlen=strlen(string);
while(nlen<nint)
{
for(int i=0;i<=nlen;i++)
p[nlen+1-i]=p[nlen-i];
p[0]=space?' ':'0';
nlen++;
}
while(nlen>nint)
{
for(int i=0;i<=nlen;i++)
p[i]=p[i+1];
nlen--;
}
return string;
}
CString TimetoStr(double time)
{
int hour, mi, sec;
hour = int(time)/3600;
time = time - hour*3600;
mi = int(time)/60;
sec = int(time) - mi*60;
CString str;
str.Format("%4d:%2d:%2d",hour, mi, sec);
return str;
}
void OutAlarmLampOn(BOOL ison)
{
out_mutex.Lock();
int ch;
ch=0x0400;//
if(ison)
OutData|=ch;
else
OutData&=~(ch);//
_outpw(SysParam.baseio+2,OutData);
out_mutex.Unlock();
}
void OutMainOn(BOOL ison)
{
out_mutex.Lock();
int ch;
ch=0x0080;//
if(ison)
OutData|=ch;
else
OutData&=~(ch);//
_outpw(SysParam.baseio+2,OutData);
out_mutex.Unlock();
}
void OutAllDown()
{
out_mutex.Lock();
OutData = 0x0000;
_outpw(SysParam.baseio+2,OutData);
out_mutex.Unlock();
}
void IniSysData(void)
{
//SysParam.basead=0x300;
SysParam.baseco=0x290;
SysParam.basein=0X288;//6110
SysParam.baseio=0x280; //6160
}
void ReadSysData()
{
char xfname[256];
GetSystemDirectory(xfname,255);
strcat(xfname,"\\Speed.dat");
CFile xzfile;
if(xzfile.Open(xfname,CFile::modeRead)){
CArchive ar(&xzfile,CArchive::load);
SerializeSysData(ar);
}
else{
IniSysData();
CFile wfile;
if(wfile.Open(xfname,CFile::modeCreate|CFile::modeWrite)){
CArchive ar(&wfile,CArchive::store);
SerializeSysData(ar);
}
}
}
void WriteSysData()
{
char xfname[256];
GetSystemDirectory(xfname,255);
strcat(xfname,"\\Speed.dat");
CFile wfile;
if(wfile.Open(xfname,CFile::modeCreate|CFile::modeWrite)){
CArchive ar(&wfile,CArchive::store);
SerializeSysData(ar);
}
}
void SerializeSysData(CArchive& ar)
{
if (ar.IsStoring())
{
ar<<SysParam;
}
else
{
ar>>SysParam;
}
}
long Get6220Counter(int counter)
{
long data;
int basen;//第几块8253
int controldata;//计数器的控制字
int timern;//第几个计数器
switch(counter)
{
case 0:
basen = 2; controldata = 0x40; timern = 1;
break;
case 1:
basen = 2; controldata = 0x80; timern = 2;
break;
case 2:
basen = 3; controldata = 0x00; timern = 0;
break;
case 3:
basen = 3; controldata = 0x40; timern = 1;
break;
case 4:
basen = 3; controldata = 0x80; timern = 2;
break;
case 5:
basen = 4; controldata = 0x00; timern = 0;
break;
case 6:
basen = 4; controldata = 0x40; timern = 1;
break;
case 7:
basen = 4; controldata = 0x80; timern = 2;
break;
default:
break;
}
c_mutex.Lock();
_outp(SysParam.baseco+5,3);
_outp(SysParam.baseco+basen,controldata);
_outp(SysParam.baseco+5,timern);
data = _inp(SysParam.baseco+basen)|(_inp(SysParam.baseco+basen)<<8);//时间
c_mutex.Unlock();
return data;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -