на тему рефераты
 
Главная | Карта сайта
на тему рефераты
РАЗДЕЛЫ

на тему рефераты
ПАРТНЕРЫ

на тему рефераты
АЛФАВИТ
... А Б В Г Д Е Ж З И К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я

на тему рефераты
ПОИСК
Введите фамилию автора:


Курсовая работа: Применение автоматизированного адаптивного интерферометра для исследования наносмещений микрообъектов


//}}AFX_VIRTUAL

// Implementation

protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

{

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

// No message handlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

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

// CSerialGateTestDlg dialog

CSerialGateTestDlg::CSerialGateTestDlg(CWnd* pParent /*=NULL*/)

: CDialog(CSerialGateTestDlg::IDD, pParent)

{

//{{AFX_DATA_INIT(CSerialGateTestDlg)

m_port = 5;

m_rate = 9600;

m_recieve = _T("");

m_send = _T("");

m_axsis = _T("");

m_vel = _T("");

m_asel = _T("");

m_gomr = _T("");

m_mraxsis0 = _T("");

m_mraxsis1 = _T("");

m_tapeaxsis0 = _T("");

m_tapeaxsis1 = _T("");

m_dataininput = _T("");

m_dataoutput = _T("");

m_past = _T("");

//}}AFX_DATA_INIT

// Note that LoadIcon does not require a subsequent DestroyIcon in Win32

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

}

void CSerialGateTestDlg::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 message handlers

BOOL CSerialGateTestDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.

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

ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);

if (pSysMenu != NULL)

{

CString strAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if (!strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

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

}

}

// Set the icon for this dialog. The framework does this automatically

// when the application's main window is not a dialog

SetIcon(m_hIcon, TRUE);// Set big icon

SetIcon(m_hIcon, FALSE);// Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control

}

void CSerialGateTestDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

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

{

CAboutDlg dlgAbout;

dlgAbout.DoModal();

}

else

{

CDialog::OnSysCommand(nID, lParam);

}

}

// If you add a minimize button to your dialog, you will need the code below

// to draw the icon. For MFC applications using the document/view model,

// this is automatically done for you by the framework.

void CSerialGateTestDlg::OnPaint()

{

if (IsIconic())

{

CPaintDC dc(this); // device context for painting

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

// Center icon in client rectangle

int cxIcon = GetSystemMetrics(SM_CXICON);

int cyIcon = GetSystemMetrics(SM_CYICON);

CRect rect;

GetClientRect(&rect);

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

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

// Draw the icon

dc.DrawIcon(x, y, m_hIcon);

}

else

{

CDialog::OnPaint();

}

}

// The system calls this to obtain the cursor to display while the user drags

// the minimized window.

HCURSOR CSerialGateTestDlg::OnQueryDragIcon()

{

return (HCURSOR) m_hIcon;

}

void CSerialGateTestDlg::OnOpen()

{

// TODO: Add your control notification handler code here

UpdateData(true);

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

{

MessageBox("Not correct data","Error", MB_ICONERROR);

return;;

}

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

if(b == false)

{

MessageBox("Can`t open Port","Error", MB_ICONERROR);

return;;

}

else

{

MessageBox("Port open OK","Info", MB_ICONINFORMATION);

}

SetTimer(1, 1000, NULL);

}

void CSerialGateTestDlg::OnTimer(UINT nIDEvent)

{

if (key==0)

{// TODO: Add your message handler code here and/or call default

char buff[128];

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

this->m_recievecontr.SetWindowText("");

if(rcv > 0)

{

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

this->m_recieve += buff[i];

UpdateData(false);

}

}

CDialog::OnTimer(nIDEvent);

}

void CSerialGateTestDlg::OnSend()

{

// TODO: Add your control notification handler code here

UpdateData(true);

int len = this->m_send.GetLength();

if(len > 0)

{

char* LocBuf = m_send.GetBuffer(128);

sg.Send(LocBuf, len);

m_send.ReleaseBuffer();

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

}

}

