» » '


'

| 2 2
asubsequentDestroyIcon inWin32

>m_hIcon =AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

>voidCSerialGateTestDlg::DoDataExchange(CDataExchange*pDX)

{

>CDialog::DoDataExchange(pDX);

//{{>AFX_DATA_MAP(CSerialGateTestDlg)

>DDX_Control(pDX,IDC_RECIEVE,m_recievecontr);

>DDX_Text(pDX,IDC_PORT,m_port);

>DDX_Text(pDX,IDC_RATE,m_rate);

>DDX_Text(pDX,IDC_RECIEVE,m_recieve);

>DDX_Text(pDX,IDC_SEND,m_send);

>DDX_Text(pDX,IDC_SETAXSCIS,m_axsis);

>DDX_Text(pDX,IDC_SETVEL,m_vel);

>DDX_Text(pDX,IDC_SETASEL,m_asel);

>DDX_Text(pDX,IDC_MR,m_gomr);

>DDX_Text(pDX,IDC_MRAXSIS0,m_mraxsis0);

>DDX_Text(pDX,IDC_MRAXSIS1,m_mraxsis1);

>DDX_Text(pDX,IDC_TAPEAXSIS1,m_tapeaxsis1);

>DDX_Text(pDX,IDC_DATAEXCHANGE,m_dataininput);

>DDX_Text(pDX,IDC_DATAEXCHANGE2,m_dataoutput);

//}}>AFX_DATA_MAP

}

>BEGIN_MESSAGE_MAP(CSerialGateTestDlg,CDialog)

//{{>AFX_MSG_MAP(CSerialGateTestDlg)

>ON_WM_SYSCOMMAND()

>ON_WM_PAINT()

>ON_WM_QUERYDRAGICON()

>ON_BN_CLICKED(IDC_BUTTON2,OnOpen)

>ON_WM_TIMER()

>ON_BN_CLICKED(IDC_BUTTON1,OnSend)

>ON_BN_CLICKED(IDC_BUTTON3,OnButton3)

>ON_BN_CLICKED(IDC_ON_SETAXSIS,OnOnSetaxsis)

>ON_BN_CLICKED(IDC_ON_SETACSEL,OnOnSetacsel)

>ON_BN_CLICKED(IDC_ON_SETVELOS,OnOnSetvelos)

>ON_BN_CLICKED(IDC_ON_MOTROON,OnOnMotroon)

>ON_BN_CLICKED(IDC_ON_MOTOROFF,OnOnMotoroff)

>ON_BN_CLICKED(IDC_ON_MR,OnOnMr)

>ON_BN_CLICKED(IDC_ON_GO,OnOnGo)

//}}>AFX_MSG_MAP

>END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CSerialGateTestDlg messagehandlers

>BOOLCSerialGateTestDlg::OnInitDialog()

{

>CDialog::OnInitDialog();

//Add ">About..."menuitem tosystemmenu.

//IDM_ABOUTBOXmustbe in thesystemcommandrange.

>ASSERT((IDM_ABOUTBOX &0xFFF0) ==IDM_ABOUTBOX);

>ASSERT(IDM_ABOUTBOX <0xF000);

>CMenu*pSysMenu =GetSystemMenu(FALSE);

>if (>pSysMenu !=NULL)

{

>CStringstrAboutMenu;

>strAboutMenu.LoadString(IDS_ABOUTBOX);

>if (!>strAboutMenu.IsEmpty())

{

>pSysMenu->AppendMenu(MF_SEPARATOR);

>pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);

}

}

//Set theiconforthisdialog. Theframeworkdoesthisautomatically

//when theapplication'smainwindowisnot adialog

>SetIcon(m_hIcon,TRUE);//Setbigicon

>SetIcon(m_hIcon,FALSE);//Setsmallicon

//TODO:Addextrainitializationhere

>returnTRUE; //returnTRUEunlessyouset thefocus to a control

}

>voidCSerialGateTestDlg::OnSysCommand(UINTnID,LPARAMlParam)

{

>if ((>nID &0xFFF0) ==IDM_ABOUTBOX)

{

>CAboutDlgdlgAbout;

>dlgAbout.DoModal();

}

>else

{

>CDialog::OnSysCommand(nID,lParam);

}

}

//Ifyouadd aminimizebutton toyourdialog,youwillneed thecodebelow

