CAPL Script

OpenFileRead

This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.

Contract

dword openFileRead(char filename[], dword mode);
dword openFileRead(char filename[], dword mode, dword fileEncoding);

Mode 0 requests text access; mode 1 requests binary access. A nonzero result is a handle for subsequent reads; 0 means opening failed. The optional encoding argument identifies a Microsoft code page. Verify supported encodings in the help supplied with your installed version rather than relying on a machine's default.

A successful open can still select the wrong input

The available reference describes a filename search in database directories first, then the active configuration directory. Therefore, two files named timestamps.txt can make a test use a stale fixture even though opening succeeds. This is a provenance problem, not a parsing problem.

Give each validation fixture a distinctive name and a recognizable first record. Record the active configuration and database locations with the test result. During setup, deliberately place different sentinel content in the possible locations and confirm which is read; remove the ambiguity before collecting evidence. Do this only with disposable fixtures.

Input need Choice Additional check
One timestamp per text line Text mode and a line reader Encoding, line length, unit and record count
A binary capture format Binary mode and an appropriate binary parser The file structure; a string reader is not a capture decoder
Non-ASCII labels An explicitly agreed encoding, where supported Reopen a fixture containing the actual characters

Gate every use of the handle

Opening a file does not validate its contents. If the return value is 0, stop that operation before calling a reader; do not reuse a handle left over from a previous successful run. After a successful open, every exit path must reach fileClose, including an invalid record or an aborted import.

A counterexample is retrying an import by assigning the new result to the only variable holding the previous open handle. The old resource becomes unreachable. Close the previous operation first, then start a new one with a fresh state.

Reproducible checks

Test a known fixture, a missing filename, an empty fixture and duplicate names in the possible search locations. A missing file must produce an explicit open failure; an empty file must not reuse a previous timestamp. Compare accepted records against the fixture before drawing conclusions from statistics. See the file I/O validation walkthrough for a full fixture matrix and the limitations of interpreting read termination.

API signatures and search behavior are summarized from the authorized Vector reference; the failure analysis and validation procedure are this site's commentary. These checks are proposed procedures, not recorded CANoe test results. See sources and limits.