void CSerialGateTestDlg::OnButton3()

{

UpdateData(true);

int len = this->m_send.GetLength();

if(len > 0)

{

char ent=0x01;

char* ent2 = &ent;

sg.Send(ent2, 1);

char* LocBuf = m_send.GetBuffer(128);

sg.Send(LocBuf, len);

m_send.ReleaseBuffer();

}

}

void CSerialGateTestDlg::OnOnSetaxsis() //выбор оси

{

UpdateData(true);

int popytka=0;

//изменение активного мотора

char ctrlkey=0x01;

char* ctrlkey2 = &ctrlkey;

sg.Send(ctrlkey2, 1);

int len=1;

char* LocBuf = m_axsis.GetBuffer(128);

sg.Send(LocBuf, len);

m_send.ReleaseBuffer();

CString tp="tp";

char* LocBuf2 = tp.GetBuffer(128);

sg.Send(LocBuf2, 2);

tp.ReleaseBuffer();

//enter

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

}

void CSerialGateTestDlg::OnOnSetacsel() //установить ускорение

{

UpdateData(true);

CString sa="sa";

char* LocBuf2 = sa.GetBuffer(128);

sg.Send(LocBuf2, 2);

sa.ReleaseBuffer();

int len = this->m_asel.GetLength();

if(len > 0)

{

char* LocBuf = m_asel.GetBuffer(128);

sg.Send(LocBuf, len);

m_asel.ReleaseBuffer();

//enter

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

//проверкаtl

CString tl="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);

}

}

void CSerialGateTestDlg::OnOnSetvelos()

{

UpdateData(true);

CString sv="sv";

char* LocBuf2 = sv.GetBuffer(128);

sg.Send(LocBuf2, 2);

sv.ReleaseBuffer();

int len = this->m_vel.GetLength();

if(len > 0)

{

char* LocBuf = m_vel.GetBuffer(128);

sg.Send(LocBuf, len);

m_vel.ReleaseBuffer();

//enter

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

//проверкаty

CString ty="ty";

char* LocBuf3 = ty.GetBuffer(128);

sg.Send(LocBuf3, 2);

ty.ReleaseBuffer();

//enter

sg.Send(ent2, 1);

}

}

void CSerialGateTestDlg::OnOnMotroon()

{

UpdateData(true); //включить мотор

CString mn="mn";

char* LocBuf2 = mn.GetBuffer(128);

sg.Send(LocBuf2, 2);

mn.ReleaseBuffer();// TODO: Add your control notification handler code here

//enter

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

}

void CSerialGateTestDlg::OnOnMotoroff() //выключить мотор

{

CString mf="mf";

char* LocBuf2 = mf.GetBuffer(128);

sg.Send(LocBuf2, 2);

mf.ReleaseBuffer();// TODO: Add your control notification handler code here

//enter

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

}

void CSerialGateTestDlg::OnOnMr() //перемещение

{

UpdateData(true);

CString mr="mr";

char* LocBuf2 = mr.GetBuffer(128);

sg.Send(LocBuf2, 2);

mr.ReleaseBuffer();

int len = this->m_gomr.GetLength();

if(len > 0)

{

char* LocBuf = m_gomr.GetBuffer(128);

sg.Send(LocBuf, len);

m_gomr.ReleaseBuffer();

//enter

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

//проверкаty

CString tp="tp";

char* LocBuf3 = tp.GetBuffer(128);

sg.Send(LocBuf3, 2);

tp.ReleaseBuffer();

//enter

sg.Send(ent2, 1);

//m_recieve.Clear();

}

}

void CSerialGateTestDlg::OnOnGo() //////////////////кнопка GO//////////////////////

