请访问:www.horseb.org
作者主页
//Author:horse_b
//hhkj.cpp
//车道设备接口协议---------------------------------------------------------------------------
#include /<vcl.h/>
#pragma hdrstop
#include "hhkj.h"
#include "diocomm.h"
//---------------------------------------------------------------------------
USEUNIT("Diocomm.cpp");
//---------------------------------------------------------------------------
static int LState = 0, CState = 0, FindCar = 0; //车流量信号
static int /*LCapState = 0, CCapState = 0, */CaptureCar = 0; //抓拍信号
//TDiocomm* DiocommTV; //字符叠加
//TDiocomm* DiocommSound; //语音报价器
//---------------------------------------------------------------------------
unsigned char getport(WORD address)
{ Byte bValue;
asm
{
mov dx, address
in al, dx
mov bValue, al
}
return (bValue);
}
//---------------------------------------------------------------------------
void SetPort(WORD address,WORD Value)
{
Byte bValue;
bValue = Byte(Value & 255);
asm
{
mov dx, address
mov al, bValue
out dx, al
}
}
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) int _stdcall CheckFL(void) //Address=672 Bit=3
{
CState = int(getport(672)); //672
CState= ( CState>> (3-1)) & 0x01; //3
if ((CState == 0) && (LState == 1))
{ FindCar = 1; }
else
{ FindCar = 0; }
LState = CState;
return FindCar;
}
//******************************************************************************
extern "C" __declspec(dllexport) int _stdcall CheckCar(void) //Address=672 Bit=3
{
//CCapState = int(getport(672)); //672
//CCapState= ( CCapState>> (3-1)) & 0x01; //3
//if ((CCapState == 0) && (LCapState == 1))
// { CaptureCar = 1; }
//else
// { CaptureCar = 0; }
//LCapState = CCapState;
CaptureCar = CheckFL();
return CaptureCar;
}
//************************************************************************
extern "C" __declspec(dllexport) int __stdcall CheckWarn(void) //匪警报警信号
{
unsigned char data;
asm
{
mov dx, 2a0h
in al,dx
mov data,al
};
if((data&1)==0) {return 1;}
else
{
return 0;
}
}
//********************************************************************************
void __fastcall SetNewPortBitNoLed(WORD address ,WORD Bit, WORD Status)
{
Byte bValue;//, tmp, tmp2;
bValue = Status * 0x80 + (Bit-1) * 0x10;
bValue = Byte(bValue & 255);
asm
{
mov dx, address
mov al, bValue
out dx, al
mov dx, 0x2ec
mov al, 0x2
out dx, al
mov dx, 0x2ec
mov al, 0x3
out dx, al
mov dx, 0x2ec
mov al, 0x2
out dx, al
}
}
//---------------------------------------------------------------------------
void __fastcall OnePortBitNoLed(WORD address ,WORD Bit)
{
SetNewPortBitNoLed(WORD(address),Bit,1);
}
//---------------------------------------------------------------------------
void __fastcall ZeroPortBitNoLed(WORD address ,WORD Bit)
{
SetNewPortBitNoLed(WORD(address),Bit,0);
}
//--------------------------------------------------------------------------------
void __fastcall CtrlPortBitNoLed(WORD address ,WORD Bit, int CtrlTime)
{
SetNewPortBitNoLed(WORD(address),Bit,1);
if (CtrlTime != 0) Sleep(CtrlTime);
SetNewPortBitNoLed(WORD(address),Bit,0);
}
//******************************************************************************
extern "C" __declspec(dllexport) int __stdcall CoverSignal(int mode) //mode=0 关 ; mode=1 开 雨棚灯
{
//Address=632 Bit=6
__try
{
if (mode==0)
{
ZeroPortBitNoLed(632,6);
}
else
{
OnePortBitNoLed(632,6);
}
return 1;
}
catch(...)
{
return 0;
}
}
extern "C" __declspec(dllexport) int __stdcall FogSignal(int mode) //mode=0 关 ; mode=1 开 雾灯
{
//Address=632 Bit=5
__try
{
if (mode==0)
{
ZeroPortBitNoLed(632,5);
}
else
{
OnePortBitNoLed(632,5);
}
return 1;
}
catch(...)
{
return 0;
}
}
extern "C" __declspec(dllexport) int __stdcall Signal(int mode) //mode=0 关 ; mode=1 开 通行灯
{
//Address=632 Bit=3
__try
{
if (mode==1)
{
ZeroPortBitNoLed(632,3);
}
else
{
OnePortBitNoLed(632,3);
}
return 1;
}
catch(...)
{
return 0;
}
}
extern "C" __declspec(dllexport) int __stdcall Warn(int mode) //报警器报警
{
//Address=632 Bit=4
__try
{
if (mode==1)
{
CtrlPortBitNoLed(632,4,300);
}
else
{
ZeroPortBitNoLed(632,4);
}
return 1;
}
catch(...)
{
return 0;
}
}
//******************************************************************************
//栏杆
extern "C" __declspec(dllexport) int _stdcall CheckBarStatus(void) //Address=672 Bit=2/1
{
int Status;
int BState = int(getport(672)); //672
BState= ( BState>> (2-1)) & 0x01; //2 落杆
if (BState == 0)
{ Status = 0; }
else
{
//int B2State = int(getport(672));
//B2State = (B2State>> (1-1)) & 0x01; //1 抬杆
//if (B2State == 0)
{ Status = 1;}
//else
// { Status = -1;}
}
return Status;
}
extern "C" __declspec(dllexport) int __stdcall BarOpen(void) //栏杆抬
{
__try
{
ZeroPortBitNoLed(632,2);
OnePortBitNoLed(632,1);
Sleep(320);
ZeroPortBitNoLed(632,1);
return 1;
}
catch(...)
{return 0;}
}
extern "C" __declspec(dllexport) int __stdcall BarClose(void) //栏杆落
{
__try
{
ZeroPortBitNoLed(632,1);
OnePortBitNoLed(632,2);
return 1;
}
catch(...)
{return 0;}
}
//******************************************************************************
extern "C" __declspec(dllexport) bool __stdcall InitCard(void)//初始化多功能卡
{
DiocommTV = new TDiocomm(3,12,4,0,3); //字符叠加 //com4
DiocommSound = new TDiocomm(3,48,4,0,2); //语音报价器 //com3
return true;
}
extern "C" __declspec(dllexport) bool __stdcall StopCard(void) //退出多功能卡的控制
{
delete DiocommTV;
delete DiocommSound;
return true;
}
//******************************************************************************
//字符叠加 (全角字符)
//
char* _fastcall ChangeFormat(int x, int y, char* S)
{
AnsiString tmp,tmpy,tmpx;
char *InternalFormat;
tmp=" tmpy="";
tmpx="";
if(0<=y<10)
{
tmpy="0"+IntToStr(y);
}
else if(10<=y<=99)
{
tmpy=IntToStr(y);
}
else if(y>=100)
{
tmpy="01";
}
if(0<=x<10)
{
tmpx="0"+IntToStr(x);
}
else if(10<=x<=99)
{
tmpx=IntToStr(x);
}
else if(x>=100)
{
tmpx="01";
}
tmp = tmp+tmpy+tmpx+"00518F"+S+">";
InternalFormat = tmp.c_str();
return InternalFormat;
}
char* ChangeFormatTime(int x,int y,char *S)
{
char *InternalFormat;
AnsiString tmp,tmpx,tmpy;
tmp=" tmpx="";
tmpy="";
if(0<=x<10)
{
tmpx="0"+IntToStr(x);
}
else if(10<=x<=99)
{
tmpx=IntToStr(x);
}
else if (x>=100)
{
tmpx="01";
}
if(0<=y<10)
{
tmpy="0"+IntToStr(y);
}
else if(10<=y<=99)
{
tmpy=IntToStr(y);
}
else if(y>=100)
{
tmpy="01";
}
tmp = tmp+tmpy+tmpx+S[0]+S[1]+S[2]+S[3]+S[4]+S[5]+S[6]+S[7]+S[8]+S[9]+S[10]+S[11]+">";
InternalFormat = tmp.c_str();
return InternalFormat;
}
extern "C" __declspec(dllexport) bool __stdcall SendTVAdd(int x,int y,int mode,char *S)
{
Byte* WriteChar;
int result;
if (mode==0)
{
WriteChar = (Byte*)ChangeFormat(x,y,S);
}
if (mode==1)
{
//时间不用全角
WriteChar = (Byte*)ChangeFormatTime(x,y,S);
}
result = DiocommTV->SendComm(WriteChar, Word(strlen(WriteChar)));
if (result)
{
return true;
}
else
{
return false;
}
}
extern "C" __declspec(dllexport) bool __stdcall GetTVAddStatus(void)
{
if(DiocommTV!=NULL)
{
return true;
}
else
{
return false;
}
}
//***********************************************************************************
//语音
extern "C" __declspec(dllexport) bool __stdcall GetDispStatus(void)
{
if(DiocommSound!=NULL)
{
return true;
}
else
{
return false;
}
}
bool SoundPrice(BYTE * WriteChar)
{
Byte WriteCharB[7];
if ((WriteChar[1]==0x02)||(WriteChar[1]==0x04)) //报价,免费
{
WriteCharB[0]=0x80;
WriteCharB[1]=0x04;
WriteCharB[2]=byte(WriteChar[2]);
WriteCharB[3]=byte(WriteChar[3]);
WriteCharB[4]=byte(WriteChar[4]);
WriteCharB[5]=byte(WriteChar[5]);
WriteCharB[6]=byte(WriteChar[7]);
}
if (WriteChar[1]==0x05) //月票
{
WriteCharB[0]=0x88;
WriteCharB[1]=0x04;
WriteCharB[2]=WriteChar[2];
WriteCharB[3]=WriteChar[3];
WriteCharB[4]=WriteChar[4];
WriteCharB[5]=WriteChar[5];
WriteCharB[6]=WriteChar[7];
}
if (WriteChar[1]==0x06) //逃费
{
WriteCharB[0]=0x90;
WriteCharB[1]=0x04;
WriteCharB[2]=WriteChar[2];
WriteCharB[3]=WriteChar[3];
WriteCharB[4]=WriteChar[4];
WriteCharB[5]=WriteChar[5];
WriteCharB[6]=WriteChar[7];
}
DiocommSound->SendComm(WriteCharB, 7);
return true;
}
extern "C" __declspec(dllexport) bool __stdcall SendDisp(int mode,int Data) //语音报价函数 max=999元
{
byte WriteCharA[8];
int AUnitPrice;
switch(mode)
{
case 0: //收费
WriteCharA[0]=(0x80);
WriteCharA[1]=(0x02);
WriteCharA[2]=(0x00);
WriteCharA[3]=byte(Data/100);byte(AUnitPrice = Data % 100);//百
WriteCharA[4]=byte(AUnitPrice/10);byte(AUnitPrice = AUnitPrice % 10);//十
WriteCharA[5]=byte(AUnitPrice);//个
WriteCharA[6]=(0x00);
WriteCharA[7]=(0x7f);
SoundPrice(WriteCharA);
break;
case 1: //免费
WriteCharA[0]=(0x80);
WriteCharA[1]=(0x04);
WriteCharA[2]=(0x00);
WriteCharA[3]=(0x00);
WriteCharA[4]=(0x00);
WriteCharA[5]=(0x00);
WriteCharA[6]=(0x00);
WriteCharA[7]=(0x7f);
SoundPrice(WriteCharA);
break;
case 2: //逃票
WriteCharA[0]=(0x80);
WriteCharA[1]=(0x06);
WriteCharA[2]=(0x00);
WriteCharA[3]=byte(Data/100);byte(AUnitPrice = Data % 100);//百
WriteCharA[4]=byte(AUnitPrice/10);byte(AUnitPrice = AUnitPrice % 10);//十
WriteCharA[5]=byte(AUnitPrice/10);//个
WriteCharA[6]=(0x00);
WriteCharA[7]=(0x7f);
SoundPrice(WriteCharA);
break;
case 3: //月票
WriteCharA[0]=(0x80);
WriteCharA[1]=(0x05);
WriteCharA[2]=(0x00);
WriteCharA[3]=byte(Data/100);byte(AUnitPrice = Data % 100);//百
WriteCharA[4]=byte(AUnitPrice/10);byte(AUnitPrice = AUnitPrice % 10);//十
WriteCharA[5]=byte(AUnitPrice/10);//个
WriteCharA[6]=(0x00);
WriteCharA[7]=(0x7f);
SoundPrice(WriteCharA);
break;
}
return true;
}
extern "C" __declspec(dllexport) int __stdcall Control(int mode,char* S)
{
return 0;
}
extern "C" __declspec(dllexport) int __stdcall GetData(int mode)
{
return 0;
}
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
return 1;
}