// todraw theicon.ForMFCapplicationsusing thedocument/viewmodel,

//thisisautomaticallydoneforyouby theframework.

>voidCSerialGateTestDlg::OnPaint()

{

>if (>IsIconic())

{

>CPaintDCdc(this); //devicecontextfor painting

>SendMessage(WM_ICONERASEBKGND, (>WPARAM)dc.GetSafeHdc(), 0);

//Centericon inclientrectangle

>intcxIcon =GetSystemMetrics(SM_CXICON);

>intcyIcon =GetSystemMetrics(SM_CYICON);

>CRectrect;

>GetClientRect(&rect);

>int x = (>rect.Width() -cxIcon + 1) / 2;

>int y = (>rect.Height() -cyIcon + 1) / 2;

//Draw theicon

>dc.DrawIcon(x, y,m_hIcon);

}

>else

{

>CDialog::OnPaint();

}

}

// Thesystemcallsthis toobtain thecursor todisplaywhile theuserdrags

// theminimizedwindow.

>HCURSORCSerialGateTestDlg::OnQueryDragIcon()

{

>return (>HCURSOR)m_hIcon;

}

>voidCSerialGateTestDlg::OnOpen()

{

//TODO:Addyour controlnotificationhandlercodehere

>UpdateData(true);

>if(m_port == 0 ||m_rate == 0)

{

>MessageBox("Notcorrectdata","Error",MB_ICONERROR);

>return;;

}

>bool b =sg.Open(m_port,m_rate);

>if(b ==false)

{

>MessageBox("Can`t openPort","Error",MB_ICONERROR);

>return;;

}

>else

{

>MessageBox("Port openOK","Info",MB_ICONINFORMATION);

}

>SetTimer(1, 1000,NULL);

}

>voidCSerialGateTestDlg::OnTimer(UINTnIDEvent)

{

>if (>key==0)

{//TODO:Addyour messagehandlercodehere and/orcalldefault

>charbuff[128];

>intrcv =sg.Recv(buff,sizeof(buff));

>this->m_recievecontr.SetWindowText("");

>if(rcv > 0)

{

>for(int = 0; <rcv; ++)

>this->m_recieve +=buff[i];

>UpdateData(false);

}

}

>CDialog::OnTimer(nIDEvent);

}

>voidCSerialGateTestDlg::OnSend()

{

//TODO:Addyour controlnotificationhandlercodehere

>UpdateData(true);

>intlen =this->m_send.GetLength();

>if(len > 0)

{

>char*LocBuf =m_send.GetBuffer(128);

>sg.Send(LocBuf,len);

>m_send.ReleaseBuffer();

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

}

}

>voidCSerialGateTestDlg::OnButton3()

{

>UpdateData(true);

>intlen =this->m_send.GetLength();

>if(len > 0)

{

>charent=0x01;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

>char*LocBuf =m_send.GetBuffer(128);

>sg.Send(LocBuf,len);

>m_send.ReleaseBuffer();

}

}

>voidCSerialGateTestDlg::OnOnSetaxsis() //

{

>UpdateData(true);

>intpopytka=0;

//

>charctrlkey=0x01;

>char*ctrlkey2 = &>ctrlkey;

>sg.Send(ctrlkey2, 1);

>intlen=1;

>char*LocBuf =m_axsis.GetBuffer(128);

>sg.Send(LocBuf,len);

>m_send.ReleaseBuffer();

>CStringtp="tp";

>char*LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

}

>voidCSerialGateTestDlg::OnOnSetacsel() //

{

>UpdateData(true);

>CStringsa="sa";

>char*LocBuf2 =sa.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>sa.ReleaseBuffer();

>intlen =this->m_asel.GetLength();

>if(len > 0)

{

>char*LocBuf =m_asel.GetBuffer(128);

>sg.Send(LocBuf,len);

>m_asel.ReleaseBuffer();

//>enter

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

//>tl

>CStringtl="tl";

>char*LocBuf3 =tl.GetBuffer(128);

>sg.Send(LocBuf3, 2);

>tl.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

//>m_recievecontr.SetWindowText("0");

//>CEdit::Clear;

//>UpdateData(false);

}

}

>voidCSerialGateTestDlg::OnOnSetvelos()

{

>UpdateData(true);

>CStringsv="sv";

>char*LocBuf2 =sv.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>sv.ReleaseBuffer();

>intlen =this->m_vel.GetLength();

>if(len > 0)

{

>char*LocBuf =m_vel.GetBuffer(128);

>sg.Send(LocBuf,len);

>m_vel.ReleaseBuffer();

//>enter

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

//>ty

>CStringty="ty";

>char*LocBuf3 =ty.GetBuffer(128);

>sg.Send(LocBuf3, 2);

>ty.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

}

}

>voidCSerialGateTestDlg::OnOnMotroon()

{

>UpdateData(true); //

>CStringmn="mn";

>char*LocBuf2 =mn.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>mn.ReleaseBuffer();//TODO:Addyour controlnotificationhandlercodehere

//>enter

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

}

>voidCSerialGateTestDlg::OnOnMotoroff() //

{

>CStringmf="mf";

>char*LocBuf2 =mf.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>mf.ReleaseBuffer();//TODO:Addyour controlnotificationhandlercodehere

//>enter

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

}

>voidCSerialGateTestDlg::OnOnMr() //

{

>UpdateData(true);

>CStringmr="mr";

>char*LocBuf2 =mr.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>mr.ReleaseBuffer();

>intlen =this->m_gomr.GetLength();

>if(len > 0)

{

>char*LocBuf =m_gomr.GetBuffer(128);

>sg.Send(LocBuf,len);

>m_gomr.ReleaseBuffer();

//>enter

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

//>ty

>CStringtp="tp";

>char*LocBuf3 =tp.GetBuffer(128);

>sg.Send(LocBuf3, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

//>m_recieve.Clear();

}

}

>voidCSerialGateTestDlg::OnOnGo() //////////////////GO//////////////////////

{

>UpdateData(true);

>key=1;

>intaxis=0;

>intres;

>TP0:

//

>charctrlkey=0x01;

>char*ctrlkey2 = &>ctrlkey;

>sg.Send(ctrlkey2, 1);

>intlen=1;

>charaxsis0='0';

>char*axsis0_2 = &>axsis0;

>sg.Send(axsis0_2, 1);

>CStringtp="tp";

>char*LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

>Sleep(700); //

// //

>charbuff[128];

>intrcv =sg.Recv(buff,sizeof(buff));

>intelmbuff=rcv-1;

>buff[rcv]=0;

>CStringstr;

>for(int = 0; <rcv; ++)

>str +=buff[i];

>char* j =strchr(buff, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff, '-');

>res =atoi(j); //res

}

>CStringmraxsis0_2; // editaxsis0

>GetDlgItemText(IDC_MRAXSIS0,mraxsis0_2);

>intposnum0=atoi(mraxsis0_2);

>intposnum0_mr=res-posnum0/2;

>CStringmraxsis0_mr;

>mraxsis0_mr =>itoa(posnum0_mr,mraxsis0_mr.GetBuffer(10),10);

// //

>CStringmr="MA";

>char*LocBuf8 =mr.GetBuffer(128);

>sg.Send(LocBuf8, 2);

>mr.ReleaseBuffer();

>len=mraxsis0_mr.GetLength();

>char*LocBuf9 =mraxsis0_mr.GetBuffer(128);

>sg.Send(LocBuf9,len);

>mraxsis0_mr.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>intgto0=posnum0_mr;

>intposicino00=res;

>Sleep(400);

>TP1:

//

>sg.Send(ctrlkey2, 1);

>len=1;

>charaxsis1='1';

>char*axsis1_2 = &>axsis1;

>sg.Send(axsis1_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(700);

//

// //

>charbuff2[128];

>rcv =sg.Recv(buff2,sizeof(buff2));

>elmbuff=rcv-1;

>buff2[rcv]=0;

>CStringstr2;

>for(i = 0; <rcv; ++)

>str2 +=buff2[i];

j =strchr(buff2, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff2, '-');

>res =atoi(j); //res

}

>CStringmraxsis1_2; // editaxsis0

>GetDlgItemText(IDC_MRAXSIS1,mraxsis1_2);

>intposnum1=atoi(mraxsis1_2);

>intposnum1_mr=res-posnum1/2;

>CStringmraxsis1_mr;

>mraxsis1_mr =>itoa(posnum1_mr,mraxsis1_mr.GetBuffer(10),10);

// //

>mr="MA";

>LocBuf8 =mr.GetBuffer(128);

>sg.Send(LocBuf8, 2);

>mr.ReleaseBuffer();

>len=mraxsis1_mr.GetLength();

>LocBuf9 =mraxsis1_mr.GetBuffer(128);

>sg.Send(LocBuf9,len);

>mraxsis1_mr.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>intgto1=posnum1_mr;

>intposicino01=res;

>Sleep(130);

>intpos01=gto1;

>intpos00=gto0;

>intmodul;

>do

{

>Sleep(400);

//

>sg.Send(ctrlkey2, 1);

>sg.Send(axsis0_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(800); //

// //

>CStringstr;

>charbuff[128];

>rcv =sg.Recv(buff,sizeof(buff));

>if(rcv > 0)

>elmbuff=rcv-1;

>buff[rcv]=0;

>for(int = 0; <rcv; ++)

>str +=buff[i];

j =strchr(buff, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff, '-');

>res =atoi(j); //res

}

}//

>modul=res-gto0;

>if (>modul<0)modul=-modul;

}while (>modul>20);