{

UpdateData(true);

key=1;

int axis=0;

int res;

TP0:

//изменение активного мотора

char ctrlkey=0x01;

char* ctrlkey2 = &ctrlkey;

sg.Send(ctrlkey2, 1);

int len=1;

char axsis0='0';

char* axsis0_2 = &axsis0;

sg.Send(axsis0_2, 1);

CString tp="tp";

char* LocBuf2 = tp.GetBuffer(128);

sg.Send(LocBuf2, 2);

tp.ReleaseBuffer();

//enter

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

Sleep(700); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

char buff[128];

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

int elmbuff=rcv-1;

buff[rcv]=0;

CString str;

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

str += buff[i];

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

res = atoi(j);

if (j==0)

{

j = strchr(buff, '-');

res = atoi(j); //в res здесь храниться текущие положение

}

CString mraxsis0_2; //сюда записывается занчение е окошка edit axsis0

GetDlgItemText(IDC_MRAXSIS0,mraxsis0_2);

int posnum0=atoi(mraxsis0_2);

int posnum0_mr=res-posnum0/2;

CString mraxsis0_mr;

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

//выполним перемещение на нулевую позицию//

CString mr="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);

int gto0=posnum0_mr;

int posicino00=res;

Sleep(400);

TP1:

//изменение активного мотора

 

sg.Send(ctrlkey2, 1);

 len=1;

char axsis1='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);

//организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

char buff2[128];

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

 elmbuff=rcv-1;

buff2[rcv]=0;

CString str2;

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

str2 += buff2[i];

 j = strchr(buff2, '+');

res = atoi(j);

if (j==0)

{

j = strchr(buff2, '-');

res = atoi(j); //в res здесь храниться текущие положение

}

CString mraxsis1_2; //сюда записывается занчение е окошка edit axsis0

GetDlgItemText(IDC_MRAXSIS1,mraxsis1_2);

int posnum1=atoi(mraxsis1_2);

int posnum1_mr=res-posnum1/2;

CString mraxsis1_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);

int gto1=posnum1_mr;

int posicino01=res;

Sleep(130);

int pos01=gto1;

int pos00=gto0;

int modul;

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); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

CString str;

char buff[128];

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

if(rcv > 0)

elmbuff=rcv-1;

buff[rcv]=0;

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

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); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

char buff[128];

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

elmbuff=rcv-1;

buff[rcv]=0;

CString str;

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

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);

//////////////организуем сканирование////////////////

int tape0=0;

int tape1=0;

int tape0t=0; //текущий проход

int tape1t=0;

//CString tapeaxsis0_1;

//GetDlgItemText(IDC_TAPEAXSIS0,tapeaxsis0_1);

//tape0=atoi(tapeaxsis0_1);

CString tapeaxsis1_1;

GetDlgItemText(IDC_TAPEAXSIS1,tapeaxsis1_1);

tape1=atoi(tapeaxsis1_1);

//перемещение по оси 1//

while (tape1t<tape1)

{

//премещение по оси 0//

//UpdateData(false);

//CString mraxsis0_mr;

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

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

//CString tape1tstr;

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

//this->m_past=tape1tstr;

tape1t++;

//изменение активного мотора

char ctrlkey=0x01;

char* ctrlkey2 = &ctrlkey;

sg.Send(ctrlkey2, 1);

int len=1;

char axsis0='0';

char* axsis0_2 = &axsis0;

sg.Send(axsis0_2, 1);

CString tp="tp";

char* LocBuf2 = tp.GetBuffer(128);

sg.Send(LocBuf2, 2);

tp.ReleaseBuffer();

//enter

char ent=0x0D;

char* ent2 = &ent;

sg.Send(ent2, 1);

Sleep(600); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

char buff1[128];

int rcv = sg.Recv(buff1, sizeof(buff1));

buff1[rcv]=0;

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

int res = atoi(j);

if (j==0)

{

j = strchr(buff1, '-');

res = atoi(j); //в res здесь храниться текущие положение

}

CString mraxsis0_2; //сюда записывается занчение е окошка edit axsis0

GetDlgItemText(IDC_MRAXSIS0,mraxsis0_2);

posnum0=atoi(mraxsis0_2);

posnum0_mr=posicino00+posnum0/2; //перемещаемся вперед

CString mraxsis0_mr;

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

//выполним перемещение//

CString mr="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;

//считывание данных из файла//

CString inputfile;

GetDlgItemText(IDC_DATAEXCHANGE, inputfile);

CString outputfile;

GetDlgItemText(IDC_DATAEXCHANGE2, outputfile);

CString strinput;

CString stroutput;

CStdioFile FileInPut(inputfile, CFile::shareDenyNone);

CStdioFile FileOutPut(outputfile, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite|CFile::shareDenyNone);

FileInPut.SeekToEnd();

int positionFileInPut1=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); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

