IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Delphi Discussion :

TmemoryStream: definition des Word


Sujet :

Langage Delphi

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    108
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 108
    Points : 89
    Points
    89
    Par défaut TmemoryStream: definition des Word
    Bonjour,

    Je travail sur avec un TmemoryStream. J'ai crée un type record comme ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Type
      TAquaProPlusMTO = record
        Bof: array[0..4] of byte;
        sync: byte;
        id: byte;
        size: word;
        //Bof: array[0..8] of byte;
    end;
    Le problème est le suivant:
    Si je lis 2 octets directement sous forme de word (la variable size), j'obtient une valeur abérante. Si je lis les deux meme octets sous forme de byte (bof[7] et bof[8]) et que je fait la transformation en word, c'est bon.

    Exemple:
    Mes deux bytes sont 106 0 donc la valeur du word associée est 106+0*256=106 et lui me sort 8192 si je lis un word alors qu'il me dit bien que les deux byte sont 106 et 0.

    Ququ'un sait il ce qui se passe?
    merci.

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    108
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 108
    Points : 89
    Points
    89
    Par défaut
    Oups! Y maquait le rapport avec le TmemoryStream:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    var
      mesureAquaPro: TAquaProPlusMTO;
    begin
      Buffer:=TmemoryStream.Create;
      Buffer.Write(data^, size);
      //ou data est un pointeur vers une trame binaire...
      Buffer.Seek(0,soFromBeginning);
      Buffer.Read(mesureAquaPro, sizeOf(mesureAquaPro));
    Et je regarde le contenu de mon recorder avec le debugger...

  3. #3
    Membre confirmé
    Avatar de Philippe Gormand
    Inscrit en
    Mars 2002
    Messages
    330
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 330
    Points : 647
    Points
    647
    Par défaut TmemoryStream
    Salut.

    Size est unepropriété de l'objet TMemoryStream.
    Il est tout à fait possible que le nom de ta variable size entre en confli avec la propriété. Je sais que cela parrait abérant, mais j'ai déja été confronté à ce problème, notament avec l'objet TForm.

    Change le nom de la variable "size" en "Taille" par exemple, essais.

    Tiens nous au courant si cela résoud ton problème.

    A+

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    108
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 108
    Points : 89
    Points
    89
    Par défaut
    En fait j'ai pressenter cette valeur la comme exemple, mais ma structure comporte plus de variables, dont des words et j'ai le meme probleme...

    De plus cette structure à deja fonctionner dans un autre programme.

    Je me demande si le probleme ne viens pas d'une declaration ou d'une option qui modifirait la définition des word (mais la c'est assez esotérique pour moi!)

    Bon, j'ai changer le nom de la variable et ca ne modifie pas grande chose...

  5. #5
    Membre confirmé
    Avatar de Philippe Gormand
    Inscrit en
    Mars 2002
    Messages
    330
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 330
    Points : 647
    Points
    647
    Par défaut TMemoryStream suite
    OK.

    Cela m'intrigue.
    Peux tu donner la définition complète de ta structure ?

    Effectivement, jai vérifié, On peut très bien redéclarer une variable
    ou un type avec le nom Word donc...
    Fais une recherche dans cette voie, qui sait ?

    A+

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    108
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 108
    Points : 89
    Points
    89
    Par défaut
    alors, voila tout le debut du programme:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, OoMisc, AdPort, TeEngine, Series, TeeProcs,
      Chart, AdPacket, Math, TeeGalleryPanel, ComCtrls, TeePolar, TeeRose, Unit2,
      TeeEdit;
     
    CONST nbCells = 20;
    CONST nbMesureMax = 288;
     
    type
      ArrayOfArrayOfReal = array[0..nbCells-1] of array[0..288] of real;
     
    type
      TForm1 = class(TForm)
        PageControl1: TPageControl;
        TabSheet1: TTabSheet;
        GroupBox1: TGroupBox;
        Label1: TLabel;
        GroupBox2: TGroupBox;
        Label2: TLabel;
        GroupBox5: TGroupBox;
        Label12: TLabel;
        GroupBox9: TGroupBox;
        Label3: TLabel;
        Label4: TLabel;
        Label8: TLabel;
        Label9: TLabel;
        Chart5: TChart;
        Series5: TWindRoseSeries;
        GroupBox10: TGroupBox;
        Label18: TLabel;
        Label19: TLabel;
        Label20: TLabel;
        Label21: TLabel;
        Chart6: TChart;
        Series6: TWindRoseSeries;
        GroupBox11: TGroupBox;
        Label5: TLabel;
        Label10: TLabel;
        Label6: TLabel;
        Label11: TLabel;
        Chart7: TChart;
        Series7: TWindRoseSeries;
        GroupBox12: TGroupBox;
        Label22: TLabel;
        Label23: TLabel;
        Label24: TLabel;
        Label25: TLabel;
        Chart8: TChart;
        Series8: TWindRoseSeries;
        GroupBox3: TGroupBox;
        Label14: TLabel;
        Label15: TLabel;
        Label16: TLabel;
        Label17: TLabel;
        Chart9: TChart;
        Series9: TWindRoseSeries;
        TabSheet2: TTabSheet;
        Label13: TLabel;
        GroupBox7: TGroupBox;
        Chart1: TChart;
        Series1: TLineSeries;
        Chart3: TChart;
        Series2: TLineSeries;
        GroupBox8: TGroupBox;
        Chart2: TChart;
        Series3: TLineSeries;
        Chart4: TChart;
        Series4: TLineSeries;
        ComboBox2: TComboBox;
        TabSheet3: TTabSheet;
        Memo1: TMemo;
        CheckBox2: TCheckBox;
        CheckBox1: TCheckBox;
        CheckBox3: TCheckBox;
        GroupBox4: TGroupBox;
        Label26: TLabel;
        GroupBox6: TGroupBox;
        Label27: TLabel;
        GroupBox13: TGroupBox;
        Label28: TLabel;
        ApdComPort1: TApdComPort;
        ApdDataPacket1: TApdDataPacket;
        GroupBox14: TGroupBox;
        Label29: TLabel;
        GroupBox15: TGroupBox;
        Label30: TLabel;
        Timer1: TTimer;
        ChartEditor1: TChartEditor;
        Timer2: TTimer;
        procedure Timer2Timer(Sender: TObject);
        procedure ComboBox2Change(Sender: TObject);
        procedure Chart5Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure ApdDataPacket1Packet(Sender: TObject; Data: Pointer;
          Size: Integer);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
        procedure ScrollingTableaux(var Tab: Array of real); Overload;
        procedure trace_courbes();
      private
        Procedure ScrollingTableaux(var Tab: Array of TDateTime); Overload;
        procedure ScrollingTableaux(var Tab: ArrayOfArrayOfReal); Overload;
      public
        //stockage des données pour les graphiques 6, 12, 24H
        // Interval 5 min => 12 relevés par heures => 288 relevés par 24 H
        courant_vit: ArrayOfArrayOfReal;
        courant_dir: ArrayOfArrayOfReal;
        vent_vit: array[0..288] of real;
        vent_dir: array[0..288] of real;
        heure_mesure: array[0..288] of Tdatetime;
        nbMesure, Echelle: integer;
        donneeManquantes: boolean;
      end;
     
    Type
      TAquaProPlusMTO = record
        Bof: array[0..4] of byte;
        sync: byte;
        id: byte;
        Taille: Word;
        //Taille: array[0..1] of byte;
        Date: array[1..6] of byte;
        error: word;
        AnaIn1: word;
        battery: smallint;
        SndSpeed: word;
        heading: word;
        Pitch: smallint;
        Roll: smallint;
        PressureMSB: byte;
        Status: byte;
        PressureLSW: word;
        Temperature: word;
        spd: array[0..2] of array[0..nbCells-1] of smallint;
        Amp: array[0..2] of array[0..nbCells-1] of byte;
    //  bof3: byte;
        CheckSum: smallint;
        syncMTO: byte;
        idMTO: byte;
        WdMoy: word;
        WsMoy: word;
        WdMax: word;
        WsMax: word;
        TemperatureMTO: word;
        PressionMTO: word;
        Humidite: word;
        CheckSumMOT: smallint;
    end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
    C'est long mais il y a tout...

  7. #7
    Membre confirmé
    Avatar de Philippe Gormand
    Inscrit en
    Mars 2002
    Messages
    330
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 330
    Points : 647
    Points
    647
    Par défaut
    Je ne vois rien d'anormal dans ta structure. C'est correcte.
    Tu dis qu'elle fonctionnait dans d'autres programmes ! Se serait donc
    la façon dont tu l'utilise dans ton nouveau programme. Recherche de ce
    coté. Le problème ne viendrait il pas de la façon ou du type de variable ou
    procédure pour récupérer les valeurs ?

    Désolé, je ne peux pas t'n dire plus.

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    108
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 108
    Points : 89
    Points
    89
    Par défaut
    Merci...

    Bon, je repars de zero et on vera bien. Ca sent la connerie de base, mais
    je ne la voie pas...

    Je vous tiens au courrant!

  9. #9
    Expert éminent Avatar de Graffito
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    5 993
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 5 993
    Points : 7 903
    Points
    7 903
    Par défaut
    Bonjour,

    Je pense que le problème vient de l'alignement :
    - soit on déclare TAquaProPlusMTO = packed record,
    - soit (je préfére) on aligne en mettant des bytes de Padding dans le record.

    Dans ton cas, il en faut 1 entre "id" et "taille" et, si nbcells est impair, 1 entre amp et checksum.

Discussions similaires

  1. definition des axes avec gnuplot
    Par willem77 dans le forum Autres éditeurs
    Réponses: 1
    Dernier message: 05/04/2006, 15h23
  2. Definition des tables
    Par ghyosmik dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 02/12/2005, 23h10
  3. Charte de definitions des "champs ou rubriques" d'
    Par elcondore dans le forum Décisions SGBD
    Réponses: 1
    Dernier message: 30/04/2005, 18h50
  4. [LG]definitions des Instruments carte Adlib
    Par Alkangelis dans le forum Langage
    Réponses: 2
    Dernier message: 03/11/2004, 13h41
  5. [FB 1.5][BCB5]Definition des colonnes des tables systemes ?
    Par Sitting Bull dans le forum Débuter
    Réponses: 2
    Dernier message: 13/10/2004, 19h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo