Advantech PCI-1682U Manual de usuario Pagina 74

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 104
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 73
PCI-1680U/1682U User Manual 68
4.7.3.3 Write code
Write code in source file.
#include <windows.h>
#include "../../../Include/AdvCan.h"
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
HANDLE hDevice = 0;
BOOL result;
int dwOutLen=0;
int lpSecurityAttributes=0;
OVERLAPPED ov ;
CanStatusPar_t CanStatus;
Command_par_t cmd ;
//Open Can Port "CAN1".
//You can also change "CAN1" to a port's name which you have
installed.
System::String^ CanPortName = "\\\\.\\" + "can1";
TCHAR* LWCanPortName= static_cast<TCHAR*>(System::Runt-
ime::InteropServices::Marshal::StringToCoTaskMemAuto( Can-
PortName).ToPointer());
hDevice = CreateFile( LWCanPortName,GENERIC_READ |
GENERIC_WRITE,0,(LPSECURITY_ATTRIBUTES)lpSecurityAt-
tributes,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);
if( (unsigned int)hDevice == 0xffffffff )
{
MessageBox::Show("Open CAN port Error!");
return;
}
//Get Can port status.
result = DeviceIoControl( hDe-
vice,(ULONG)CAN_IOCTL_STATUS,&cmd,0,&CanSta-
tus,sizeof(CanStatusPar_t),(LPDWORD)&dwOutLen,&ov);
if( !result )
{
MessageBox::Show("GetStauts Error!");
return;
}
this->textBox1->Text = "Baud rate = " + CanSta-
tus.baud.ToString();
this->textBox2->Text = "Accept code = " + CanStatus.accep-
tancecode .ToString("X2");
this->textBox3->Text = "Mask code = " + CanStatus.acceptance-
mask .ToString("X2");
this->textBox4->Text = "Self recevie = " + CanStatus.selfre-
ception .ToString();
this->textBox5->Text = "Read TimeOut = " + CanStatus.readtime-
out .ToString();
this->textBox6->Text = "Write TimeOut= " + CanStatus.writetim-
eout .ToString();
result = CloseHandle( hDevice ); //Close the CAN port
if (! result )
{
MessageBox::Show ("GetStauts Error!");
return;
}
}
Vista de pagina 73
1 2 ... 69 70 71 72 73 74 75 76 77 78 79 ... 103 104

Comentarios a estos manuales

Sin comentarios