
PCI-1680U/1682U User Manual 76
4.7.5.3 Write code
1. Add the following code to Button:
private void button1_Click(object sender, System.EventArgs e)
{
uint hDevice = 0;
bool result;
int dwOutLen=0;
int lpSecurityAttributes=0;
AdvCan.OVERLAPPED ov =new AdvCan.OVERLAPPED();
AdvCan.CanStatusPar_t CanStatus = new AdvCan.CanStatusPar_t();
AdvCan.Command_par_t cmd =new AdvCan.Command_par_t ();
//Open Can Port "CAN1".
//You can also change "CAN1" to a port's name which you have
installed.
hDevice = AdvCan.CreateFile("\\\\.\\can1",AdvCan.GENERIC_READ +
AdvCan.GENERIC_WRITE, 0, lpSecurityAttributes, Adv-
Can.OPEN_EXISTING, AdvCan.FILE_ATTRIBUTE_NORMAL + Adv-
Can.FILE_FLAG_OVERLAPPED, 0);
if( hDevice == 0xffffffff )
{
MessageBox.Show("Open CAN port Error!");
return;
}
//Get Can port status.
result = AdvCan.DeviceIoControl(hDevice, Adv-
Can.CAN_IOCTL_STATUS,ref cmd, 0,ref CanStatus,Marshal.SizeOf (Can-
Status),ref dwOutLen,ref ov);
if( !result )
{
MessageBox.Show("GetStauts Error!");
return;
}
textBox1.Text = "Baud rate = " + CanStatus.baud .ToString();
textBox2.Text = "Accept code = " + CanStatus.acceptancecode
.ToString("X2");
textBox3.Text = "Mask code = " + CanStatus.acceptancemask
.ToString("X2");
textBox4.Text = "Self recevie = " + CanStatus.selfreception
.ToString();
textBox5.Text = "Read TimeOut = " + CanStatus.readtimeout
.ToString();
textBox6.Text = "Write TimeOut= " + CanStatus.writetimeout
.ToString();
result = AdvCan.CloseHandle( hDevice ); //Close the CAN port
if (! result )
{
MessageBox.Show ("GetStauts Error!");
return;
}
}
Kommentare zu diesen Handbüchern