//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
AnsiString strls;
int status;
char lll[100];
char *jhls;
int jihao;
int beepforxms;
int unbeepforxms;
int times;
HANDLE (__stdcall *PortOpen)(int comport);
bool (__stdcall *PortClose)(HANDLE ComportHandle);
void (__stdcall *Delay_ms)(DWORD xms);
int (__stdcall *CloseBeep)(HANDLE ComportHandle,int Jihao);
AnsiString FileName=ExtractFilePath(Application->ExeName);
if(FileName.SubString(FileName.Length(),1) != "\\")
{
FileName += "\\";
}
FileName += "sycomdll.dll";
if(!FileExists(FileName))
{
ShowMessage("无法在当前目录下找到sycomdll.dll文件!");
return;
}
//to get function pointers
HINSTANCE hDll;
hDll=LoadLibrary(FileName.c_str());
PortOpen = (HANDLE (__stdcall *)(int comport))GetProcAddress(hDll,"PortOpen");
PortClose = (bool (__stdcall *)(HANDLE ComportHandle))GetProcAddress(hDll,"PortClose");
Delay_ms = (void (__stdcall *)(DWORD xms))GetProcAddress(hDll,"Delay_ms");
CloseBeep = (int (__stdcall *)(HANDLE ComportHandle,int Jihao))GetProcAddress(hDll,"CloseBeep");
if(commindex->Items->Count<1)
{
Application->MessageBox("无法找到可用的串口,请释放其他软件对串口的占用再重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
if(CheckBox3->Checked)
{
jihao = 0;
}
else
{
if((Edit18->Text).Length() == 0)
{
Application->MessageBox("结束设备号输入框为空!", "警告", MB_OK+MB_ICONINFORMATION);
Edit18->SetFocus();
return;
}
if(!isrightint(Edit18->Text))
{
Application->MessageBox("结束设备号输入框中有非法字符!", "警告", MB_OK+MB_ICONINFORMATION);
Edit18->SetFocus();
Edit18->SelectAll();
return;
}
jihao = StrToInt(Edit18->Text);
}
Comport_Handle = PortOpen(commindex->ItemIndex+1);
if(Comport_Handle == INVALID_HANDLE_VALUE)
{
Application->MessageBox("串口无法打开,请选择其他串口重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
CloseBeep(Comport_Handle,jihao);
PortClose(Comport_Handle);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
AnsiString strls;
AnsiString strls1;
int status;
char lll[100];
char *jhls;
int jihao;
int beepforxms;
int unbeepforxms;
int times;
unsigned char cardhao[10];
unsigned long cardserial_long;
int i;
HANDLE (__stdcall *PortOpen)(int comport);
bool (__stdcall *PortClose)(HANDLE ComportHandle);
void (__stdcall *Delay_ms)(DWORD xms);
int (__stdcall *GetCardNoForByte)(HANDLE ComportHandle,int Jihao,unsigned char * CardNoBuf);
AnsiString FileName=ExtractFilePath(Application->ExeName);
if(FileName.SubString(FileName.Length(),1) != "\\")
{
FileName += "\\";
}
FileName += "sycomdll.dll";
if(!FileExists(FileName))
{
ShowMessage("无法在当前目录下找到sycomdll.dll文件!");
return;
}
//to get function pointers
HINSTANCE hDll;
hDll=LoadLibrary(FileName.c_str());
PortOpen = (HANDLE (__stdcall *)(int comport))GetProcAddress(hDll,"PortOpen");
PortClose = (bool (__stdcall *)(HANDLE ComportHandle))GetProcAddress(hDll,"PortClose");
Delay_ms = (void (__stdcall *)(DWORD xms))GetProcAddress(hDll,"Delay_ms");
GetCardNoForByte = (int (__stdcall *)(HANDLE ComportHandle,int Jihao,unsigned char * CardNoBuf))GetProcAddress(hDll,"GetCardNoForByte");
if(commindex->Items->Count<1)
{
Application->MessageBox("无法找到可用的串口,请释放其他软件对串口的占用再重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
if((Edit6->Text).Length() == 0)
{
Application->MessageBox("设备号输入框为空!", "警告", MB_OK+MB_ICONINFORMATION);
Edit6->SetFocus();
Edit6->SelectAll();
return;
}
if(!isrightint(Edit6->Text))
{
Application->MessageBox("设备号中有非法字符!", "警告", MB_OK+MB_ICONINFORMATION);
Edit6->SetFocus();
Edit6->SelectAll();
return;
}
jihao = StrToInt(Edit6->Text);
Comport_Handle = PortOpen(commindex->ItemIndex+1);
if(Comport_Handle == INVALID_HANDLE_VALUE)
{
Application->MessageBox("串口无法打开,请选择其他串口重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
status = GetCardNoForByte(Comport_Handle,jihao,cardhao);
PortClose(Comport_Handle);
if(status == 0)
{//读卡成功
strls1 = "";
for(i=0;i<4;i++)
{
strls = "00"+IntToHex(cardhao[i],2);
strls1 = strls1 + RightStr(strls,2) + "-";
}
strls = "00"+IntToHex(cardhao[4],2);
strls1 = strls1 + RightStr(strls,2);
Edit8->Text = strls1;
cardserial_long = 0;
for(i=1;i<5;i++)
{
cardserial_long = cardserial_long * 256;
cardserial_long = cardserial_long + cardhao[i];
}
strls = "000000000" + IntToStr(cardserial_long);
Edit3->Text = RightStr(strls,10);
strls = "000" + IntToStr(cardhao[2]);
strls1 = RightStr(strls,3) + ",";
strls = "00000" + IntToStr(int(cardhao[3])*256+int(cardhao[4]));
Edit5->Text = strls1 + RightStr(strls,5);
return;
}
Edit3->Text = "读卡失败";
Edit5->Text = "读卡失败";
Edit8->Text = "读卡失败";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn1Click(TObject *Sender)
{
HANDLE (__stdcall *PortOpen)(int comport);
void (__stdcall *Delay_ms)(DWORD xms);
AnsiString FileName=ExtractFilePath(Application->ExeName);
if(FileName.SubString(FileName.Length(),1) != "\\")
{
FileName += "\\";
}
FileName += "sycomdll.dll";
if(!FileExists(FileName))
{
ShowMessage("无法在当前目录下找到sycomdll.dll文件!");
return;
}
//to get function pointers
HINSTANCE hDll;
hDll=LoadLibrary(FileName.c_str());
PortOpen = (HANDLE (__stdcall *)(int comport))GetProcAddress(hDll,"PortOpen");
Delay_ms = (void (__stdcall *)(DWORD xms))GetProcAddress(hDll,"Delay_ms");
if(btn1->Caption == "开始轮询")
{
if(commindex->Items->Count<1)
{
Application->MessageBox("无法找到可用的串口,请释放其他软件对串口的占用再重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
if((edt_1->Text).Length() == 0)
{
Application->MessageBox("启始设备号输入框为空!", "警告", MB_OK+MB_ICONINFORMATION);
edt_1->SetFocus();
edt_1->SelectAll();
return;
}
if(!isrightint(edt_1->Text))
{
Application->MessageBox("启始设备号输入框中有非法字符!", "警告", MB_OK+MB_ICONINFORMATION);
edt_1->SetFocus();
edt_1->SelectAll();
return;
}
if((edt_2->Text).Length() == 0)
{
Application->MessageBox("结束设备号输入框为空!", "警告", MB_OK+MB_ICONINFORMATION);
edt_2->SetFocus();
edt_2->SelectAll();
return;
}
if(!isrightint(edt_2->Text))
{
Application->MessageBox("结束设备号输入框中有非法字符!", "警告", MB_OK+MB_ICONINFORMATION);
edt_2->SetFocus();
edt_2->SelectAll();
return;
}
if((edt_3->Text).Length() == 0)
{
Application->MessageBox("每一轮循环间隔输入框为空!", "警告", MB_OK+MB_ICONINFORMATION);
edt_3->SetFocus();
edt_3->SelectAll();
return;
}
if(!isrightint(edt_3->Text))
{
Application->MessageBox("每一轮循环间隔输入框中有非法字符!", "警告", MB_OK+MB_ICONINFORMATION);
edt_3->SetFocus();
edt_3->SelectAll();
return;
}
startxbh = StrToInt(edt_1->Text);
endxbh = StrToInt(edt_2->Text);
if(startxbh>endxbh)
{
midxbh = endxbh;
endxbh = startxbh;
startxbh = midxbh;
}
else
{
midxbh = startxbh;
}
sjjg = StrToInt(edt_3->Text);
zqs = 0;
Comport_Handle = PortOpen(commindex->ItemIndex+1);
if(Comport_Handle == INVALID_HANDLE_VALUE)
{
Application->MessageBox("串口无法打开,请选择其他串口重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
lv1->Items->Clear();
edt_4->Text ="0";
//timescount = 0;
edt_1->Enabled = false;
edt_2->Enabled = false;
edt_3->Enabled = false;
Button_updata->Enabled = false;
Button1->Enabled = false;
Button2->Enabled = false;
Button3->Enabled = false;
Button6->Enabled = false;
Button8->Enabled = false;
Button9->Enabled = false;
Button10->Enabled = false;
Button10->Enabled = false;
btn1->Caption = "终止轮询";
timeconitue = true;
myprocstart = True;
thread0 = new lsthread(false);
}
else
{
timeconitue = false;
edt_1->Enabled = true;
edt_2->Enabled = true;
edt_3->Enabled = true;
Button_updata->Enabled = true;
Button1->Enabled = true;
Button2->Enabled = true;
Button3->Enabled = true;
Button6->Enabled = true;
Button8->Enabled = true;
Button9->Enabled = true;
Button10->Enabled = true;
Button10->Enabled = true;
btn1->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn2Click(TObject *Sender)
{
lv1->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject *Sender)
{
AnsiString strls;
int status;
char lll[100];
char *jhls;
int jihao;
int beepforxms;
int unbeepforxms;
int times;
char cardhao[10];
char keystring[39];
HANDLE (__stdcall *PortOpen)(int comport);
bool (__stdcall *PortClose)(HANDLE ComportHandle);
void (__stdcall *Delay_ms)(DWORD xms);
int (__stdcall *GetKeyInputForString)(HANDLE ComportHandle,int Jihao,LPSTR KeyInputString);
AnsiString FileName=ExtractFilePath(Application->ExeName);
if(FileName.SubString(FileName.Length(),1) != "\\")
{
FileName += "\\";
}
FileName += "sycomdll.dll";
if(!FileExists(FileName))
{
ShowMessage("无法在当前目录下找到sycomdll.dll文件!");
return;
}
//to get function pointers
HINSTANCE hDll;
hDll=LoadLibrary(FileName.c_str());
PortOpen = (HANDLE (__stdcall *)(int comport))GetProcAddress(hDll,"PortOpen");
PortClose = (bool (__stdcall *)(HANDLE ComportHandle))GetProcAddress(hDll,"PortClose");
Delay_ms = (void (__stdcall *)(DWORD xms))GetProcAddress(hDll,"Delay_ms");
GetKeyInputForString = (int (__stdcall *)(HANDLE ComportHandle,int Jihao,LPSTR KeyInputString))GetProcAddress(hDll,"GetKeyInputForString");
if(commindex->Items->Count<1)
{
Application->MessageBox("无法找到可用的串口,请释放其他软件对串口的占用再重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
if((Edit6->Text).Length() == 0)
{
Application->MessageBox("设备号输入框为空!", "警告", MB_OK+MB_ICONINFORMATION);
Edit6->SetFocus();
Edit6->SelectAll();
return;
}
if(!isrightint(Edit6->Text))
{
Application->MessageBox("设备号中有非法字符!", "警告", MB_OK+MB_ICONINFORMATION);
Edit6->SetFocus();
Edit6->SelectAll();
return;
}
jihao = StrToInt(Edit6->Text);
Comport_Handle = PortOpen(commindex->ItemIndex+1);
if(Comport_Handle == INVALID_HANDLE_VALUE)
{
Application->MessageBox("串口无法打开,请选择其他串口重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
jhls = keystring;
status = GetKeyInputForString(Comport_Handle,jihao,jhls);
PortClose(Comport_Handle);
if(status == 0)
{
Edit21->Text = jhls;
return;
}
else if ((status == 3) || (status == 4))
{
Edit21->Text = "没有键盘输入......";
return;
}
//ShowMessage(IntToStr(status));
Edit21->Text = "读键盘码失败";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button11Click(TObject *Sender)
{
AnsiString strls;
int status;
char lll[100];
char *jhls;
int jihao;
int beepforxms;
int unbeepforxms;
int times;
AnsiString dispstring;
HANDLE (__stdcall *PortOpen)(int comport);
bool (__stdcall *PortClose)(HANDLE ComportHandle);
void (__stdcall *Delay_ms)(DWORD xms);
int (__stdcall *SetDispFull)(HANDLE ComportHandle,int Jihao,LPSTR DispString);
AnsiString FileName=ExtractFilePath(Application->ExeName);
if(FileName.SubString(FileName.Length(),1) != "\\")
{
FileName += "\\";
}
FileName += "sycomdll.dll";
if(!FileExists(FileName))
{
ShowMessage("无法在当前目录下找到sycomdll.dll文件!");
return;
}
//to get function pointers
HINSTANCE hDll;
hDll=LoadLibrary(FileName.c_str());
PortOpen = (HANDLE (__stdcall *)(int comport))GetProcAddress(hDll,"PortOpen");
PortClose = (bool (__stdcall *)(HANDLE ComportHandle))GetProcAddress(hDll,"PortClose");
Delay_ms = (void (__stdcall *)(DWORD xms))GetProcAddress(hDll,"Delay_ms");
SetDispFull = (int (__stdcall *)(HANDLE ComportHandle,int Jihao,LPSTR DispString))GetProcAddress(hDll,"SetDispFull");
if(commindex->Items->Count<1)
{
Application->MessageBox("无法找到可用的串口,请释放其他软件对串口的占用再重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
if(CheckBox1->Checked)
{
jihao = 0;
}
else
{
if((Edit22->Text).Length() == 0)
{
Application->MessageBox("设备号输入框为空!", "警告", MB_OK+MB_ICONINFORMATION);
Edit22->SetFocus();
return;
}
if(!isrightint(Edit22->Text))
{
Application->MessageBox("设备号输入框中有非法字符!", "警告", MB_OK+MB_ICONINFORMATION);
Edit22->SetFocus();
Edit22->SelectAll();
return;
}
jihao = StrToInt(Edit22->Text);
}
if((Edit20->Text).Length() == 0)
{
Application->MessageBox("显示字符框为空!", "警告", MB_OK+MB_ICONINFORMATION);
Edit20->SetFocus();
return;
}
Comport_Handle = PortOpen(commindex->ItemIndex+1);
if(Comport_Handle == INVALID_HANDLE_VALUE)
{
Application->MessageBox("串口无法打开,请选择其他串口重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
dispstring = Edit20->Text;
SetDispFull(Comport_Handle,jihao,dispstring.c_str());
PortClose(Comport_Handle);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btn3Click(TObject *Sender)
{
//动态调用动态库
SYSTEMTIME mytime;
Word wYear,wMonth,wDay,wHour,wMinute,wSecond,wMsec;
int jihao;
HANDLE (__stdcall *PortOpen)(int comport);
bool (__stdcall *PortClose)(HANDLE ComportHandle);
void (__stdcall *Delay_ms)(DWORD xms);
int (__stdcall *SetTime)(HANDLE ComportHandle,int Jihao,SYSTEMTIME *mytime);
AnsiString FileName=ExtractFilePath(Application->ExeName);
if(FileName.SubString(FileName.Length(),1) != "\\")
{
FileName += "\\";
}
FileName += "sycomdll.dll";
if(!FileExists(FileName))
{
ShowMessage("无法在当前目录下找到sycomdll.dll文件!");
return;
}
//to get function pointers
HINSTANCE hDll;
hDll=LoadLibrary(FileName.c_str());
PortOpen = (HANDLE (__stdcall *)(int comport))GetProcAddress(hDll,"PortOpen");
PortClose = (bool (__stdcall *)(HANDLE ComportHandle))GetProcAddress(hDll,"PortClose");
Delay_ms = (void (__stdcall *)(DWORD xms))GetProcAddress(hDll,"Delay_ms");
SetTime = (int (__stdcall *)(HANDLE ComportHandle,int Jihao,SYSTEMTIME *mytime))GetProcAddress(hDll,"SetTime");
DecodeDate(dtp1->Date,wYear,wMonth,wDay);
mytime.wYear =wYear ;
mytime.wMonth =wMonth ;
mytime.wDay = wDay;
mytime.wDayOfWeek = DayOfWeek(dtp1->Date)-1;
mytime.wHour = StrToInt(edt__xd_s->Text);
mytime.wMinute = StrToInt(edt__xd_f->Text);
mytime.wSecond = StrToInt(edt__xd_m->Text);
if(commindex->Items->Count<1)
{
Application->MessageBox("无法找到可用的串口,请释放其他软件对串口的占用再重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
if(chk1->Checked)
{
jihao = 0;
}
else
{
if((edt_5->Text).Length() == 0)
{
Application->MessageBox("设备号输入框为空!", "警告", MB_OK+MB_ICONINFORMATION);
edt_5->SetFocus();
return;
}
if(!isrightint(edt_5->Text))
{
Application->MessageBox("设备号输入框中有非法字符!", "警告", MB_OK+MB_ICONINFORMATION);
edt_5->SetFocus();
edt_5->SelectAll();
return;
}
jihao = StrToInt(Edit16->Text);
}
Comport_Handle = PortOpen(commindex->ItemIndex+1);
if(Comport_Handle == INVALID_HANDLE_VALUE)
{
Application->MessageBox("串口无法打开,请选择其他串口重试!", "警告", MB_OK+MB_ICONINFORMATION);
return;
}
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
status = SetTime(Comport_Handle,jihao,&mytime);
PortClose(Comport_Handle);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
if(btn1->Caption == "开始轮询")
{
Close();
}
else
{
Application->MessageBox("请先终止轮询!", "警告", MB_OK+MB_ICONINFORMATION);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::myproc(void)
{
char keystr[39];
char *keystr_pchar;
char cardstr[21];
char *cardstr_pchar;
int status;
int i;
int jihao;
unsigned char cardhao[10];
unsigned long cardserial_long;
TListItem *pItem;
bool isadditem1;
AnsiString strls0;
AnsiString strls1;
AnsiString strlsok0;
AnsiString strlsok1;
HANDLE (__stdcall *PortOpen)(int comport);
bool (__stdcall *PortClose)(HANDLE ComportHandle);
void (__stdcall *Delay_ms)(DWORD xms);
int (__stdcall *GetCARDNO_KeyInput)(HANDLE ComportHandle,int Jihao,LPSTR CardNoString,LPSTR KeyInputString);
AnsiString FileName=ExtractFilePath(Application->ExeName);
if(FileName.SubString(FileName.Length(),1) != "\\")
{
FileName += "\\";
}
FileName += "sycomdll.dll";
if(!FileExists(FileName))
{
ShowMessage("无法在当前目录下找到sycomdll.dll文件!");
return;
}
//to get function pointers
HINSTANCE hDll;
hDll=LoadLibrary(FileName.c_str());
PortOpen = (HANDLE (__stdcall *)(int comport))GetProcAddress(hDll,"PortOpen");
PortClose = (bool (__stdcall *)(HANDLE ComportHandle))GetProcAddress(hDll,"PortClose");
Delay_ms = (void (__stdcall *)(DWORD xms))GetProcAddress(hDll,"Delay_ms");
GetCARDNO_KeyInput = (int (__stdcall *)(HANDLE ComportHandle,int Jihao,LPSTR CardNoString,LPSTR KeyInputString))GetProcAddress(hDll,"GetCARDNO_KeyInput");
//轮询读卡及键盘
if(midxbh>endxbh)
{
midxbh = startxbh;
edt_4->Text = IntToStr(StrToInt(edt_4->Text)+1);
if(sjjg >0)
{
Delay_ms(sjjg);
}
}
//读函数
keystr_pchar = keystr;
cardstr_pchar = cardstr;
status = GetCARDNO_KeyInput(Comport_Handle,midxbh,cardstr_pchar,keystr_pchar);
if(status == 0X10)
{
strlsok0 = cardstr_pchar;
strlsok1 = "无键盘输出";
status = 0;
}
else if(status = 0x20)
{
strlsok0 = "暂无刷卡";
strlsok1 = keystr_pchar;
status = 0;
}
else if(status = 0)
{
strlsok0 = cardstr_pchar;
strlsok0 = IntToHex(StrToInt(strlsok0),8);
strlsok1 = keystr_pchar;
}
if(status = 0)
{
pItem = lv1->Items->Add();
pItem->Caption = IntToStr(midxbh);
pItem->SubItems->Add(strlsok0);
pItem->SubItems->Add(strlsok1);
SendMessage(lv1->Handle,WM_KEYDOWN, 35, 0);
}
midxbh = midxbh + 1;
if(!timeconitue)
{
PortClose(Comport_Handle); //关闭串口
btn1->Caption = "开始轮询";
btn1->Enabled = true;
}
myprocstart = True;
}