CString str;

char buff[128];

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

if(rcv > 0)

{

elmbuff=rcv-1;

buff[rcv]=0;

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

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();

int positionFileInPut2=FileInPut.GetPosition();

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

CString space=" ";

//char buffstr[128];

for (int positionFileInPutCurrent=FileInPut.GetPosition(); positionFileInPutCurrent<positionFileInPut2; positionFileInPutCurrent=FileInPut.GetPosition())

{

//FileOutPut.ReadString(stroutput);

FileInPut.ReadString(strinput);

char* buffstr = strinput.GetBuffer(128);

int lenstr=strinput.GetLength();

buffstr[lenstr]=0;

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

stroutput=j+1;

FileOutPut.WriteString(stroutput);

FileOutPut.WriteString(space);

}

//перемещение по оси 1//

FileOutPut.WriteString("\r\n");

//изменение активного мотора//

sg.Send(ctrlkey2, 1);

 len=1;

char axsis1='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); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

char buff4[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 здесь храниться текущие положение

}

CString mraxsis1_2; //сюда записывается занчение е окошка edit axsis0

GetDlgItemText(IDC_MRAXSIS1,mraxsis1_2);

int posnum1=atoi(mraxsis1_2);

int posnum1_mr=pos01+tape1t*posnum1/tape1;

CString mraxsis1_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;

char axsis1='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); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

CString str;

char buff[128];

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

if(rcv > 0)

{

elmbuff=rcv-1;

buff[rcv]=0;

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

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; i< rcv; i++)

str7 += buff7[i];

j = strchr(buff7, '+');

res = atoi(j);

if (j==0)

{

j = strchr(buff7, '-');

res = atoi(j); //в res здесь храниться текущие положение

}

 //сюда записывается занчение е окошка edit axsis0

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); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

CString str8;

char buff8[128];

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

if(rcv > 0)

{

elmbuff=rcv-1;

buff8[rcv]=0;

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

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);

char buff10[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); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

CString str;

char buff[128];

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

if(rcv > 0)

{

elmbuff=rcv-1;

buff[rcv]=0;

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

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); //организуем паузу чтобы контроллер успел ответить

//считаем текущую позицию//

char buff[128];

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

elmbuff=rcv-1;

buff[rcv]=0;

CString str;

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

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>

BOOL APIENTRY DllMain( HANDLE hModule,

 DWORD ul_reason_for_call,

 LPVOID lpReserved

                                                )

{

 switch (ul_reason_for_call)

         {

                   case DLL_PROCESS_ATTACH:

                   case DLL_THREAD_ATTACH:

                   case DLL_THREAD_DETACH:

                   case DLL_PROCESS_DETACH:

                            break;

 }

 return TRUE;

}

extern "C" __declspec (dllexport) bool SerialGate::Open(int port, int baud)

{

         char COM_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)

         {                                   

                   return false;

         }

         DCB dcb;

         GetCommState(m_hFile, &dcb);

         COMMTIMEOUTS CommTimeOuts;

         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;

         return true;

}

extern "C" __declspec (dllexport) SerialGate::SerialGate()

{

         this->state = false;

}

extern "C" __declspec (dllexport) SerialGate::~SerialGate()

{

         this->Close();

}

extern "C" __declspec (dllexport) void SerialGate::Close()

