📄 eeproom-writerdlg.cpp
字号:
ShowSystemTime(&bSystemTime);
bResult = SubmitCmd(hDevice,myRequest,&buffer,bufferLength);
return bResult;
}
BOOLEAN CEEPROOMWriterDlg::WriteCommandOthr(HANDLE hDevice,VENDOR_OR_CLASS_REQUEST_CONTROL *myRequest)
{
BOOLEAN bResult = FALSE;
ULONG p =0;
ULONG bufferLength = 8;
LONGLONG buffer = 0;
for(int i=0;i<3;i++)
{
p = Res[i];
ULONG temp=0;
if(i==0){
GetBcdCode(&temp,p);
buffer+=temp;
}
else
{
GetBcdCode(&temp,p);
buffer=(buffer<<16)+temp;
}
}
Res_save[2] = buffer;
bResult = SubmitCmd(hDevice,myRequest,&buffer,bufferLength);
return bResult;
}
void CEEPROOMWriterDlg::GetBcdCode(ULONG* num ,ULONG number)
{
ULONG bresvr;
if((number/100)!=0)
{
bresvr = number/100;
GetBcdCode(num,bresvr);
}
bresvr = number%100;
if(bresvr!=0)
{
*num=(*num<<8)+((bresvr/10)<<4)+(bresvr%10);
return;
}
return;
}
BOOLEAN CEEPROOMWriterDlg::SubmitCmd(HANDLE hDevice,VENDOR_OR_CLASS_REQUEST_CONTROL *myRequest,LONGLONG* buffer,ULONG bufferLength)
{
BOOLEAN bResult = FALSE;
int nBytes = 0;
bResult = DeviceIoControl (hDevice,
IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,
myRequest,
sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),
buffer,
bufferLength,
(unsigned long *)&nBytes,
NULL);
return bResult;
}
void CEEPROOMWriterDlg::OnBnClickedButtionOpenDev()
{
// TODO: Add your control notification handler code here
}
void CEEPROOMWriterDlg::OnBnClickedButtonShow()
{
LONGLONG buffer[3];
FILE *pSn = NULL;
ReadEEproom(buffer);
if((buffer[0] ==Res_save[0])&&(buffer[1] ==Res_save[1])&&(buffer[2] ==Res_save[2]))
{
MessageBox("下载成功",NULL,MB_OK);
///////////////////////////////////////////////////
CString PathString,SNFilePath;
GetFilePath(&PathString);
SNFilePath=PathString+CString("\\sn.txt");
pSn = fopen(SNFilePath,"wr");
//////////////////////////////////////////////////////
m_SN+=1;
if(pSn !=NULL){
fprintf(pSn,"%d %d %d",m_operatorcode,m_pccode,m_SN);
}
fclose(pSn);
UpdateData(FALSE);
}
else
{
MessageBox("下载没有完全成功,请重新下载",NULL,MB_OK);
}
// TODO: Add your control notification handler code here
}
void CEEPROOMWriterDlg::OnBnClickedButtonOpenDev()
{
// TODO: Add your control notification handler code here
HANDLE hDevice;
if(bOpenDriver(&hDevice)!=TRUE)
{
MessageBox("打开设备失败,请确认设备是否正确安装!!",NULL,MB_OK);
this->GetDlgItem(IDC_BUTTON_EEPROM_READ)->EnableWindow(FALSE);
}
else
{
this->GetDlgItem(IDC_BUTTON_EEPROM_READ)->EnableWindow(TRUE);
CloseHandle (hDevice);
}
}
void CEEPROOMWriterDlg::OnBnClickedCheckOpenShow()
{
// TODO: Add your control notification handler code here
WINDOWPLACEMENT wPlace;
this->GetWindowPlacement(&wPlace);
if(m_Show)
{
wPlace.rcNormalPosition.bottom -=m_HighthDe;
}
else{
wPlace.rcNormalPosition.bottom +=m_HighthDe;
}
m_Show = !m_Show;
this->SetWindowPlacement(&wPlace);
}
void CEEPROOMWriterDlg::ShowEEproomDataC0(LONGLONG * Data)
{
LONGLONG bTemp[2];
CString bString;
bTemp[1] = *Data;
bTemp[0] = (bTemp[1]&0xFF);
bString.Format("%x",bTemp[0]);
this->GetDlgItem(IDC_EDIT_SLOADER)->SetWindowText(bString);
bTemp[0] = ((bTemp[1]>>8)&0xFFFF);
bString.Format("%x",bTemp[0]);
this->GetDlgItem(IDC_EDIT_SVID)->SetWindowText(bString);
bTemp[0] = ((bTemp[1]>>24)&0xFFFF);
bString.Format("%x",bTemp[0]);
this->GetDlgItem(IDC_EDIT_SPID)->SetWindowText(bString);
bTemp[0] = ((bTemp[1]>>40)&0xFFFF);
bString.Format("%x",bTemp[0]);
this->GetDlgItem(IDC_EDIT_SDID)->SetWindowText(bString);
}
void CEEPROOMWriterDlg::ShowEEproomDataDat(LONGLONG * Data)
{
LONGLONG bTemp[2];
CString bString;
SYSTEMTIME SystemTime;
bTemp[1] = *Data;
SystemTime.wYear = (WORD)(bTemp[1]&0xFFFF);
SystemTime.wMonth = (WORD)((bTemp[1]>>16)&0xFF);
SystemTime.wDay = (WORD)((bTemp[1]>>24)&0xFF);
SystemTime.wHour = (WORD)((bTemp[1]>>32)&0xFF);
SystemTime.wMinute = (WORD)((bTemp[1]>>40)&0xFF);
SystemTime.wSecond = (WORD)((bTemp[1]>>48)&0xFF);
ShowSystemTimeFromEEproom(&SystemTime);
}
void CEEPROOMWriterDlg::ShowEEproomDataOthr(LONGLONG * Data)
{
LONGLONG bTemp[2];
CString bString;
bTemp[1] = *Data;
bTemp[0] = (bTemp[1]&0xFFFF);
//GetIntFromBcdCode(&bTemp[3],bTemp[0]);
bString.Format("%x",bTemp[0]);
this->GetDlgItem(IDC_EDIT_SOCODE)->SetWindowText(bString);
bTemp[0] = ((bTemp[1]>>16)&0xFFFF);
//GetIntFromBcdCode(&bTemp[3],bTemp[0]);
bString.Format("%x",bTemp[0]);
this->GetDlgItem(IDC_EDIT_SPCCODE)->SetWindowText(bString);
bTemp[0] = ((bTemp[1]>>32)&0xFFFFFFFF);
bString.Format("%x",bTemp[0]);
this->GetDlgItem(IDC_EDIT_SSN)->SetWindowText(bString);
//GetIntFromBcdCode(&bTemp[3],bTemp[0]);
}
void CEEPROOMWriterDlg::ShowSystemTimeFromEEproom(SYSTEMTIME *pSystemTime)
{
CString bString;
bString.Format("%d",pSystemTime->wYear);
this->GetDlgItem(IDC_EDIT_SYEAR)->SetWindowText(bString);
bString.Format("%d/%d",pSystemTime->wMonth,pSystemTime->wDay);
this->GetDlgItem(IDC_EDIT_SMD)->SetWindowText(bString);
bString.Format("%d/%d",pSystemTime->wHour,pSystemTime->wMinute);
this->GetDlgItem(IDC_EDIT_SHM)->SetWindowText(bString);
bString.Format("%d",pSystemTime->wSecond);
this->GetDlgItem(IDC_EDIT_SSEC)->SetWindowText(bString);
}
void CEEPROOMWriterDlg::ShowSystemTime(SYSTEMTIME *pSystemTime)
{
CString bString;
bString.Format("%d",pSystemTime->wYear);
this->GetDlgItem(IDC_EDIT_YEAR_SET)->SetWindowText(bString);
this->GetDlgItem(IDC_EDIT_YEAR_SET)->EnableWindow(FALSE);
bString.Format("%d/%d",pSystemTime->wMonth,pSystemTime->wDay);
this->GetDlgItem(IDC_EDIT_MD_SET)->SetWindowText(bString);
this->GetDlgItem(IDC_EDIT_MD_SET)->EnableWindow(FALSE);
bString.Format("%d/%d",pSystemTime->wHour,pSystemTime->wMinute);
this->GetDlgItem(IDC_EDIT_HM_SET)->SetWindowText(bString);
this->GetDlgItem(IDC_EDIT_HM_SET)->EnableWindow(FALSE);
bString.Format("%d",pSystemTime->wSecond);
this->GetDlgItem(IDC_EDIT_SEC_SET)->SetWindowText(bString);
this->GetDlgItem(IDC_EDIT_SEC_SET)->EnableWindow(FALSE);
}
void CEEPROOMWriterDlg::OnBnClickedButtonRepair()
{
// TODO: Add your control notification handler code here
m_RepairFlag = !m_RepairFlag;
this->GetDlgItem(IDC_EDIT_OCODE_SET)->EnableWindow(m_RepairFlag);
this->GetDlgItem(IDC_EDIT_PCCODE_SET)->EnableWindow(m_RepairFlag);
this->GetDlgItem(IDC_EDIT_SN_SET)->EnableWindow(m_RepairFlag);
if(m_RepairFlag)
{
this->GetDlgItem(IDC_BUTTON_REPAIR)->SetWindowText("禁止修改");
}
else
{
CString PathString,SNFilePath;
FILE *pSn;
this->GetDlgItem(IDC_BUTTON_REPAIR)->SetWindowText("修改");
UpdateData(TRUE);
GetFilePath(&PathString);
SNFilePath=PathString+CString("\\sn.txt");
pSn = fopen(SNFilePath,"wr");
if(pSn !=NULL){
fprintf(pSn,"%d %d %d",m_operatorcode,m_pccode,m_SN);
}
fclose(pSn);
}
}
void CEEPROOMWriterDlg::OnEnChangeEdit9()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CEEPROOMWriterDlg::OnBnClickedButtonAdvance()
{
// TODO: Add your control notification handler code here
if(m_Advance)
{
CHAR wintext[10],length;
CString PathString,Cmd1FilePath;
BOOLEAN bResult=FALSE;
FILE *pSn = NULL;
length = this->GetDlgItem(IDC_EDIT_PID_SET)->GetWindowText(wintext,5);
bResult=GetIntFromChar(wintext,length,&m_Pid);
if(!bResult)
return;
this->GetDlgItem(IDC_EDIT_PID_SET)->EnableWindow(FALSE);
length = this->GetDlgItem(IDC_EDIT_DID_SET)->GetWindowText(wintext,5);
bResult=GetIntFromChar(wintext,length,&m_Did);
if(!bResult)
return;
this->GetDlgItem(IDC_EDIT_DID_SET)->EnableWindow(FALSE);
GetFilePath(&PathString);
Cmd1FilePath = PathString+CString("\\Cmd1.txt");
pSn = fopen(Cmd1FilePath,"wr");
if(pSn !=NULL){
fprintf(pSn,"%d %d",m_Pid,m_Did);
}
fclose(pSn);
this->GetDlgItem(IDC_STATIC_PID)->ShowWindow(FALSE);
this->GetDlgItem(IDC_STATIC_DID)->ShowWindow(FALSE);
this->GetDlgItem(IDC_BUTTON_ADVANCE)->SetWindowText("高级");
}
else
{
this->GetDlgItem(IDC_EDIT_PID_SET)->EnableWindow(TRUE);
this->GetDlgItem(IDC_EDIT_DID_SET)->EnableWindow(TRUE);
this->GetDlgItem(IDC_STATIC_PID)->ShowWindow(TRUE);
this->GetDlgItem(IDC_STATIC_DID)->ShowWindow(TRUE);
this->GetDlgItem(IDC_BUTTON_ADVANCE)->SetWindowText("保存");
}
m_Advance=!m_Advance;
}
BOOLEAN CEEPROOMWriterDlg::GetIntFromChar(CHAR *string,int length,ULONG *number)
{
*number = 0;
for(int i=0;i<length;i++)
{
if(string[i]>='0'&&string[i]<='9')
{
*number = (*number)*16+(string[i]-'0');
}
else if(string[i]>='a'&&string[i]<='f')
{
*number = (*number)*16+(string[i]-'a')+10;
}
else if(string[i]>='A'&&string[i]<='F')
{
*number = (*number)*16+(string[i]-'A')+10;
}
else
{
MessageBox("请确认输入的值是为十六进制数!!",MB_OK);
return FALSE;
}
}
return TRUE;
}
void CEEPROOMWriterDlg::ReadEEproom(LONGLONG *buffer_save)
{
HANDLE hDevice = NULL;
BOOLEAN bResult = FALSE;
VENDOR_OR_CLASS_REQUEST_CONTROL myRequest;
LONGLONG buffer;
ULONG bufferLength = 8;
if(m_DownLoading)
return;
if(bOpenDriver(&hDevice)!=TRUE)
{
MessageBox("打开设备失败,请确认设备是否正确安装!!",NULL,MB_OK);
return;
}
myRequest.request = (UCHAR)0xDB;
myRequest.direction = 0x00;
myRequest.value = 0x00;
myRequest.index = (WORD) 0x00;
myRequest.direction = 1;
myRequest.requestType = 2;
myRequest.recepient = 0;
bResult = SubmitCmd(hDevice,&myRequest,&buffer,bufferLength);
buffer_save[0] = buffer;
if(!bResult)
{
MessageBox("读取EEproom的第一个内存块失败!!",NULL,MB_OK);
}
else{
//ShowEEproomData(Res_save);
ShowEEproomDataC0(&buffer);
}
myRequest.value = 0x01;
bResult = SubmitCmd(hDevice,&myRequest,&buffer,bufferLength);
buffer_save[1] = buffer;
if(!bResult)
{
MessageBox("读取EEproom的第二个内存块失败!!",NULL,MB_OK);
}
else{
ShowEEproomDataDat(&buffer);
}
myRequest.value = 0x02;
bResult = SubmitCmd(hDevice,&myRequest,&buffer,bufferLength);
buffer_save[2] = buffer;
if(!bResult)
{
MessageBox("读取EEproom的第三个内存块失败!!",NULL,MB_OK);
}
else{
ShowEEproomDataOthr(&buffer);
}
}
void CEEPROOMWriterDlg::OnBnClickedButtonEepromRead()
{
// TODO: Add your control notification handler code here
LONGLONG buffer[3];
ReadEEproom(buffer);
}
void CEEPROOMWriterDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -