mouloud42
Messages postés3Date d'inscriptionvendredi 21 novembre 2008StatutMembreDernière intervention11 mai 2009
-
11 mai 2009 à 20:04
Lutinore
Messages postés3246Date d'inscriptionlundi 25 avril 2005StatutMembreDernière intervention27 octobre 2012
-
12 mai 2009 à 19:43
salut,
j'ai un pb de compilation quand je met ce code, à chaque déclarations le compilo m'envoie boulé quand c'est pas une varialb c'est l'autre, un calvaire, ça fait 2 jours que je bloque là, en C ça marche mais en C# je mouline, si vous aver une idée. Merci
//structure d'un octect accessible bit à bit
[System.Runtime.InteropServices.
StructLayout(
LayoutKind.Explicit)]
struct
byte_bool_struct
{
[System.Runtime.InteropServices.
FieldOffset(0)]
BitArray b =
new
BitArray(8);
[System.Runtime.InteropServices.
FieldOffset(0)]
byte octet;
};
//structure mise corélation entre les infos accessibles
//du programme et le Buffer envoyé a l'USB
[System.Runtime.InteropServices.
StructLayout(
LayoutKind.Explicit)]
struct
Send_USB
{
[System.Runtime.InteropServices.
FieldOffset(0)]
byte Always_Zero;
[System.Runtime.InteropServices.
FieldOffset(1)]
fixed
byte_bool_struct digital[8];
[System.Runtime.InteropServices.
FieldOffset(9)]
Int16[] ana =
new
Int16[8];
[System.Runtime.InteropServices.
FieldOffset(25)]
byte LCD_command;
[System.Runtime.InteropServices.
FieldOffset(26)]
byte[] LCD_charatere_ligne =
new
Byte[20];
[System.Runtime.InteropServices.
FieldOffset(26)]
string LCD_ligne;
[System.Runtime.InteropServices.
FieldOffset(0)]
byte[] Buffer =
new
Byte[65];
};
//structure mise corélation entrees les infos accessibles
//du programme et le Buffer lu sur l'USB
[System.Runtime.InteropServices.
StructLayout(
LayoutKind.Explicit)]
struct
Receive_USB
{
[System.Runtime.InteropServices.
FieldOffset(0)]
byte_bool_struct digital[8];
[System.Runtime.InteropServices.
FieldOffset(8)]
Int16[] ana =
new
Int16[8];
[System.Runtime.InteropServices.
FieldOffset(0)]
byte[] Buffer =
new
Byte[64];
};
//déclaration
public
Send_USB TX_Report;
public
Receive_USB RX_Report;
Lutinore
Messages postés3246Date d'inscriptionlundi 25 avril 2005StatutMembreDernière intervention27 octobre 201241 12 mai 2009 à 19:16
Salut, il y'a beaucoup d'erreurs, apparemment tu ne sais pas marshaller les tableaux en C#.. Les tableaux ne sont pas inlines c'est des références ( des pointeurs ) , donc dans une structure, peu importe sa taille un tableau fait toujours 4 ou 8 octets.. On ne peut pas initialiser directement le tableau dans la structure.. il faut soit utiliser l'attribut MarshalAs pour simuler un tableau inline soit utiliser du code unsafe avec le mot clé fixed pour définir un vrai tableau inline.. etc..