>do

{

>Sleep(800);

//

>sg.Send(ctrlkey2, 1);

>sg.Send(axsis1_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(400); //

// //

>charbuff[128];

>rcv =sg.Recv(buff,sizeof(buff));

>elmbuff=rcv-1;

>buff[rcv]=0;

>CStringstr;

>for(int = 0; <rcv; ++)

>str +=buff[i];

j =strchr(buff, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff, '-');

>res =atoi(j); //res

}//

>modul=res-gto1;

>if (>modul<0)modul=-modul;

}>while (>modul>20);

>MessageBox("peremecheno","ok",MB_ICONINFORMATION);

//>UpdateData(false);

////////////// ////////////////

>inttape0=0;

>inttape1=0;

>inttape0t=0; //

>inttape1t=0;

//>CStringtapeaxsis0_1;

//>GetDlgItemText(IDC_TAPEAXSIS0,tapeaxsis0_1);

//>tape0=atoi(tapeaxsis0_1);

>CStringtapeaxsis1_1;

>GetDlgItemText(IDC_TAPEAXSIS1,tapeaxsis1_1);

>tape1=atoi(tapeaxsis1_1);

// 1//

>while (>tape1t<tape1)

{

//> 0//

//>UpdateData(false);

//>CStringmraxsis0_mr;

//>mraxsis0_mr =>itoa(posnum0_mr,mraxsis0_mr.GetBuffer(10),10);

//>this->m_pastcontrol.SetWindowText("");

//>CStringtape1tstr;

//>tape1tstr =>itoa(tape1t,tape1tstr.GetBuffer(10),10);

//>this->m_past=tape1tstr;

>tape1t++;

//

>charctrlkey=0x01;

>char*ctrlkey2 = &>ctrlkey;

>sg.Send(ctrlkey2, 1);

>intlen=1;

>charaxsis0='0';

>char*axsis0_2 = &>axsis0;

>sg.Send(axsis0_2, 1);

>CStringtp="tp";

>char*LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>charent=0x0D;

>char*ent2 = &>ent;

>sg.Send(ent2, 1);

>Sleep(600); //

// //

>charbuff1[128];

>intrcv =sg.Recv(buff1,sizeof(buff1));

>buff1[rcv]=0;

>char* j =strchr(buff1, '+');

>intres =atoi(j);

>if (>j==0)

{

j =strchr(buff1, '-');

>res =atoi(j); //res

}

>CStringmraxsis0_2; // editaxsis0

>GetDlgItemText(IDC_MRAXSIS0,mraxsis0_2);

>posnum0=atoi(mraxsis0_2);

>posnum0_mr=posicino00+posnum0/2; //

>CStringmraxsis0_mr;

>mraxsis0_mr =>itoa(posnum0_mr,mraxsis0_mr.GetBuffer(10),10);

// //

>CStringmr="MA";

>char*LocBuf8 =mr.GetBuffer(128);

>sg.Send(LocBuf8, 2);

>mr.ReleaseBuffer();

>len=mraxsis0_mr.GetLength();

>char*LocBuf9 =mraxsis0_mr.GetBuffer(128);

>sg.Send(LocBuf9,len);

>mraxsis0_mr.ReleaseBuffer();//enter

>sg.Send(ent2, 1);

>gto0=posnum0_mr;

// //

>CStringinputfile;

>GetDlgItemText(IDC_DATAEXCHANGE,inputfile);

>CStringoutputfile;

>GetDlgItemText(IDC_DATAEXCHANGE2,outputfile);

>CStringstrinput;

>CStringstroutput;

>CStdioFileFileInPut(inputfile,CFile::shareDenyNone);

>CStdioFileFileOutPut(outputfile,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite|CFile::shareDenyNone);

>FileInPut.SeekToEnd();

>intpositionFileInPut1=FileInPut.GetPosition();

// //

>Sleep(300);

>do

{

>Sleep(400);

//

>sg.Send(ctrlkey2, 1);

>sg.Send(axsis0_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(800); //

// //

>CStringstr;

>charbuff[128];

>rcv =sg.Recv(buff,sizeof(buff));

>if(rcv > 0)

{

>elmbuff=rcv-1;

>buff[rcv]=0;

>for(int = 0; <rcv; ++)

>str +=buff[i];

j =strchr(buff, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff, '-');

>res =atoi(j); //res

}

}//

>modul=res-gto0;

>if (>modul<0)modul=-modul;

}while (>modul>20);

// //

// //

>FileInPut.SeekToEnd();

>FileOutPut.SeekToEnd();

>intpositionFileInPut2=FileInPut.GetPosition();

>FileInPut.Seek(positionFileInPut1,CFile::begin);

>CStringspace=" ";

//>charbuffstr[128];

>for (>intpositionFileInPutCurrent=FileInPut.GetPosition();positionFileInPutCurrent<positionFileInPut2;positionFileInPutCurrent=FileInPut.GetPosition())

{

//>FileOutPut.ReadString(stroutput);

>FileInPut.ReadString(strinput);

>char*buffstr =strinput.GetBuffer(128);

>intlenstr=strinput.GetLength();

>buffstr[lenstr]=0;

>char* j =strchr(buffstr, ',');

>stroutput=j+1;

>FileOutPut.WriteString(stroutput);

>FileOutPut.WriteString(space);

}

// 1//

>FileOutPut.WriteString("rn");

// //

>sg.Send(ctrlkey2, 1);

>len=1;

>charaxsis1='1';

>char*axsis1_2 = &>axsis1;

>sg.Send(axsis1_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(300); //

// //

>charbuff4[128];

>rcv =sg.Recv(buff4,sizeof(buff4));

>buff4[rcv]=0;

j =strchr(buff4, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff4, '-');

>res =atoi(j); //res

}

>CStringmraxsis1_2; // editaxsis0

>GetDlgItemText(IDC_MRAXSIS1,mraxsis1_2);

>intposnum1=atoi(mraxsis1_2);

>intposnum1_mr=pos01+tape1t*posnum1/tape1;

>CStringmraxsis1_mr;

>mraxsis1_mr =>itoa(posnum1_mr,mraxsis1_mr.GetBuffer(10),10);

>gto1=posnum1_mr;

// //

>mr="MA";

>LocBuf8 =mr.GetBuffer(128);

>sg.Send(LocBuf8, 2);

>mr.ReleaseBuffer();

>len=mraxsis1_mr.GetLength();

>LocBuf9 =mraxsis1_mr.GetBuffer(128);

>sg.Send(LocBuf9,len);

>mraxsis1_mr.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(300);

>do

{

>Sleep(400);

//

>sg.Send(ctrlkey2, 1);

>len=1;

>charaxsis1='1';

>char*axsis1_2 = &>axsis1;

>sg.Send(axsis1_2, 1);

>sg.Send(ctrlkey2, 1);

>sg.Send(axsis1_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(800); //

// //

>CStringstr;

>charbuff[128];

>rcv =sg.Recv(buff,sizeof(buff));

>if(rcv > 0)

{

>elmbuff=rcv-1;

>buff[rcv]=0;

>for(int = 0; <rcv; ++)

>str +=buff[i];

j =strchr(buff, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff, '-');

>res =atoi(j); //res

}

}//

>modul=res-gto1;

>if (>modul<0)modul=-modul;

}while (>modul>20);

// //

// //

>Sleep(300);

>ctrlkey=0x01;

>ctrlkey2 = &>ctrlkey;

>sg.Send(ctrlkey2, 1);

>len=1;

>axsis0='0';

>axsis0_2 = &>axsis0;

>sg.Send(axsis0_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>ent=0x0D;

>ent2 = &>ent;

>sg.Send(ent2, 1);

>Sleep(300); //

// //

>charbuff7[128];

>rcv =sg.Recv(buff7,sizeof(buff7));

>elmbuff=rcv-1;

>buff7[rcv]=0;

>CStringstr7;

>for(i = 0; <rcv; ++)

>str7 +=buff7[i];

j =strchr(buff7, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff7, '-');

>res =atoi(j); //res

}

// editaxsis0

>GetDlgItemText(IDC_MRAXSIS0,mraxsis0_2);

>posnum0=atoi(mraxsis0_2);

>posnum0_mr=pos00; //

>mraxsis0_mr =>itoa(posnum0_mr,mraxsis0_mr.GetBuffer(10),10);

// //

>mr="MA";

>LocBuf8 =mr.GetBuffer(128);

>sg.Send(LocBuf8, 2);

>mr.ReleaseBuffer();

>len=mraxsis0_mr.GetLength();

>LocBuf9 =mraxsis0_mr.GetBuffer(128);

>sg.Send(LocBuf9,len);

>mraxsis0_mr.ReleaseBuffer();//enter

>sg.Send(ent2, 1);

>gto0=pos00;

>Sleep(300);

>do

{

>Sleep(300);

//

>sg.Send(ctrlkey2, 1);

>sg.Send(axsis0_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(300); //

// //

>CStringstr8;

>charbuff8[128];

>rcv =sg.Recv(buff8,sizeof(buff8));

>if(rcv > 0)

{

>elmbuff=rcv-1;

>buff8[rcv]=0;

>for(int = 0; <rcv; ++)

>str8 +=buff8[i];

j =strchr(buff8, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff8, '-');

>res =atoi(j); //res

}

}//

>modul=res-gto0;

>if (>modul<0)modul=-modul;

}while (>modul>20);// //

>UpdateData(true);

// 1//

}

