江苏公路收费设备接口协议代码,horse_b于1999年开发

请访问:www.horseb.org

            www.horseb.net

         作者主页

//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;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
支持GPL协议: one line to give the program\'s name and an idea of what it does. Copyright (C) Ports Project 2007/01/30 horse_b This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.      horse_b 研究了6代码跨平台移植项目,可以做大部分项目的移植,在这里的项目大部分是GPL工程 所以大家得到我的PORTS工程以后,也请尊重GPL协议   文件列表: libpcap-cygwin-port.tar.gz libnet-cygwin-port.tar.gz libtiff-cygwin-port.tar.gz libtiff-mingw-port.tar.gz libtiff-vc-vs.net-port.rar 说明: 所有这些PORTS项目都是horse_b的个人制作,2001我为NIDS系统软件SNORT项目做了一个WIN32-Port的项目, 应该比SNORT作者出win32 port要早半,但是我没有公开过这个WIN32 PORT,这个项目的WIN32 的二进制程序 在黑客网站黑白中可以找到 http://www.yiii.net/app/club/view.jsp?Information_Id=I00014317 抓包驱动snort182drv.zip http://www.yiii.net/app/club/view.jsp?Information_Id=I00014560 ids.zip 请大家尊重我的劳动,不允许任意改动我做的PORTS项目,用要做PORTS项目的,请发邮件和我联系 如果有人和我讨论移植和开发编译器,可以来信和我讨论: 我的专门接受此类问题的EMAIL: winddk64@gmail.com 或者 winddk64@163.com       技术下载区 Libpcap cygwin port下载:    libpcap-cygwin-port.tar.gz libnet cygwin port下载: libnet-cygwin-port.tar.gz   libtiff cygwin port下载: libtiff-cygwin-port.tar.gz libtiff mingw port下载: libnet-mingw-port.tar.gz (这个工程我觉得有VC和VS。NET的PORT了,我就没做这个PORT,有人要这个PORT,可以和我联系,半天就能搞定了) libtiff vc++&

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值