summaryrefslogtreecommitdiff
path: root/doxygen-src/delphi/doxypage_delphi_mbgdevio.txt
blob: cc30b3aeb4c452988fe623a51dcca54de72b1771 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**************************************************************************
 *
 *  $Id: doxypage_delphi_mbgdevio.txt 1.3 2009/01/23 13:41:55Z daniel REL_M $
 *  $Name: $
 *
 *  Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
 *
 *  Description:
 *    Documentation for Meinberg Device I/O (Delphi)
 *
 * -----------------------------------------------------------------------
 *  $Log: doxypage_delphi_mbgdevio.txt $
 *  Revision 1.3  2009/01/23 13:41:55Z  daniel
 *  Revision 1.2  2008/05/21 11:33:09Z  martin
 *  Revision 1.1  2007/12/13 10:45:27Z  daniel
 *  Initial revision
 *
 **************************************************************************/

/*! \page doxypage_delphi_mbgdevio Meinberg Device I/O (MbgDevIo) (Delphi)
   This page describes libraries and sample code that can
   be used to access Meinberg computer peripherals from user applications via the mbgdevio.dll.
 *

\section install_sec Step-by-step instructions for using the MbgDevIo API

\subsection stepvb1 Step 1: Installing the driver package
Download and install the latest available Windows driver from our homepage.<br>

http://www.meinberg.de/english/sw/#win  <br>
  
The driver is shipped with the latest <I>mbgdevio.dll</I> which can be used to access the board via the SDK.<br>
Install a Meinberg computer device and test if it works correctly with the driver package.

\subsection stepdph2 Step 2: Compiling and testing the demo program.

  \li Download and extract the SDK files to a temporary folder. <br>
  \li Open the main file <I><b>mbgdemo.dpr</b></I> which is located in <B>"%INSTALL_ROOT%\delphi\demo"</B>.<BR>
  \li Compile and test.

\subsection stepdph3 Step 3: Integrating the SDK files into a user application
  
  \li Download and extract the SDK files to a temporary folder.
  \li Add the units <I><b>mbgdevio.pas</b></I> and <I><b>mbgdefs.pas</b></I> to your Delphi project.<br>
    
\subsection stepdph4 Step 4: Getting a handle to the radio clock

\code
program mbgdemo;
{$APPTYPE CONSOLE}

uses
  sysutils,
  mbgdefs in 'mbgdefs.pas',
  mbgdevio in 'mbgdevio.pas';

var
  dh : MBG_DEV_HANDLE;
  di : PCPS_DRVR_INFO;
  rc : Integer;
  n  : Integer;

begin  
  (* Check the mbgdevio version first *)
  if mbgdevio_check_version( MBGDEVIO_VERSION ) <> PCPS_SUCCESS then
    begin
      WriteLn( Format(
        'The MBGDEVIO version %x which is installed is not compatible' + #$0D + #$0A +
        'with API version %x required by this program.',
        [ mbgdevio_get_version, MBGDEVIO_VERSION ] )
      );
      Exit;
    end;

  (* Search for installed devices *)
  n := mbg_find_devices;
  WriteLn( 'Found ', n, ' device(s).' );

  if n > 0 then
    begin
      WriteLn( 'Kernel device driver:' );
    
      (* Retrieve a handle to the first device that was found on the computer *)
      dh := mbg_open_device( 0 );
    
      if dh <> MBG_INVALID_DEV_HANDLE then
        begin
          rc := mbg_get_drvr_info( dh, di );
    
          if  rc = PCPS_SUCCESS then
            begin            
              with di do
                begin
                  WriteLn( '  Driver ID:      ', id_str );
                  WriteLn( '  Driver version: ',
                    Format( 'v%u.%2.2u', [ ver_num div 100, ver_num mod 100 ] ) );
                end;
                
            (* ----------------------- *)    
            (* Insert custom code here *)
            (* ----------------------- *)
            
            end
          else
            WriteLn( '  mbg_get_drvr_info returned ', rc, '.' );
    
          mbg_close_device( dh );
        end
      else
        WriteLn( 'Failed to open driver.' );
    
      WriteLn;
    end;
end.
\endcode

\subsection stepdph5 Step 5: Accessing the device
After retrieving the handle <B>dh</B> of a specific device, this handle can be used with
several API calls to read from or write to the board.<br>
For example:
  
\code
procedure ShowDeviceInfo;

var
  dh : MBG_DEV_HANDLE;
  di : PCPS_DEV;
  t : PCPS_TIME;
  rc : Integer;
  s : string[2];

begin  (* ShowDeviceInfo *)
  dh := mbg_open_device( 0 );

  if dh <> MBG_INVALID_DEV_HANDLE then
    begin
      (* show device info *)
      rc := mbg_get_device_info( dh, di );

      if  rc = PCPS_SUCCESS then
        begin
          with di do
            begin
              Write( '  ', dev_cfg.fw_id, ' at port ', Format( '%3.3x', [dev_cfg.port[0].base] ) );
              if dev_cfg.port[1].base <> 0 then
                Write( '/', Format( '%3.3x', [dev_cfg.port[1].base] ) );
              WriteLn( ', IRQ ', dev_cfg.irq_num );
            end;
        end
      else
        WriteLn( '  mbg_get_device_info returned ', rc, '.' );

      (* show current date and time *)
      rc := mbg_get_time( dh, t );

      if  rc = PCPS_SUCCESS then
        begin
          with t do
            begin
              if offs_utc < #0 then
                s := '-'
              else
                s := '+';

              WriteLn( '  Date/time: ',
                Format( '%2.2u.%2.2u.%2.2u  %2.2u:%2.2u:%2.2u.%2.2u UTC%s%dh',
                        [ mday, month, year,
                          hour, min, sec, sec100,
                          s, Abs( Integer( offs_utc ) ) ] ) );
            end;
        end
      else
        WriteLn( '  mbg_get_time returned ', rc, '.' );

      mbg_close_device( dh );
    end
  else
    WriteLn( '  Failed to open device' );

end;
\endcode    

\section api_sec_dph API structures, definitions and exported functions for Borland Delphi
Below there is list of all API structures and functions from the mbgdevio.dll that
are referenced for Borland Delphi as exported via the file <b>mbgdevio.pas</b>.<br>
However, this is only a subset of functions and structures which can be provided by the 
C/C++ API, which is more powerful. Please contact Meinberg support, if there is any important
function missing for your application.

The documentations of the structures and functions below are taken from the C-API which were
automatically generated from the original C-Sources.

\section structs_dph Structures

\li ::PCPS_TIME<br>
\li PCPS_DEV
\li PCPS_DRVR_INFO

\section defin_dph Definitions

\li #PCPS_SUCCESS<br>

\li #PCPS_FREER<br>
\li #PCPS_DL_ENB<br>
\li #PCPS_SYNCD<br>
\li #PCPS_DL_ANN<br>
\li #PCPS_UTC<br>
\li #PCPS_LS_ANN<br>
\li #PCPS_IFTM<br>
\li #PCPS_INVT<br>
\li #PCPS_LS_ENB<br>
\li #PCPS_ANT_FAIL<br>
\li #PCPS_UCAP_OVERRUN<br>
\li #PCPS_UCAP_BUFFER_FULL<br>

\section functions_dph Exported functions

\li mbgdevio_get_version()<br>
\li mbgdevio_check_version()<br>

\li mbg_find_devices()<br>
\li mbg_open_device()<br>
\li mbg_close_device()<br>

\li mbg_get_drvr_info()<br> 
\li mbg_get_device_info()<br>

\li mbg_get_time()<br>

\section support_vb Contact
For further questions please contact:
support@meinberg.de

*/