📄 pci_6120dlg.cpp
字号:
void CPCI_6120Dlg::OnAIReadVScan()
{
i16 status= 0;
// i16 deviceNumber= 0;
// i16 numChans = 4;
f64 reading[4] = {0};
CString str;
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
/*
i16 chanVector[4]= {0,1,2,3};
i16 gainVector[4]= {0};
gainVector[0]= GetDlgItemInt(IDC_COMBO_GAIN1);
gainVector[1]= GetDlgItemInt(IDC_COMBO_GAIN2);
gainVector[2]= GetDlgItemInt(IDC_COMBO_GAIN3);
gainVector[3]= GetDlgItemInt(IDC_COMBO_GAIN4);
//select chan
status = SCAN_Setup (deviceNumber, numChans, chanVector, gainVector);
if(status<0)
{
str.Format("SCAN_Setup error: %d", status);
AfxMessageBox(str);
return;
}
*/
//read AI_scan select chan
status = AI_VRead_Scan (deviceNumber, reading);
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "AI_VRead_Scan", iIgnoreWarning);
//chan0
str.Format("%lf", reading[0]);
SetDlgItemText(IDC_EDIT_CHAN1, str);
//chan1
str.Format("%lf", reading[1]);
SetDlgItemText(IDC_EDIT_CHAN2, str);
//chan2
str.Format("%lf", reading[2]);
SetDlgItemText(IDC_EDIT_CHAN3, str);
//chan3
str.Format("%lf", reading[3]);
SetDlgItemText(IDC_EDIT_CHAN4, str);
}
/*
void CPCI_6120Dlg::OnDIGGrpConfig()
{
i16 status= 0;
// i16 deviceNumber= 0;
i16 numChans = 4;
CString str;
i16 group=1; //group to configure, e.g:1, 2
i16 groupSize= 0;
//0: Unassign any ports previously assigned to group.
//1: One port assigned (8-bit group) to group.
//2: Two ports assigned (16-bit group) to group.
//4: Four ports assigned (32-bit group) to group.
i16 port= 1; //port 0 assigns group port A
//groupSize = 1 port = 0 assigns port 0 (A).
//port = 1 assigns port 1 (B).
//port = 2 assigns port 2 (C).
//port = 3 assigns port 3 (D).
//groupSize = 2 port = 0 assigns ports 0 and 1 (A and B).
//port = 2 assigns ports 2 and 3 (C and D).
//groupSize = 4 port = 0 assigns ports 0, 1, 2, and 3 (A,B,C, and D).
i16 dir= 0; //input
//dir indicates the direction, input, or output for which the group is to be configured.
//0: port is configured as an input port (default).
//1: port is configured as an output port.
//3: port is configured as an input port with request-edge latching disabled.
//4: port is configured as an output port with request-edge latching enabled.
group= GetDlgItemInt(IDC_COMBO_group);
groupSize= GetDlgItemInt(IDC_COMBO_groupSize);
port= GetDlgItemInt(IDC_COMBO_port);
dir= GetDlgItemInt(IDC_COMBO_dir);
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
status = DIG_Grp_Config (deviceNumber, group, groupSize, port, dir);
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "DIG_Grp_Config", iIgnoreWarning);
}*/
void CPCI_6120Dlg::OnAutoUpdate()
{
if(IsDlgButtonChecked(IDC_AutoUpdate)) //MessageBox("check");
{
SetTimer(1,1, NULL);
}
}
void CPCI_6120Dlg::OnTimer(UINT nIDEvent)
{
i16 status= 0;
// CString str;
i16 port=1;
i16 line=0;
i16 state= 0;
//0: The specified digital line is at a digital logic low.
//1: The specified digital line is at a digital logic high.
int i= 0;
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
port= GetDlgItemInt(IDC_COMBO_port);
if(port==0)
{
for(i=0; i<8; i++)
{
line= i;
//port 0;
port= 0;
status = DIG_In_Line (deviceNumber, port, line, &state);
if(state==1) ((CButton*)GetDlgItem(IDC_RADIO1+i))->SetCheck(1);
else ((CButton*)GetDlgItem(IDC_RADIO1+i))->SetCheck(0);
if(status<0)
{ KillTimer(1); ((CButton*)GetDlgItem(IDC_AutoUpdate))->SetCheck(0); break;}
}
}else{
for(i=0; i<8; i++)
{
//port 1;
port= 1;
status = DIG_In_Line (deviceNumber, port, line, &state);
if(state==1) ((CButton*)GetDlgItem(IDC_RADIO10+i))->SetCheck(1);
else ((CButton*)GetDlgItem(IDC_RADIO10+i))->SetCheck(0);
if(status<0)
{ KillTimer(1); ((CButton*)GetDlgItem(IDC_AutoUpdate))->SetCheck(0); break;}
}
}
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "DIG_In_Line", iIgnoreWarning);
CDialog::OnTimer(nIDEvent);
}
void CPCI_6120Dlg::OnReadPort()
{
i16 status= 0;
// CString str;
i16 port=0;
i16 line=0;
i16 state= 0;
//0: The specified digital line is at a digital logic low.
//1: The specified digital line is at a digital logic high.
int i= 0;
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
port= GetDlgItemInt(IDC_COMBO_port);
if(port==0)
{
for(i=0; i<8; i++)
{
line= i;
//port 0;
//port= 0;
status = DIG_In_Line (deviceNumber, port, line, &state);
if(state==1) ((CButton*)GetDlgItem(IDC_RADIO1+i))->SetCheck(1);
else ((CButton*)GetDlgItem(IDC_RADIO1+i))->SetCheck(0);
if(status<0) { break;}
}
}
else
{
for(i=0; i<8; i++)
{
//port 1;
//port= 1;
status = DIG_In_Line (deviceNumber, port, line, &state);
if(state==1) ((CButton*)GetDlgItem(IDC_RADIO10+i))->SetCheck(1);
else ((CButton*)GetDlgItem(IDC_RADIO10+i))->SetCheck(0);
if(status<0) { break;}
}
}
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "DIG_In_Line", iIgnoreWarning);
}
void CPCI_6120Dlg::OnRead()
{
i16 status= 0;
CString str;
i16 port=0;
i32 pattern=0;
//i16 state= 0;
//0: The specified digital line is at a digital logic low.
//1: The specified digital line is at a digital logic high.
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
port= GetDlgItemInt(IDC_COMBO_port);
status = DIG_In_Prt (deviceNumber, port, &pattern);
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "DIG_In_Line", iIgnoreWarning);
str.Format("0x%x",pattern);
if(port==0)
SetDlgItemText(IDC_P0, str);
else
SetDlgItemText(IDC_P1, str);
}
void CPCI_6120Dlg::OnNext()
{
CNextDlg dlg;
dlg.DoModal();
}
void CPCI_6120Dlg::OnDIGPrtConfig()
{
i16 status= 0;
// i16 deviceNumber= 0;
CString str;
//Input
// deviceNumber i16 assigned by Measurement & Automation Explorer
// port i16 digital I/O port number of the port to write to
// mode i16 handshake mode the port uses
// dir i16 direction, input, or output
i16 port= 0; //port 0 ,1
i16 mode= 0; //0, no-handshake, 1, handshake
i16 dir= 0; //0, input; 1, output
//dir indicates the direction, input or output, or the output type to which the port is to be configured.
//0: port is configured as an input port (default).
//1: Port is configured as a standard output port.
//3: port is configured as an input port with request-edge latching disabled.
//4: port is configured as an output port with request-edge latching enabled.
port= GetDlgItemInt(IDC_COMBO_port);
mode= GetDlgItemInt(IDC_COMBO_mode2);
dir= GetDlgItemInt(IDC_COMBO_dir);
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
status = DIG_Prt_Config (deviceNumber, port, mode, dir);
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "DIG_Prt_Config", iIgnoreWarning);
}
void CPCI_6120Dlg::OnButtonReadVoltage2()
{
///////////////////////////var. define/////////////////////
i16 status= 0;
// i16 deviceNumber= 0;
i16 chan= 0;
i16 gain= 0;
f64 voltage= 0;
CString str;
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
chan= GetDlgItemInt(IDC_COMBO_CHAN);
gain= GetDlgItemInt(IDC_COMBO_GAIN);
//-2 (for gain of 0.2)
//-1 (for gain of 0.5) 1, 2, 5, 10, 20, 50
////////////////////////////updateIC//////////////////////
/* if( LoadDll("SPI.dll")<0) return;
if(!IsPowerOn)
{
PowerOn();
IsPowerOn= true;
}
unsigned int segment=0;
segment= GetDlgItemInt(IDC_EDIT_SEGMENT);
UpdateIC(segment);*/
PowerOn();
IsPowerOn= true;
unsigned int segment=0;
segment= GetDlgItemInt(IDC_EDIT_SEGMENT);
UpdateIC(segment);
///////////////////////////read voltage//////////////////
status = AI_VRead (deviceNumber, chan, gain, &voltage);
/* if(status<0)
{
str.Format("Read voltage error: %d", status);
AfxMessageBox(str);
return;
}*/
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "AI_VRead", iIgnoreWarning);
str.Format("%lf", voltage);
SetDlgItemText(IDC_EDIT_VOLTAGE, str);
}
int CPCI_6120Dlg::LoadDll(char *dllPathName)
{
/* m_hDll= LoadLibrary(dllPathName);
if(m_hDll==NULL) {MessageBox("Load \"SPI.dll\" fail"); return -1;}
PowerOn=(VOID_DLLFUNC)GetProcAddress(m_hDll, "PowerOn");
if(PowerOn==NULL) {AfxMessageBox("Get \"PowerOn\" function fail!"); return -1;}
UpdateIC=(VOID_DLLFUNC_UINT)GetProcAddress(m_hDll, "UpdateIC");
if(UpdateIC==NULL) {AfxMessageBox("Get \"UpdateIC\" function fail!"); return -1;}
PowerOff=(VOID_DLLFUNC)GetProcAddress(m_hDll, "PowerOff");
if(PowerOff==NULL) {AfxMessageBox("Get dll function fail!"); return -1;}
*/
return 0;
}
void CPCI_6120Dlg::OnAIReadScan()
{
i16 status= 0;
// i16 deviceNumber= 0;
i16 reading[4] = {0};
CString str;
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
status = AI_Read_Scan (deviceNumber, reading);
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "AI_Read_Scan", iIgnoreWarning);
str.Format("%d", reading[0]);
SetDlgItemText(IDC_EDIT_CHAN1, str);
//chan1
str.Format("%d", reading[1]);
SetDlgItemText(IDC_EDIT_CHAN2, str);
//chan2
str.Format("%d", reading[2]);
SetDlgItemText(IDC_EDIT_CHAN3, str);
//chan3
str.Format("%d", reading[3]);
SetDlgItemText(IDC_EDIT_CHAN4, str);
}
void CPCI_6120Dlg::OnAIVScale()
{
i16 status= 0;
// i16 deviceNumber= 0;
i16 chan= 0;
i16 gain= 0;
f64 gainAdjust= 1;
f64 offset= 0;
f64 voltage= 0;
i16 reading[4]= {0};
CString str;
deviceNumber= GetDlgItemInt(IDC_COMBO_DEVICE);
//chan= GetDlgItemInt(IDC_COMBO_CHAN);
gain= GetDlgItemInt(IDC_COMBO_GAIN);
//chan0
chan= 0;
reading[0]= GetDlgItemInt(IDC_EDIT_CHAN1);
status = AI_VScale (deviceNumber, chan, gain, gainAdjust, offset, reading[0], &voltage);
str.Format("%lf", voltage);
SetDlgItemText(IDC_EDIT_CHAN1, str);
//chan1
chan= 1;
reading[1]= GetDlgItemInt(IDC_EDIT_CHAN2);
status = AI_VScale (deviceNumber, chan, gain, gainAdjust, offset, reading[1], &voltage);
str.Format("%lf", voltage);
SetDlgItemText(IDC_EDIT_CHAN2, str);
//chan2
chan= 2;
reading[2]= GetDlgItemInt(IDC_EDIT_CHAN3);
status = AI_VScale (deviceNumber, chan, gain, gainAdjust, offset, reading[2], &voltage);
str.Format("%lf", voltage);
SetDlgItemText(IDC_EDIT_CHAN3, str);
//chan3
chan= 3;
reading[3]= GetDlgItemInt(IDC_EDIT_CHAN4);
status = AI_VScale (deviceNumber, chan, gain, gainAdjust, offset, reading[3], &voltage);
str.Format("%lf", voltage);
SetDlgItemText(IDC_EDIT_CHAN4, str);
i16 iIgnoreWarning = 0;
i16 iRetVal = NIDAQErrorHandler(status, "AI_VScale", iIgnoreWarning);
}
void CPCI_6120Dlg::OnSelchangeCOMBOinputRange()
{
//i16 range= GetDlgItemInt(IDC_COMBO_inputRange);
i16 range;
i16 gain;
CString tmp; //GetDlgItemText(IDC_COMBO_inputRange, tmp);MessageBox(tmp);
CComboBox* pComBox= (CComboBox*)GetDlgItem(IDC_COMBO_inputRange);
pComBox->GetLBText(pComBox->GetCurSel(), tmp);//MessageBox(tmp);
range= atoi(tmp);
switch(range)
{
case 42://42 v
gain= -2;//gain=0.2
break;
case 20://20 v
gain= -1;//gain=0.5
break;
case 10://10 v
gain= 1;
break;
case 5: //5 v
gain= 2;
break;
case 2: //2 v
gain= 5;
break;
case 1: // 1 v
gain= 10;
break;
case -1://0.5 v
gain= 20;
break;
case -2://0.2 v
gain= 50;
break;
default:
gain= 1;
}
SetDlgItemInt(IDC_COMBO_GAIN1, gain);
SetDlgItemInt(IDC_COMBO_GAIN2, gain);
SetDlgItemInt(IDC_COMBO_GAIN3, gain);
SetDlgItemInt(IDC_COMBO_GAIN4, gain);
pComBox= NULL;
delete pComBox;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -