forked from netdata-be/libnodave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodave.pas.borland
executable file
·1052 lines (887 loc) · 39.3 KB
/
nodave.pas.borland
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit nodave;
interface
(*uses windows;*)
{ Automatically converted by H2Pas 0.99.15 from nodave.h }
{ The following command line parameters were used:
nodave.h. And modified to make it work.
}
{ $ PACKRECORDS C}
{
Part of Libnodave, a free communication libray for Siemens S7 200/300/400 via
the MPI adapter 6ES7 972-0CA22-0XAC
or MPI adapter 6ES7 972-0CA23-0XAC
or TS adapter 6ES7 972-0CA33-0XAC
or MPI adapter 6ES7 972-0CA11-0XAC,
IBH/MHJ-NetLink or CPs 243, 343 and 443
or VIPA Speed7 with builtin ethernet support.
(C) Thomas Hergenhahn ([email protected]) 2002..2005
Libnodave is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Libnodave is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Libnodave; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
}
{ $ifndef __nodave}
{ $define __nodave}
{$ifdef LINUX}
type
_daveOSserialType = record
rfd : longint;
wfd : longint;
end;
const LibName = 'libnodave';
{$endif}
{$ifdef WIN32}
type
pHandle=longint;
_daveOSserialType = record
rfd : pHANDLE;
wfd : pHANDLE;
end;
const LibName = 'libnodave.dll';
{$endif}
{
Define this if your system doesn't have byteswap.h or if you experience difficulties with
the inline functions
}
{ #define HANDMADE_CONVERSIONS }
{ this is now done in the Makefile: }
{ #define LINUX }
{ #include "log.h" }
{
some frequently used ASCII control codes:
}
const
DLE = $10;
ETX = $03;
STX = $02;
SYN = $16;
{
Protocol types to be used with newInterface:
}
{ MPI for S7 300/400 }
daveProtoMPI = 0;
{ MPI for S7 300/400, "Andrew's version" }
daveProtoMPI2 = 1;
{ PPI for S7 200 }
daveProtoPPI = 10;
{ ISO over TCP }
daveProtoISOTCP = 122;
{ ISO over TCP with CP243 }
daveProtoISOTCP243 = 123;
{ MPI with IBH NetLink MPI to ethernet gateway }
daveProtoMPI_IBH = 223;
daveProtoPPI_IBH = 224;
{ MPI with NetLink Pro MPI to ethernet gateway }
daveProtoNLpro = 230;
{ user defined transport protocol }
daveProtoUserTransport = 255;
{
ProfiBus speed constants:
}
daveSpeed9k = 0;
daveSpeed19k = 1;
daveSpeed187k = 2;
daveSpeed500k = 3;
daveSpeed1500k = 4;
daveSpeed45k = 5;
daveSpeed93k = 6;
{
Some MPI function codes (yet unused ones may be incorrect).
}
daveFuncOpenS7Connection = $F0;
daveFuncRead = $04;
daveFuncWrite = $05;
daveFuncRequestDownload = $1A;
daveFuncDownloadBlock = $1B;
daveFuncDownloadEnded = $1C;
daveFuncStartUpload = $1D;
daveFuncUpload = $1E;
daveFuncEndUpload = $1F;
{
S7 specific constants:
}
daveBlockType_OB = '8';
daveBlockType_DB = 'A';
daveBlockType_SDB = 'B';
daveBlockType_FC = 'C';
daveBlockType_SFC = 'D';
daveBlockType_FB = 'E';
daveBlockType_SFB = 'F';
{
Use these constants for parameter "area" in daveReadBytes and daveWriteBytes
}
{ System info of 200 family }
daveSysInfo = $3;
{ System flags of 200 family }
daveSysFlags = $5;
{ analog inputs of 200 family }
daveAnaIn = $6;
{ analog outputs of 200 family }
daveAnaOut = $7;
daveP = $80;
{ Peripheral data like PIW, PQW }
daveInputs = $81;
daveOutputs = $82;
daveFlags = $83;
{ data blocks }
daveDB = $84;
{ not tested }
daveDI = $85;
{ not tested }
daveLocal = $86;
{ don't know what it is }
daveV = $87;
daveCounter = 28;
daveTimer = 29;
{
Library specific:
}
{
Result codes. Genarally, 0 means ok,
>0 are results (also errors) reported by the PLC
<0 means error reported by library code.
}
{ means all ok }
daveResOK = 0;
{ CPU tells it does not support to read a bit block with a }
daveResMultipleBitsNotSupported = 6;
{ length other than 1 bit. }
{ means a a piece of data is not available in the CPU, e.g. }
daveResItemNotAvailable200 = 3;
{ when trying to read a non existing DB or bit bloc of length<>1 }
{ This code seems to be specific to 200 family. }
{ means a a piece of data is not available in the CPU, e.g. }
daveResItemNotAvailable = 10;
{ when trying to read a non existing DB }
{ means the data address is beyond the CPUs address range }
daveAddressOutOfRange = 5;
daveResCannotEvaluatePDU = -(123);
daveResCPUNoData = -(124);
daveUnknownError = -(125);
daveEmptyResultError = -(126);
daveEmptyResultSetError = -(127);
{
error code to message string conversion:
Call this function to get an explanation for error codes returned by other functions.
}
function daveStrerror(code:longint):Pchar;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveStrerror'{$ENDIF};
{
Max number of bytes in a single message.
An upper limit for MPI over serial is:
8 transport header
+2 240 max PDU len 2 if every character were a DLE
+3 DLE,ETX and BCC
= 491
Later I saw some programs offering up to 960 bytes in PDU size negotiation
Max number of bytes in a single message.
An upper limit for MPI over serial is:
8 transport header
+2 960 max PDU len 2 if every character were a DLE
+3 DLE,ETX and BCC
= 1931
For now, we take the rounded max of all this to determine our buffer size. This is ok
for PC systems, where one k less or more doesn't matter.
}
const
daveMaxRawLen = 2048;
{
Some definitions for debugging:
}
{ Show the single bytes received }
daveDebugRawRead = $01;
{ Show when special chars are read }
daveDebugSpecialChars = $02;
{ Show the single bytes written }
daveDebugRawWrite = $04;
{ Show the steps when determine devices in MPI net }
daveDebugListReachables = $08;
{ Show the steps when Initilizing the MPI adapter }
daveDebugInitAdapter = $10;
{ Show the steps when connecting a PLC }
daveDebugConnect = $20;
daveDebugPacket = $40;
daveDebugByte = $80;
daveDebugCompare = $100;
daveDebugExchange = $200;
{ debug PDU handling }
daveDebugPDU = $400;
{ debug PDU loading program blocks from PLC }
daveDebugUpload = $800;
daveDebugMPI = $1000;
{ Print error messages }
daveDebugPrintErrors = $2000;
daveDebugPassive = $4000;
daveDebugErrorReporting = $8000;
daveDebugOpen = $10000;
daveDebugAll = $1ffff;
{
Some data types:
}
type uc = char;
Puc=^char;
pPuc=^puc;
us = word;
Pus =^us;
{
This is a wrapper for the serial or ethernet interface. This is here to make porting easier.
}
{
type
_daveConnection = daveConnection;
_daveInterface = daveInterface;
}
{
Helper struct to manage PDUs. This is NOT the part of the packet I would call PDU, but
a set of pointers that ease access to the "private parts" of a PDU.
}
{ pointer to start of PDU (PDU header) }
{ pointer to start of parameters inside PDU }
{ pointer to start of data inside PDU }
{ pointer to start of data inside PDU }
{ header length }
{ parameter length }
{ data length }
{ user or result data length }
type
PDU = record
header : Puc;
param : Puc;
data : Puc;
udata : Puc;
hlen : longint;
plen : longint;
dlen : longint;
udlen : longint;
end;
PPDU =^PDU;
{
Definitions of prototypes for the protocol specific functions. The library "switches"
protocol by setting pointers to the protol specific implementations.
}
{
This groups an interface together with some information about it's properties
in the library's context.
}
{ some handle for the serial interface }
{ a counter used when multiple PLCs are accessed via }
{ the same serial interface and adapter. }
{ the adapter's MPI address }
{ just a name that can be used in programs dealing with multiple }
{ daveInterfaces }
{ Timeout in microseconds used in transort. }
{ The kind of transport protocol used on this interface. }
{ The MPI or Profibus speed }
{ position of some packet number that has to be repeated in ackknowledges }
{ pointers to the protocol }
{ specific implementations }
{ of these functions }
type
MPIheader = record
src_conn : uc;
dst_conn : uc;
MPI : uc;
localMPI : uc;
len : uc;
func : uc;
packetNumber : uc;
end;
pdaveInterface=^_daveInterface;
pdaveConnection=^_daveConnection;
{
This holds data for a PLC connection;
}
{ pointer to used interface }
{ The PLC's address }
{ current message number }
{ message number we need ackknowledge for }
{ length of last message }
{ template of MPI Header, setup once, copied in and then modified }
{ used to retrieve single values from the result byte array }
{ packetNumber in transport layer }
{ position of PDU in outgoing messages. This is different for different transport methodes. }
{ position of PDU in incoming messages. This is different for different transport methodes. }
{ rack number for ISO over TCP }
{ slot number for ISO over TCP }
_daveConnection = record
AnswLen : longint;
resultPointer : Puc;
maxPDUlength : longint;
MPIAdr : longint;
iface : PdaveInterface;
needAckNumber : longint;
PDUnumber : longint;
ibhSrcConn : longint;
ibhDstConn : longint;
msgIn : array[0..(daveMaxRawLen)-1] of uc;
msgOut : array[0..(daveMaxRawLen)-1] of uc;
_resultPointer : Puc;
PDUstartO : longint;
PDUstartI : longint;
rack : longint;
slot : longint;
connectionNumber : longint;
connectionNumber2 : longint;
messageNumber : uc;
packetNumber : uc;
end;
initAdapterFunc=function(d:pdaveInterface):longint;
connectPLCFunc=function(d:pdaveConnection):longint;
disconnectPLCFunc=function(d:pdaveConnection):longint;
disconnectAdapterFunc=function(d:pdaveInterface):longint;
exchangeFunc=function(d:pdaveConnection;p:pPDU):longint;
sendMessageFunc=function(d:pdaveConnection;p:pPDU):longint;
getResponseFunc=function(d:pdaveConnection):longint;
listReachablePartnersFunc=function(d:pdaveInterface; buffer:puc):longint;
PinitAdapterFunc=^initAdapterFunc;
PconnectPLCFunc=^connectPLCFunc;
PdisconnectPLCFunc=^initAdapterFunc;
PdisconnectAdapterFunc=^disconnectAdapterFunc;
PexchangeFunc=^exchangeFunc;
PsendMessageFunc=^sendMessageFunc;
PgetResponseFunc=^getResponseFunc;
PlistReachablePartnersFunc=^listReachablePartnersFunc;
_daveInterface = record
timeout : longint;
fd : _daveOSserialType;
localMPI : longint;
users : longint;
name : Pchar;
protocol : longint;
speed : longint;
ackPos : longint;
nextConnection : longint;
initAdapter : PinitAdapterFunc;
connectPLC : PconnectPLCFunc;
disconnectPLC : PdisconnectPLCFunc;
disconnectAdapter : PdisconnectAdapterFunc;
exchange : PexchangeFunc;
sendMessage : PsendMessageFunc;
getResponse : PgetResponseFunc;
listReachablePartners : PlistReachablePartnersFunc;
end;
daveInterface=_daveInterface;
(* pdaveInterface=^_daveInterface; *)
{
A special header for MPI packets:
}
type
daveBlockTypeEntry = record
type_ : array[0..1] of uc;
count : word;
end;
pdaveBlockTypeEntry = ^daveBlockTypeEntry;
daveBlockEntry = record
number : word;
type_ : array[0..1] of uc;
end;
pdaveBlockEntry = ^daveBlockEntry;
{ 00 4A }
{ some word var? }
{ allways 'pp' }
{ 00 4A }
{ the block's number }
{ ? }
{ the block's length }
daveBlockInfo = record
type_ : array[0..1] of uc;
x1 : array[0..1] of uc;
w1 : array[0..1] of uc;
pp : array[0..1] of char;
x2 : array[0..3] of uc;
number : word;
x3 : array[0..25] of uc;
length : word;
x4 : array[0..15] of uc;
name : array[0..7] of uc;
x5 : array[0..11] of uc;
end;
{
PDU handling:
PDU is the central structure present in S7 communication.
It is composed of a 10 or 12 byte header,a parameter block and a data block.
When reading or writing values, the data field is itself composed of a data
header followed by payload data
}
{ allways 0x32 }
{ Header type, one of 1,2,3 or 7. type 2 and 3 headers are two bytes longer. }
{ currently unknown. Maybe it can beused for long numbers? }
{ A number. This can be used to make sure a received answer }
{ corresponds to the request with the same number. }
{ length of parameters which follow this header }
{ length of data which follow the parameters }
{ only present in type 2 and 3 headers. This contains error information. }
PDUHeader = record
P : uc;
type_ : uc;
a : uc;
b : uc;
number : us;
plen : us;
dlen : us;
result : array[0..1] of uc;
end;
{
Setup a new connection structure using an initialized
daveInterface and PLC's MPI address.
}
function daveNewConnection(di:PdaveInterface; MPI:longint; rack:longint; slot:longint):
PdaveConnection; stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveNewConnection'{$ENDIF};
function daveNewInterface(nfd:_daveOSserialType; nname:pchar; localMPI:longint;protocol:longint; speed:longint)
:PdaveInterface;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveNewInterface'{$ENDIF};
{
set up the header. Needs valid header pointer in the struct p points to.
}
procedure _daveInitPDUheader(p:PPDU; type_:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveInitPDUheader'{$ENDIF};
{
add parameters after header, adjust pointer to data.
needs valid header
}
procedure _daveAddParam(p:PPDU; param:Puc; len:us);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveAddParam'{$ENDIF};
{
add data after parameters, set dlen
needs valid header,and valid parameters.
}
procedure _daveAddData(p:PPDU; data:pointer; len:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveAddData'{$ENDIF};
{
add values after value header in data, adjust dlen and data count.
needs valid header,parameters,data,dlen
}
procedure _daveAddValue(p:PPDU; data:pointer; len:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveAddValue'{$ENDIF};
{
add data in user data. Add a user data header, if not yet present.
}
procedure _daveAddUserData(p:PPDU; da:Puc; len:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveAddUserData'{$ENDIF};
{
set up pointers to the fields of a received message
}
function _daveSetupReceivedPDU(dc:PdaveConnection; p:PPDU):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSetupReceivedPDU'{$ENDIF};
{
send PDU to PLC and retrieves the answer
}
function _daveExchange(dc:PdaveConnection; p:PPDU):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveExchange'{$ENDIF};
{
Utilities:
}
{
Hex dump PDU:
}
procedure _daveDumpPDU(p:PPDU);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveDumpPDU'{$ENDIF};
{
This is an extended memory compare routine. It can handle don't care and stop flags
in the sample data. A stop flag lets it return success, if there were no mismatches
up to this point.
}
type size_t=longint;
function _daveMemcmp(a:Pus; b:Puc; len:size_t):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveMemcmp'{$ENDIF};
{
Hex dump. Write the name followed by len bytes written in hex and a newline:
}
procedure _daveDump(name:Pchar; b:Puc; len:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveDump'{$ENDIF};
{
name Objects:
}
function daveBlockName(bn:uc):Pchar;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveBlockName'{$ENDIF};
function daveAreaName(n:uc):Pchar;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveAreaName'{$ENDIF};
{
Data conversion convenience functions:
}
function daveGetFloat(dc:PdaveConnection):single;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetFloat'{$ENDIF};
function daveGetFloatAt(dc:PdaveConnection; pos:longint):single;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetFloatAt'{$ENDIF};
function toPLCfloat(ff:single):double;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_toPLCfloat'{$ENDIF};
function daveToPLCfloat(ff:single):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveToPLCfloat'{$ENDIF};
function daveSwapIed_16(ff:smallint):smallint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveSwapIed_16'{$ENDIF};
function daveSwapIed_32(ff:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveSwapIed_32'{$ENDIF};
{
Timer and Counter conversion functions:
}
{
get time in seconds from current read position:
}
function daveGetSeconds(dc:PdaveConnection):double;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetSeconds'{$ENDIF};
{
get time in seconds from random position:
}
function daveGetSecondsAt(dc:PdaveConnection; pos:longint):double;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetSecondsAt'{$ENDIF};
{
get counter value from current read position:
}
function daveGetCounterValue(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetCounterValue'{$ENDIF};
{
get counter value from random read position:
}
function daveGetCounterValueAt(dc:PdaveConnection; pos:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetCounterValueAt'{$ENDIF};
{
Functions to load blocks from PLC:
}
procedure _daveConstructUpload(p:PPDU; blockType:char; blockNr:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveConstructUpload'{$ENDIF};
procedure _daveConstructDoUpload(p:PPDU; uploadID:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveConstructDoUpload'{$ENDIF};
procedure _daveConstructEndUpload(p:PPDU; uploadID:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveConstructEndUpload'{$ENDIF};
function _daveForce200(dc:PdaveConnection; area:longint; start:longint; val:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveForce200'{$ENDIF};
{
Get the PLC's order code as ASCIIZ. Buf must provide space for
21 characters at least.
}
const
daveOrderCodeSize = 21;
function daveGetOrderCode(dc:PdaveConnection; buf:Pchar):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetOrderCode'{$ENDIF};
{
connect to a PLC. returns 0 on success.
}
function daveConnectPLC(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveConnectPLC'{$ENDIF};
{
Read len bytes from the PLC. Start determines the first byte.
Area denotes whether the data comes from FLAGS, DATA BLOCKS,
INPUTS or OUTPUTS, etc.
DB is the number of the data block to be used. Set it to zero
for other area types.
Buffer is a pointer to a memory block provided by the calling
program. If the pointer is not NULL, the result data will be copied thereto.
Hence it must be big enough to take up the result.
In any case, you can also retrieve the result data using the get<type> macros
on the connection pointer.
RESTRICTION:There is no check for max. message len or automatic splitting into
multiple messages. Use daveReadManyBytes() in case the data you want
to read doesn't fit into a single PDU.
}
function daveReadBytes(dc:PdaveConnection; area:longint; DB:longint; start:longint; len:longint;
buffer:pointer):longint;stdcall;
external LibName {$ifdef WIN32} name '_daveReadBytes'{$ENDIF};
{
Read len bytes from the PLC. Start determines the first byte.
In contrast to daveReadBytes(), this function can read blocks
that are too long for a single transaction. To achieve this,
the data is fetched with multiple subsequent read requests to
the CPU.
Area denotes whether the data comes from FLAGS, DATA BLOCKS,
INPUTS or OUTPUTS, etc.
DB is the number of the data block to be used. Set it to zero
for other area types.
Buffer is a pointer to a memory block provided by the calling
program. It may not be NULL, the result data will be copied thereto.
Hence it must be big enough to take up the result.
You CANNOT read result bytes from the internal buffer of the
daveConnection. This buffer is overwritten in each read request.
}
function daveReadManyBytes(dc:PdaveConnection; area:longint; DB:longint; start:longint; len:longint;
buffer:pointer):longint;stdcall;
external LibName {$ifdef WIN32} name '_daveReadManyBytes'{$ENDIF};
{
Write len bytes from buffer to the PLC.
Start determines the first byte.
Area denotes whether the data goes to FLAGS, DATA BLOCKS,
INPUTS or OUTPUTS, etc.
DB is the number of the data block to be used. Set it to zero
for other area types.
RESTRICTION: There is no check for max. message len or automatic splitting into
multiple messages. Use daveReadManyBytes() in case the data you want
to read doesn't fit into a single PDU.
}
function daveWriteBytes(dc:PdaveConnection; area:longint; DB:longint; start:longint; len:longint;
buffer:pointer):longint;stdcall;
external LibName {$ifdef WIN32} name '_daveWriteBytes'{$ENDIF};
{
Write len bytes to the PLC. Start determines the first byte.
In contrast to daveWriteBytes(), this function can write blocks
that are too long for a single transaction. To achieve this, the
the data is transported with multiple subsequent write requests to
the CPU.
Area denotes whether the data comes from FLAGS, DATA BLOCKS,
INPUTS or OUTPUTS, etc.
DB is the number of the data block to be used. Set it to zero
for other area types.
Buffer is a pointer to a memory block provided by the calling
program. It may not be NULL.
}
function daveWriteManyBytes(dc:PdaveConnection; area:longint; DB:longint; start:longint; len:longint;
buffer:pointer):longint;stdcall;
external LibName {$ifdef WIN32} name '_daveWriteManyBytes'{$ENDIF};
{
Bit manipulation:
}
function daveReadBits(dc:PdaveConnection; area:longint; DB:longint; start:longint; len:longint;
buffer:pointer):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveReadBits'{$ENDIF};
function daveWriteBits(dc:PdaveConnection; area:longint; DB:longint; start:longint; len:longint;
buffer:pointer):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveWriteBits'{$ENDIF};
{
PLC diagnostic and inventory functions:
}
function daveReadSZL(dc:PdaveConnection; ID:longint; index:longint; buf:pointer):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveReadSZL'{$ENDIF};
function daveListBlocksOfType(dc:PdaveConnection; type_:uc; buf:PdaveBlockEntry):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveListBlocksOfType'{$ENDIF};
function daveListBlocks(dc:PdaveConnection; buf:PdaveBlockTypeEntry):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveListBlocks'{$ENDIF};
{
PLC program read functions:
}
function initUpload(dc:PdaveConnection; blockType:char; blockNr:longint; uploadID:Plongint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_initUpload'{$ENDIF};
function doUpload(dc:PdaveConnection; more:Plongint; buffer:PPuc; len:Plongint; uploadID:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_doUpload'{$ENDIF};
function endUpload(dc:PdaveConnection; uploadID:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_endUpload'{$ENDIF};
{
PLC run/stop control functions:
}
function daveStop(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveStop'{$ENDIF};
function daveStart(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveStart'{$ENDIF};
{
Multiple variable support:
}
type
daveResult = record
error : longint;
length : longint;
bytes : Puc;
end;
pdaveResult=^daveResult;
daveResultSet = record
numResults : longint;
results : PdaveResult;
end;
pdaveResultSet=^daveResultSet;
{ use this to initialize a multivariable read: }
procedure davePrepareReadRequest(dc:PdaveConnection; p:PPDU);stdcall;cdecl;
external LibName {$ifdef WIN32} name '_davePrepareReadRequest'{$ENDIF};
procedure davePrepareWriteRequest(dc:PdaveConnection; p:PPDU);stdcall;cdecl;
external LibName {$ifdef WIN32} name '_davePrepareWriteRequest'{$ENDIF};
{ Adds a new variable to a prepared request: }
procedure daveAddVarToReadRequest(p:PPDU; area:longint; DBnum:longint; start:longint; bytes:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveAddVarToReadRequest'{$ENDIF};
procedure daveAddVarToWriteRequest(p:PPDU; area:longint; DBnum:longint; start:longint; bytes:longint; buffer:pointer);stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveAddVarToWriteRequest'{$ENDIF};
procedure daveAddBitVarToWriteRequest(p:PPDU; area:longint; DBnum:longint; start:longint; bytes:longint; buffer:pointer);stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveAddBitVarToWriteRequest'{$ENDIF};
{ Executes the complete request. }
function daveExecReadRequest(dc:PdaveConnection; p:PPDU; rl:PdaveResultSet):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveExecReadRequest'{$ENDIF};
function daveExecWriteRequest(dc:PdaveConnection; p:PPDU; rl:PdaveResultSet):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveExecWriteRequest'{$ENDIF};
{ Lets the functions daveGet<data type> work on the n-th result: }
function daveUseResult(dc:PdaveConnection; rl:pDaveResultSet; n:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveUseResult'{$ENDIF};
{ Frees the memory occupied by the result structure }
procedure daveFreeResults(rl:PdaveResultSet);stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveFreeResults'{$ENDIF};
function daveInitAdapter(di:PdaveInterface):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveInitAdapter'{$ENDIF};
function daveDisconnectPLC(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveDisconnectPLC'{$ENDIF};
function daveDisconnectAdapter(di:PdaveInterface):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveDisconnectAdapter'{$ENDIF};
function daveListReachablePartners(di:PdaveInterface; buf:Pchar):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveListReachablePartners'{$ENDIF};
function daveForceDisconnectIBH(di:PdaveInterface; src:longint; dest:longint; MPI: longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveForceDisconnectIBH'{$ENDIF};
function _daveListReachablePartnersDummy(di:PdaveInterface; buf:Pchar):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveListReachablePartnersDummy'{$ENDIF};
{ MPI specific functions }
const
daveMPIReachable = $30;
daveMPIunused = $10;
davePartnerListSize = 126;
function _daveListReachablePartnersMPI(di:PdaveInterface; buf:Pchar):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveListReachablePartnersMPI'{$ENDIF};
function _daveInitAdapterMPI1(di:PdaveInterface):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveInitAdapterMPI1'{$ENDIF};
function _daveInitAdapterMPI2(di:PdaveInterface):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveInitAdapterMPI2'{$ENDIF};
function _daveConnectPLCMPI1(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveConnectPLCMPI1'{$ENDIF};
function _daveConnectPLCMPI2(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveConnectPLCMPI2'{$ENDIF};
function _daveDisconnectPLCMPI(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveDisconnectPLCMPI'{$ENDIF};
function _daveDisconnectAdapterMPI(di:PdaveInterface):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveDisconnectAdapterMPI'{$ENDIF};
function _daveExchangeMPI(dc:PdaveConnection; p1:PPDU):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveExchangeMPI'{$ENDIF};
{ ISO over TCP specific functions }
function _daveExchangeTCP(dc:PdaveConnection; p1:PPDU):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveExchangeTCP'{$ENDIF};
function _daveConnectPLCTCP(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveConnectPLCTCP'{$ENDIF};
{ PPI specific functions }
function _daveExchangePPI(dc:PdaveConnection; p1:PPDU):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveExchangePPI'{$ENDIF};
{
make PPI functions available for "passive mode"
}
procedure _daveSendLength(di:PdaveInterface; len:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendLength'{$ENDIF};
procedure _daveSendIt(di:PdaveInterface; b:Puc; size:longint);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendIt'{$ENDIF};
{ serial interface }
{ a buffer }
{ timeout in us }
{ limit }
(*
function _daveReadChars(di:PdaveInterface; b:Puc; tmo:longint; max:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveReadChars'{$ENDIF};
*)
function _daveReadChars2(di:PdaveInterface; b:Puc; max:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveReadChars2'{$ENDIF};
{
make MPI functions available for experimental use:
}
function _daveReadMPI(di:PdaveInterface; b:Puc):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveReadMPI'{$ENDIF};
procedure _daveSendSingle(di:PdaveInterface; c:uc);stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendSingle'{$ENDIF};
function _daveSendAck(dc:PdaveConnection; nr:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendAck'{$ENDIF};
function _daveGetAck(di:PdaveInterface):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveGetAck'{$ENDIF};
function _daveSendDialog2(dc:PdaveConnection; size:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendDialog2'{$ENDIF};
function _daveSendWithPrefix(dc: PdaveConnection; b:Puc; size:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendWithPrefix'{$ENDIF};
function _daveSendWithPrefix2(dc: PdaveConnection; size:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendWithPrefix2'{$ENDIF};
function _daveSendWithCRC(di: PdaveInterface; b:Puc; size:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendWithCRC'{$ENDIF};
function _daveReadSingle(di: PdaveInterface):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveReadSingle'{$ENDIF};
function _daveReadOne(di: PdaveInterface; b:Puc):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveReadOne'{$ENDIF};
function _daveReadMPI2(dc: PdaveInterface; b:Puc):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveReadMPI2'{$ENDIF};
function _daveGetResponseMPI(dc: PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveGetResponseMPI'{$ENDIF};
function _daveSendMessageMPI(dc:PdaveConnection; p1:PPDU):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '__daveSendMessageMPI'{$ENDIF};
{$IFDEF WIN32}
function setPort(name:pchar; baud: pchar; parity:char):pHandle; stdcall;cdecl;
external LibName {$ifdef WIN32} name 'setPort'{$ENDIF};
{$ENDIF}
{$IFDEF LINUX}
function setPort(name:pchar; baud: pchar; parity:char):longint; stdcall;cdecl;
external LibName {$ifdef WIN32} name 'setPort'{$ENDIF};
{$ENDIF}
function openSocket(port:longint;name:pchar):longint; stdcall;cdecl;
external LibName {$ifdef WIN32} name '_openSocket'{$ENDIF};
procedure closePort(port:longint); stdcall;cdecl;
external LibName {$ifdef WIN32} name '_closePort'{$ENDIF};
procedure closeS7online(port:longint); stdcall;cdecl;
external LibName {$ifdef WIN32} name '_closeS7online'{$ENDIF};
procedure daveSetDebug(nDebug:longint); stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveSetDebug'{$ENDIF};
function daveGetDebug:longint; stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetDebug'{$ENDIF};
{ _nodave }
{
Changes:
07/19/04 added the definition of daveExchange().
09/09/04 applied patch for variable Profibus speed from Andrew Rostovtsew.
09/09/04 applied patch from Bryan D. Payne to make this compile under Cygwin and/or newer gcc.
12/09/04 added daveReadBits(), daveWriteBits()
12/09/04 added some more comments.
12/09/04 changed declaration of _daveMemcmp to use typed pointers.
}
function daveGetS8(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetS8'{$ENDIF};
function daveGetU8(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetU8'{$ENDIF};
function daveGetS16(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetS16'{$ENDIF};
function daveGetU16(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetU16'{$ENDIF};
function daveGetS32(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetS32'{$ENDIF};
function daveGetU32(dc:PdaveConnection):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetU32'{$ENDIF};
function daveGetS8at(dc:PdaveConnection;pos:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetS8at'{$ENDIF};
function daveGetU8at(dc:PdaveConnection;pos:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetU8at'{$ENDIF};
function daveGetS16at(dc:PdaveConnection;pos:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetS16at'{$ENDIF};
function daveGetU16at(dc:PdaveConnection;pos:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetU16at'{$ENDIF};
function daveGetS32at(dc:PdaveConnection;pos:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetS32at'{$ENDIF};
function daveGetU32at(dc:PdaveConnection;pos:longint):longint;stdcall;cdecl;
external LibName {$ifdef WIN32} name '_daveGetU32at'{$ENDIF};