0

I want to pass a struct into another struct but the error i get is "name" doesn't exist in the current context , it's not included . How to make it known for the other struct

public struct iec_unit_id
    {
        internal byte iec_unit_id_data1;
        internal byte iec_unit_id_data2;

        public byte type_id;         //Type_identification

        public byte num
        {
            get            { return (byte)(iec_unit_id_data1 & 0x7f); }
            set            { iec_unit_id_data1 = (byte)((iec_unit_id_data1 & ~0x7f) | (value & 0x7f)); }
        }                                 //Number of Objects:7;
        public byte sq
        {
            get
            { return (byte)((iec_unit_id_data1 >> 7) & 0x01); }
            set
            { iec_unit_id_data1 = (byte)((iec_unit_id_data1 & ~(0x01 << 7)) | (value & 0x01) << 7); }
        }                                 // sequenced/not sequenced address:1;

        public byte cause
        {
            get            { return (byte)(iec_unit_id_data2 & 0x3f); }
            set            { iec_unit_id_data2 = (byte)((iec_unit_id_data2 & ~0x3f) | (value & 0x3f)); }
        }                             //cause of transmission:6;
        public byte pn
        {
            get            { return (byte)((iec_unit_id_data2 >> 6) & 0x01); }
            set            { iec_unit_id_data2 = (byte)((iec_unit_id_data2 & ~(0x01 << 6)) | (value & 0x01) << 6); }
        }                               // pn:1; positive=1 negative=0
        public byte t
        {
            get            { return (byte)((iec_unit_id_data2 >> 7) & 0x01); }
            set            { iec_unit_id_data2 = (byte)((iec_unit_id_data2 & ~(0x01 << 7)) | (value & 0x01) << 7); }
        }                               // test : 1;


        public byte oa;             //Originator Adress
        public ushort ca;           // ASDU Common Adress
    }

    public struct iec_apdu
    {
        byte start;
        byte length;
        byte NS;
        byte NR;
        struct iec_unit_id asdu ;
    }

The name of the struct variable is asdu ;

Rafał Czabaj
  • 720
  • 7
  • 16
  • 1
    try change "struct iec_unit_id asdu ;" to "iec_unit_id asdu ;" – Henningsson May 02 '16 at 12:24
  • It's totally unclear what you are asking. I don't see what you are trying to do. Where do you want to pass what in the struct? – ckruczek May 02 '16 at 12:24
  • Watch out for mutable structs, they might give unexpected results. See http://stackoverflow.com/questions/441309/why-are-mutable-structs-evil – Hans Kesting May 02 '16 at 12:31

1 Answers1

4

Remove the struct keyword, use it like a normal variable like:

public struct iec_apdu
{
     iec_unit_id asdu;
}
L-Four
  • 13,345
  • 9
  • 65
  • 109