Autor Beitrag
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mo 07.03.11 17:12 
Hallo Leute,

ich habe für eine synchrone RS232 Karte eine mitgelieferte DLL + Headerdateien.

Die meisten Typen kann ich selber in Delphi Typen umsetzen, nur bei diesen Zweien benötige ich eure Hilfe !
ausblenden volle Höhe Quelltext
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:
typedef struct tagMPA_CONFIG
{
    ULONG   structLen;
    union
    {
        struct
        {
            // Set the following bits to indicate which parameter(s) are to be 
            // set.  Parameter value(s) with corresponding bits set to zero are 
            // not changed.
            // Tx does not require buffers since pending IRPs provide buffers.
            UCHAR FrameBufferSizeRx : 1;
            UCHAR NumFrameBuffersRx : 1;
            UCHAR BaudRate          : 1;
            UCHAR ClockRate         : 1;
            UCHAR ClockMode         : 1;
            UCHAR InternalLoopback  : 1;
            UCHAR RxClockSource     : 1;
            UCHAR TxClockSource     : 1;
            UCHAR TRXCOutput        : 1;
            UCHAR Encoding          : 1;
            UCHAR DPLLClockSource   : 1;
            UCHAR DPLLMode          : 1;
            UCHAR AutoRTSDeact      : 1;
            UCHAR CRCPreset         : 1;
            UCHAR IdleLineControl   : 1;
            ULONG pad               : (8*sizeof(ULONG) - 13);
        } bits;
        ULONG all;  // Used to clear/set all bits at once.
    } set;

    ULONG             FrameBufferSizeRx;      // In bytes.
    ULONG             NumFrameBuffersRx;
    ULONG             BaudRate;
    ULONG             ClockRate;
    ULONG             ClockMode;
    BOOLEAN           InternalLoopback;
    CLOCK_SOURCE      RxClockSource;
    CLOCK_SOURCE      TxClockSource;
    TRXC_OUTPUT       TRXCOutput;
    ENCODING          Encoding;
    DPLL_CLOCK_SOURCE DPLLClockSource;
    DPLL_MODE         DPLLMode;
    BOOLEAN           AutoRTSDeact;
    BOOLEAN           CRCPreset;
    IDLE_LINE_CONTROL IdleLineControl;
} MPA_CONFIG, *PMPA_CONFIG;

typedef struct tagMPA_MODEM_CNTL_SIG
{
    ULONG   structLen;
    union
    {
        struct
        {
            // Set the following bits to indicate which parameter(s) are to be 
            // set.  Parameter value(s) with corresponding bits set to zero are 
            // not changed.
// removed support for the following three bits of the COMM register            
//            UCHAR testModeStatus    : 1;
//            UCHAR localLoopbackEn   : 1;
//            UCHAR remoteLoopbackEn  : 1;

            UCHAR extSyncEn         : 1;
            UCHAR rxClkSource       : 1;
            UCHAR txClkSource       : 1;
            UCHAR rxBufEnable       : 1; // enable RX buffers
            UCHAR txBufEnable       : 1; // enable TX buffers

            UCHAR rts               : 1;
            UCHAR dtr               : 1;
            UCHAR cts               : 1;
            UCHAR dcd               : 1;
            ULONG pad               : (8*sizeof(USHORT) - 10);
        } bits;
        USHORT all; // Used to clear/set all bits at once.
    } set;

    union
    {
        struct
        {
            // On-board modem control signals in Communications Register.
// removed support for the following three bits of the COMM register            
//            UCHAR testModeStatus    : 1;
//            UCHAR localLoopbackEn   : 1;
//            UCHAR remoteLoopbackEn  : 1;

            UCHAR extSyncEn         : 1;
            UCHAR rxClkSource       : 1;
            UCHAR txClkSource       : 1;
            UCHAR rxBufEnable       : 1; // enable rx buffers on card
            UCHAR txBufEnable       : 1; // enable tx buffers on card

            // On-chip modem control signals
            UCHAR rts               : 1;
            UCHAR dtr               : 1;
            UCHAR cts               : 1;
            UCHAR dcd               : 1;
            UCHAR pad               : (8*sizeof(USHORT) - 10);
        } bits;
        USHORT all; // Used to clear/set all bits at once.
    } signals;
} MPA_MODEM_CNTL_SIG, *PMPA_MODEM_CNTL_SIG;



Danke schonmal !!

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mo 07.03.11 17:41 
Hey,

union geht in Delhi so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
type
  TSet = packed record
    case Integer of
      0: (bits: packed record
            FrameBufferSizeRx: Byte;
            NumFrameBuffersRx: Byte;
            BaudRate: Byte;
            ClockRate: Byte;
            ClockMode: Byte;
            InternalLoopback: Byte;
            RxClockSource: Byte;
            TxClockSource: Byte;
            TRXCOutput: Byte;
            Encoding: Byte;
            DPLLClockSource: Byte;
            DPLLMode: Byte;
            AutoRTSDeact: Byte;
            CRCPreset: Byte;
            IdleLineControl: Byte;
            pad:Longword;
         end);
      1: (all: Longword);
  end;


Allerdings wunder ich mich, wie man 13 Byte-Werte mit einem Longword (4Byte) abdecken will um alle auf einmal zu setzen. Dazu müsste UCHAR schon 1Bit groß sein. Aber laut Doku ist es ein Byte.

Mfg Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
OlafSt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 486
Erhaltene Danke: 99

Win7, Win81, Win10
Tokyo, VS2017
BeitragVerfasst: Do 10.03.11 13:11 
Entscheidend sind die von dir geflisstentlich überlesenen ":1" im C-Code ;). Damit wird festgelegt, das hier tatsächlich nur ein einziges Bit belegt wird, während die Delphi-Portierung für jedes Element ein komplettes Byte nutzt.

Folglich ist der Delphi-Record auch drastisch größer. Wenn ich mich recht entsinne, sind solche Bitfelder in Delphi nicht möglich.

_________________
Lies, was da steht. Denk dann drüber nach. Dann erst fragen.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 10.03.11 13:21 
Bit-Felder werden in Delphi nicht direkt supportet. Stattdessen muss man hier über entsprechende Konstanten und ein wenig Bit-Arithmetik manuell nachhelfen. Entsprechend kann der entsprechende Zweig entfallen und die Union durch einen einzigen Wert ersetzt werden.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Do 10.03.11 14:59 
Hey,

irgendwie hab ich mir sowas schon gedacht^^ Aber mal noch ne Frage: Wenn ich da nur 1 Bit festgelegt hab und jetzt der Variablen nen Wert > 1 geben will. Meckert da dann der Compiler, oder schreibt der einfach in die anderen Variablen rein?

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 12.03.11 22:56 
Es gibt da einfach einen stillen Überlauf, ggf. auch ne Warnung vom Compiler, wenn der das statisch feststellen kann), aber die anderen Bit-Felder werden nicht verändert. Es steht halt von dem zugewiesenen Wert nur die niedrigsten X Bit in deinem Feld dann drin.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.