User`s manual

Software Manual • EKF Intelligent I/O Controller Family On
CompactPCI
- 22 -
EKF Elektronik GmbH * Philipp-Reis-Str. 4 * D-59065 HAMM (Germany)
Tel. +49 (0)2381/6890-0 * Fax. +49 (0)2381/6890-90 * E-Mail info@ekf.de * Internet http://www.ekf.de
CreateFile
returns a handle to the device opened. If the opening failed, the constant
INVALID_HANDLE_VALUE is returned and a call to
GetLastError
returns a corresponding
error code.
To close an previously opened port the C function
CloseHandle
should be used. When
closing a serial port, the driver waits for the transmission of the data that currently reside in
the transmit FIFO of the UART. If programmed for XON/XOFF flow control, an XON
character is sent when the reception was held before by sending XOFF. After that the driver
waits 10 character times before clearing the DTR and RTS lines.
Call: CloseHandle(
handle // handle returned by
CreateFile
);
CloseHandle
returns TRUE on success. If the closing of the device failed, FALSE is returned
and a call to
GetLastError
returns a corresponding error code.
Write Data
Data transmission via a previously successfully opened port is provided by the C function
WriteFile
. The data buffer given to
WriteFile
is sent unchanged to the port.
Call: WriteFile(
handle, // handle returned by
CreateFile
pBuffer, // pointer to data buffer
bytesToWrite, // number of bytes to write
pBytesWritten, // pointer to number of bytes written
pOverlapped // pointer to overlapped buffer
);
WriteFile
returns TRUE on success. If the write operation failed, FALSE is returned and a
call to
GetLastError
returns a corresponding error code.
If the port was opened with FILE_FLAG_OVERLAPPED for asynchronous I/O,
WriteFile
returns FALSE and
GetLastError
may return ERROR_IO_PENDING. In that case a
subsequent call to
GetOverlappedResult
is necessary. See also the Windows “Visual C++”
documentation for details of asynchronous I/O operations.
On CANbus ports a complete frame including frame information field, transmit identifier and
transmit data must be supplied to
WriteFile
. The driver will return an error, if a bad frame was
passed. Therefore it is better to use the C function
Ekf960SendCanFrame
within the static
library “ekf960si1.lib” to send frames over a CANbus port. This routine sets up a frame from
the data supplied by the user and then calls
WriteFile
and, if necessary,
GetOverlappedResult
. See also the source file of
Ekf960SendCanFrame
“sendcan.c” that
is delivered with the driver installation package.