{

         this->state = false;

         CloseHandle(m_hFile);

}

extern "C" __declspec (dllexport) void SerialGate::Clean()

extern "C" __declspec (dllexport) int SerialGate::Send(char* buff, int szBuff)

{

         if(!state)

                   return 0;

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

         {

                   return 0;

         }

         DWORD lpdwBytesWrittens = 0;

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

        

         return lpdwBytesWrittens;

}

extern "C" __declspec (dllexport) int SerialGate::Recv(char* buff, int szBuff)

{

         if(!state)

                   return 0;

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

         {

                   return 0;

         }

         DWORD dwBytesRead = 0; 

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

         return dwBytesRead;

}

extern "C" __declspec (dllexport) void SerialGate::SetLine(OUT_LINES_NAME ln, bool state)

{

         if(!state)

                   return ;

         unsigned char value;

        

         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 "C" __declspec (dllexport) bool SerialGate::GetLine(IN_LINES_NAME ln)

{

         if(!state)

                   return 0;

         unsigned long ul = 0;

         GetCommModemStatus(m_hFile, &ul);

                  

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

         {

                   return true;

         }

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

         {

                   return true;

         }

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

         {

                   return true;

         }

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

         {

                   return true;

         }                

         return false;

}

extern "C" __declspec (dllexport) void SerialGate::GetPortsInfo(PortInfo* pi)

{

 DWORD Ports_MemSize = 0;

 DWORD Ports_Count = 0;

 BYTE* lpPorts = NULL;

 //Getting Ports_MemSize value...

 EnumPorts(NULL,

 1,

 lpPorts,

 0,

 &Ports_MemSize,

 &Ports_Count);

 //Getting lpPorts...

 lpPorts = new BYTE[Ports_MemSize];

 EnumPorts(NULL,

 1,

 lpPorts,

 Ports_MemSize,

 &Ports_MemSize,

 &Ports_Count);

 //Forming List Of Ports...

 DWORD dw;

 TCHAR str[8];

 char temp[4];

 int port = -1;

 PORT_INFO_1 *pPortInfo;

 pPortInfo = (PORT_INFO_1 *)lpPorts;

 int counter = 0;

 bool av = false;

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

 {

 

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

 str[4] = 0;

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

 {

                   //printf("%s\n", pPortInfo->pName);       

                   memset(temp, '\0', sizeof(temp));

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

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

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

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

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

                   port = atoi(temp);

                   //printf("%d\n", port);

                  

                   char COM_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)

                   {                                   

                            //return false;

                            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>

#define MAX_WIN_PORT 255

struct Port

{

         unsigned char Id;

         bool Availbl;

};

struct PortInfo

{

         Port p[MAX_WIN_PORT];

         unsigned char koll;

};

extern "C" class __declspec (dllexport) SerialGate

{       

public:

        

         enum IN_LINES_NAME {CTS, DSR, RING, RLSD};

         enum OUT_LINES_NAME {DTR, RTS};        

         SerialGate();

         ~SerialGate();     

         bool Open(int port, int baud);        

         int Send(char* buff, int szBuff);

         int Recv(char* buff, int szBuff);      

         void SetLine(OUT_LINES_NAME ln, bool state);

         bool GetLine(IN_LINES_NAME ln);

         void GetPortsInfo(PortInfo* pi);

         void Close();

         void Clean();

private:

         HANDLE m_hFile;

         bool state;

};


Страницы: 1, 2


на тему рефераты
НОВОСТИ на тему рефераты
на тему рефераты
ВХОД на тему рефераты
Логин:
Пароль:
регистрация
забыли пароль?

на тему рефераты    
на тему рефераты
ТЕГИ на тему рефераты

Рефераты бесплатно, реферат бесплатно, курсовые работы, реферат, доклады, рефераты, рефераты скачать, рефераты на тему, сочинения, курсовые, дипломы, научные работы и многое другое.


Copyright © 2012 г.
При использовании материалов - ссылка на сайт обязательна.