/////////////////////////////////////////////

// //

/////////////////////////////////////////////

>Tp0:

//

>sg.Send(ctrlkey2, 1);

>len=1;

>axsis0='0';

>axsis0_2 = &>axsis0;

>sg.Send(axsis0_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(300); //

// //

>posnum0_mr=posicino00;

>mraxsis0_mr =>itoa(posnum0_mr,mraxsis0_mr.GetBuffer(10),10);

// //

>mr="MA";

>char*LocBuf11 =mr.GetBuffer(128);

>sg.Send(LocBuf11, 2);

>mr.ReleaseBuffer();

>len=mraxsis0_mr.GetLength();

>char*LocBuf14 =mraxsis0_mr.GetBuffer(128);

>sg.Send(LocBuf14,len);

>mraxsis0_mr.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(200);

>UpdateData(true);

>gto0=posicino00;

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

>Sleep(300);

>charbuff10[128];

>rcv =sg.Recv(buff10,sizeof(buff10));

>Tp1:

//

>sg.Send(ctrlkey2, 1);

>len=1;

>axsis1='1';

>axsis1_2 = &>axsis1;

>sg.Send(axsis1_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(300);

//

// //

>rcv =sg.Recv(buff10,sizeof(buff10));

>posnum1_mr=posicino01;

>mraxsis1_mr =>itoa(posnum1_mr,mraxsis1_mr.GetBuffer(10),10);

>gto1=posicino01;

// //

>mr="MA";

>LocBuf8 =mr.GetBuffer(128);

>sg.Send(LocBuf8, 2);

>mr.ReleaseBuffer();

>len=mraxsis1_mr.GetLength();

>LocBuf9 =mraxsis1_mr.GetBuffer(128);

>sg.Send(LocBuf9,len);

>mraxsis1_mr.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>UpdateData(true);

>Sleep(130);

>do

{

>Sleep(300);

//

>sg.Send(ctrlkey2, 1);

>sg.Send(axsis0_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(300); //

// //

>CStringstr;

>charbuff[128];

>rcv =sg.Recv(buff,sizeof(buff));

>if(rcv > 0)

{

>elmbuff=rcv-1;

>buff[rcv]=0;

>for(int = 0; <rcv; ++)

>str +=buff[i];

j =strchr(buff, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff, '-');

>res =atoi(j); //res

}

}//

>modul=res-gto0;

>if (>modul<0)modul=-modul;

}while (>modul>40);

>do

{

>Sleep(400);

//

>sg.Send(ctrlkey2, 1);

>sg.Send(axsis1_2, 1);

>tp="tp";

>LocBuf2 =tp.GetBuffer(128);

>sg.Send(LocBuf2, 2);

>tp.ReleaseBuffer();

//>enter

>sg.Send(ent2, 1);

>Sleep(300); //

// //

>charbuff[128];

>rcv =sg.Recv(buff,sizeof(buff));

>elmbuff=rcv-1;

>buff[rcv]=0;

>CStringstr;

>for(int = 0; <rcv; ++)

>str +=buff[i];

j =strchr(buff, '+');

>res =atoi(j);

>if (>j==0)

{

j =strchr(buff, '-');

>res =atoi(j); //res

}//

>modul=res-gto1;

>if (>modul<0)modul=-modul;

}>while (>modul>20);

>key=0;

////////////////////////////////////////////

}

>SerialGate.dll

>SerialGate.cpp:

 

#>include ">stdafx.h"

#>include ">SerialGate.h"

#>include <>iostream>

#>include <>Winspool.h>

>BOOLAPIENTRYDllMain(HANDLEhModule,

>DWORDul_reason_for_call,

>LPVOIDlpReserved

)

{

>switch (>ul_reason_for_call)

{

caseDLL_PROCESS_ATTACH:

caseDLL_THREAD_ATTACH:

caseDLL_THREAD_DETACH:

caseDLL_PROCESS_DETACH:

break;

}

>returnTRUE;

}

>extern "" __>declspec (>dllexport)boolSerialGate::Open(intport,intbaud)

{

charCOM_string[20];

sprintf(COM_string,"\.COM%d",port);

m_hFile =CreateFile(COM_string,GENERIC_READ|GENERIC_WRITE, 0,NULL,

>OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

if(m_hFile ==INVALID_HANDLE_VALUE)

{

returnfalse;

}

DCBdcb;

GetCommState(m_hFile, &>dcb);

COMMTIMEOUTSCommTimeOuts;

CommTimeOuts.ReadIntervalTimeout =MAXDWORD;

CommTimeOuts.ReadTotalTimeoutMultiplier = 0;

CommTimeOuts.ReadTotalTimeoutConstant = 0;

CommTimeOuts.WriteTotalTimeoutMultiplier = 0;

CommTimeOuts.WriteTotalTimeoutConstant = 1000;

SetCommTimeouts(m_hFile, &>CommTimeOuts);

dcb.ByteSize = 8;

dcb.Parity =NOPARITY;

dcb.StopBits =ONESTOPBIT;

dcb.BaudRate =baud;

SetCommState(m_hFile, &>dcb);

this->state =true;

returntrue;

}

>extern "" __>declspec (>dllexport)SerialGate::SerialGate()

{

this->state =false;

}

>extern "" __>declspec (>dllexport)SerialGate::~SerialGate()

{

this->Close();

}

>extern "" __>declspec (>dllexport)voidSerialGate::Close()

{

this->state =false;

CloseHandle(m_hFile);

}

>extern "" __>declspec (>dllexport)voidSerialGate::Clean()

{

if(!state)

return;

PurgeComm(m_hFile,PURGE_TXCLEAR|PURGE_RXCLEAR);

}

>extern "" __>declspec (>dllexport)intSerialGate::Send(char*buff,intszBuff)

{

if(!state)

return 0;

if(buff ==NULL ||szBuff <= 0)

{

return 0;

}

DWORDlpdwBytesWrittens = 0;

WriteFile(m_hFile,buff,szBuff, &>lpdwBytesWrittens,NULL);

returnlpdwBytesWrittens;

}

>extern "" __>declspec (>dllexport)intSerialGate::Recv(char*buff,intszBuff)

{

if(!state)

return 0;

if(buff ==NULL ||szBuff <= 0)

{

return 0;

}

DWORDdwBytesRead = 0;

ReadFile(m_hFile,buff,szBuff, &>dwBytesRead,NULL);

returndwBytesRead;

}

>extern "" __>declspec (>dllexport)voidSerialGate::SetLine(OUT_LINES_NAMEln,bool state)

{

if(!state)

return ;

unsignedcharvalue;

if(ln ==DTR)

{

if(state)

value = 6;

else

value = 5;

}

if(ln ==RTS)

{

if(state)

value = 4;

else

value = 3;

}

EscapeCommFunction(m_hFile,value);

}

>extern "" __>declspec (>dllexport)boolSerialGate::GetLine(IN_LINES_NAMEln)

{

if(!state)

return 0;

unsignedlongul = 0;

GetCommModemStatus(m_hFile, &>ul);

if(ul ==0x10 &&ln ==CTS)

{

returntrue;

}

if(ul ==0x20 &&ln ==DSR)

{

returntrue;

}

if(ul ==0x40 &&ln ==RING)

{

returntrue;

}

if(ul ==0x80 &&ln ==RLSD)

{

returntrue;

}

returnfalse;

}

>extern "" __>declspec (>dllexport)voidSerialGate::GetPortsInfo(PortInfo*pi)

{

>DWORDPorts_MemSize = 0;

>DWORDPorts_Count = 0;

>BYTE*lpPorts =NULL;

//>GettingPorts_MemSizevalue...

>EnumPorts(NULL,

1,

>lpPorts,

0,

&>Ports_MemSize,

&>Ports_Count);

//>GettinglpPorts...

>lpPorts = newBYTE[Ports_MemSize];

>EnumPorts(NULL,

1,

>lpPorts,

>Ports_MemSize,

&>Ports_MemSize,

&>Ports_Count);

//>FormingListOfPorts...

>DWORDdw;

>TCHARstr[8];

>chartemp[4];

>intport = -1;

>PORT_INFO_1 *>pPortInfo;

>pPortInfo = (>PORT_INFO_1 *)>lpPorts;

>intcounter = 0;

>boolav =false;

>for (>dw = 0;dw <Ports_Count;dw++)

{

>lstrcpyn(str,pPortInfo->pName, 4);

>str[4] = 0;

>if (>lstrcmpi(str, ">com") == 0)

{

//>printf("%sn",pPortInfo->pName);

memset(temp, '[>fde_1327656973_7735213966_1327656974_6697731425_5164]',sizeof(temp));

temp[0] =pPortInfo->pName[3];

if(pPortInfo->pName[4]!= ':' &&pPortInfo->pName[4]!= '[>fde_1327656973_7735213966_1327656974_9657372164_4263]')

temp[1] =pPortInfo->pName[4];

if(pPortInfo->pName[5]!= ':' &&pPortInfo->pName[5]!= '[>fde_1327656973_7735213966_1327656974_4166377592_1087]')

temp[2] =pPortInfo->pName[5];

port =atoi(temp);

//>printf("%dn",port);

charCOM_string[20];

sprintf(COM_string,"\.COM%d",port);

HANDLE h =CreateFile(COM_string,GENERIC_READ|GENERIC_WRITE, 0,NULL,

OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

if(h ==INVALID_HANDLE_VALUE)

{

//>returnfalse;

av =false;

}

else

{

av =true;

CloseHandle(h);

}

pi->p[counter].Id =port;

pi->p[counter].Availbl =av;

counter++;

}

>pPortInfo++;

}

>pi->koll =counter;

>delete []lpPorts;

}

>SerialGate.dll

>SerialGate.h:

#>include <>windows.h>

#>defineMAX_WIN_PORT 255

>struct Port

{

unsignedcharId;

boolAvailbl;

};

>structPortInfo

{

Portp[MAX_WIN_PORT];

unsignedcharkoll;

};

>extern ""class __>declspec (>dllexport)SerialGate

{

public:

enumIN_LINES_NAME {>CTS,DSR,RING,RLSD};

enumOUT_LINES_NAME {>DTR,RTS};

SerialGate();

~>SerialGate();

boolOpen(intport,intbaud);

intSend(char*buff,intszBuff);

intRecv(char*buff,intszBuff);

voidSetLine(OUT_LINES_NAMEln,bool state);

boolGetLine(IN_LINES_NAMEln);

voidGetPortsInfo(PortInfo*pi);

voidClose();

voidClean();

private:

HANDLEm_hFile;

bool state;

};


| 2 2

:

  • :
    1 >- 2 Գ
  • :
    ̳ >
  • :
    ̳
  • :
    ̳ -
  • : 䳿
    >̳ > > > > > .