📄 serialdlg.cpp
字号:
MessageBox ("Error: TxRDY missing, can't send. To be terminated!" ) ;
return ;
}
} while(! (inportb(CTRL_8251) & 0x01) );
// send to 8251
outportb (DATA_8251,'c' ) ;//发送 我要加钱!!!
outportb(0x301,'c');
Sleep (40) ;
iTextLengthOld = iTextLengthNew ;
pWndReceive->LineScroll(255,0);
//*假设加钱 发钱
//char addstring[7]="111111"; //1111.11元
int i;
for(i=0;i<6;i++) {
pWndSend = GetDlgItem(IDC_EDIT_SEND);
// get input text
pWndSend->GetWindowText(m_strSend);
iTextLengthNew = m_strSend.GetLength() ;
chSend = (char)tchSend ; //method 3
m_strSend+=substring[i]; //显示
UpdateData(false);
tchSend = m_strSend.GetAt(iTextLengthNew) ;
CEdit* pWndReceive =(CEdit*) GetDlgItem(IDC_EDIT_SEND);
time (&tFirst) ; //取当前时间(以秒为单位)
do {
time (&tSecond) ; //再次取当前时间(以秒为单位)
if(difftime(tSecond,tFirst) > 1 )
{
//TxRDY missing, can't send.
MessageBox ("Error: TxRDY missing, can't send. To be terminated!" ) ;
return ;
}
} while(! (inportb(CTRL_8251) & 0x01) );
outportb (DATA_8251, substring[i]) ;//发送 我要加钱了!!!!!
outportb(0x301,0xff-substring[i]);
Sleep (50) ;
iTextLengthOld = iTextLengthNew ;
pWndReceive->LineScroll(255,0);
} //假设发送1111.11钱 以分为单位 加
for(int l=0;l<6;l++) substring[l]='0';//初始化substring
ifpoint=false;
m_point.EnableWindow(true);
nowat=3;
}
//减法
void CSerialDlg::Onsub()
{//开始声音
iTime = (CLK_8253 / iBaudrate ) / FACTOR16_BAUDRATE_8251 ;
iTimeHigh = (iTime>>8) & 0x00FF ;
iTimeLow = iTime & 0x00FF ;
//初始化8255、8253、8251
//设置8255工作方式
//置PC6为输出以控制8251 GATE2
outportb(CTRL_8255, 0x80 );
outportb(0x301,0xff);//LED全灭 ////8255控制
outportb(0x303,0x0c);//关闭SPK
outportb(0x303,0x01); //PC0置1
Sleep(DELAY1_8251);
//设置8253工作方式
//通道2;
//读/写2个字节,先是低字节,后是高字节;
//3方式;
//二进制码计数。
outportb (CTRL_8253, 0xB6) ; //10110110B,8253工作方式命令字
Sleep (DELAY1_8251) ;
//往8253送计时常数
//outportb (TIMER2_8253, iTimeLow ) ; //装计数初值低字节
//outportb (TIMER2_8253, iTimeHigh ) ; //装计数初值高字节
outportb (TIMER2_8253, 0xff);
outportb (TIMER2_8253, 0x00);
Sleep (DELAY1_8251) ;
//置8255 PC6=1,PC6与8253 GATE2相连,即允许8253通道2计数
outportb (CTRL_8255, 0x0D ) ; //00001101B //开喇叭
outportb (0x301, 0xcc);//灯亮
Sleep (DELAY1_8251) ;
//空操作,向8251命令口写任意数
for(int j=0; j<REPEATS2_8251; j++)
{
outportb (CTRL_8251, 0x00 ) ;
Sleep (DELAY2_8251) ;
}
//8251内部复位
//置8251 D6=1,使其内部复位
//发方式命令之前一定要先进行内部复位
outportb (CTRL_8251, 0x40) ;
Sleep (DELAY1_8251);
//往8251写方式命令字
//复位命令之后一定是跟方式命令
outportb (CTRL_8251, iModal_8251) ;
Sleep (DELAY1_8251);
//往8251写工作命令字
outportb(CTRL_8251, iOperating_8251);
Sleep(DELAY1_8251);
//outportb(0x303,0
outportb(0x303,0x0c);// 关声音clock
outportb (TIMER2_8253, iTimeLow ) ; //装计数初值低字节
outportb (TIMER2_8253, iTimeHigh ) ; //装计数初值高字节
outportb(0x303,0x0d);// 开声音clock
outportb(0x301,0xff);//
//结束声音
ifcardin=false;
SetTimer(0,999,NULL);
//MessageBox(substring);
pWndSend = GetDlgItem(IDC_EDIT_SEND);
// get input text
pWndSend->GetWindowText(m_strSend);
iTextLengthNew = m_strSend.GetLength() ;
//if (iTextLengthNew > iTextLengthOld ) {
// CString to TCHAR
//tchSend = m_strSend.GetAt(iTextLengthNew - 1) ;
// TCHAR to CHAR
//chSend = tchSend & 0x00FF ; //method 1
//chSend = char(tchSend) ; //method 2
chSend = (char)tchSend ; //method 3
m_strSend+='d'; //显示
// m_strSend+=13;
// m_strSend+='\n';
UpdateData(false);
tchSend = m_strSend.GetAt(iTextLengthNew) ;
CEdit* pWndReceive =(CEdit*) GetDlgItem(IDC_EDIT_SEND);
//判断待发字符种类
//if (! iscntrl (chSend ) ) {//如果chSend是
// Waiting for TxRDY on
time (&tFirst) ; //取当前时间(以秒为单位)
do {
time (&tSecond) ; //再次取当前时间(以秒为单位)
if(difftime(tSecond,tFirst) > 1 )
{
//TxRDY missing, can't send.
MessageBox ("Error: TxRDY missing, can't send. To be terminated!" ) ;
return ;
}
} while(! (inportb(CTRL_8251) & 0x01) );
// send to 8251
outportb (DATA_8251,'d' ) ;//发送 我要加钱!!!
outportb(0x301,'d');
Sleep (40) ;
iTextLengthOld = iTextLengthNew ;
pWndReceive->LineScroll(255,0);
//*假设加钱 发钱
int i;
for(i=0;i<6;i++) {
pWndSend = GetDlgItem(IDC_EDIT_SEND);
// get input text
pWndSend->GetWindowText(m_strSend);
iTextLengthNew = m_strSend.GetLength() ;
chSend = (char)tchSend ; //method 3
m_strSend+=substring[i]; //显示
UpdateData(false);
tchSend = m_strSend.GetAt(iTextLengthNew) ;
CEdit* pWndReceive =(CEdit*) GetDlgItem(IDC_EDIT_SEND);
time (&tFirst) ; //取当前时间(以秒为单位)
do {
time (&tSecond) ; //再次取当前时间(以秒为单位)
if(difftime(tSecond,tFirst) > 1 )
{
//TxRDY missing, can't send.
MessageBox ("Error: TxRDY missing, can't send. To be terminated!" ) ;
return ;
}
} while(! (inportb(CTRL_8251) & 0x01) );
outportb (DATA_8251, substring[i]) ;//发送 我要加钱了!!!!!
outportb(0x301,0xff-substring[i]);
Sleep (50) ;
iTextLengthOld = iTextLengthNew ;
pWndReceive->LineScroll(255,0);
} //假设发送2222.22钱 以分为单位 加
for(int l=0;l<6;l++) substring[l]='0';//初始化substring
ifpoint=false;
m_point.EnableWindow(true);
nowat=3;
}
void CSerialDlg::On1()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="1";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='1';
nowat--;
} else {
m_strSend+="1";
UpdateData(false);
substring[nowat]='1';
nowat++;
}
m_disp=substring;
UpdateData(false);
}
}
}
void CSerialDlg::On2()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="2";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='2';
nowat--;
} else {
m_strSend+="2";
UpdateData(false);
substring[nowat]='2';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::On3()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="3";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='3';
nowat--;
} else {
m_strSend+="3";
UpdateData(false);
substring[nowat]='3';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::On4()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="4";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='4';
nowat--;
} else {
m_strSend+="4";
UpdateData(false);
substring[nowat]='4';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::On5()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="5";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='5';
nowat--;
} else {
m_strSend+="5";
UpdateData(false);
substring[nowat]='5';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::On6()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="61";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='6';
nowat--;
} else {
m_strSend+="6";
UpdateData(false);
substring[nowat]='6';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::On7()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="7";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='7';
nowat--;
} else {
m_strSend+="7";
UpdateData(false);
substring[nowat]='7';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::On8()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="8";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='8';
nowat--;
} else {
m_strSend+="8";
UpdateData(false);
substring[nowat]='8';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::On9()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="9";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='9';
nowat--;
} else {
m_strSend+="9";
UpdateData(false);
substring[nowat]='9';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::On0()
{
if (nowat==-1) {MessageBox("前4位满了"); }
else {
if (nowat==6) {MessageBox("后2位满了"); }
else {
if (ifpoint==false) {
// TODO: Add your control notification handler code here
m_strSend+="0";
UpdateData(false);
for(int k=0;k<3;k++) substring[k]=substring[k+1];
substring[3]='0';
nowat--;
} else {
m_strSend+="0";
UpdateData(false);
substring[nowat]='0';
nowat++;
}
m_disp=substring;UpdateData(false);
}
}
}
void CSerialDlg::Onpoint()
{
ifpoint=true;
m_point.EnableWindow(false);
nowat=4;
//m_strSend+=".";
//UpdateData(false);
}
void CSerialDlg::Onc()
{
m_strSend+="c";
for(int i=0;i<6;i++) substring[i]='0';
ifpoint=false;
m_point.EnableWindow(true);
nowat=3;
//comput="";
m_disp=substring;
UpdateData(false);
}
void CSerialDlg::OnButton1()
{
outportb(0x301,0x55); //led灯亮控制11111111
outportb(0x303,0x01); //PC0置1 控制clock-->喇叭
outportb(0x306, 0xff ) ; //装计数初值低字节
outportb(0x306, 0x00 ) ; //装计数初值高字节
outportb(0x303,0x0d);// 开声音clock 控制8253开始输出计数
Sleep(50); //关喇叭)
//outportb(0x301,0xff); //关灯
outportb(0x303,0x0c); //关喇叭
//恢复现场iTimeHigh, iTimeLow
outportb(0x306,iTimeLow);
outportb(0x306,iTimeHigh);
}
void CSerialDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
char tempc[7];
for(int i=6;i>0;i--)
{
tempc[i-1]=m_strMessage.GetAt(m_IndexNum-7+i);
}
//MessageBox(tempc);
m_disp.Empty();
for(i=0;i<6;i++) m_disp+=tempc[i];
if (ifcardin==false)
{
UpdateData(false);
ifcardin=true;
}
CDialog::OnTimer(nIDEvent);
}
/*
outportb(0x301,0xff);//LED全灭 ////8255控制
outportb(0x303,0x0c);//关闭SPK
outportb(0x301,0x00); //led灯亮控制11111111
outportb(0x303,0x01); //PC0置1 控制clock-->喇叭
outportb(0x306, 0xff ) ; //装计数初值低字节
outportb(0x306, 0xff ) ; //装计数初值高字节
outportb(0x303,0x0d);// 开声音clock 控制8253开始输出计数
sleep(2000);
outportb(0x301,0xff);
outportb(0x303,0x0c);
//恢复现场
outportb(0x306,TimerLow);
outportb(0x306,TimerHIGH);
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -