Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have the following enum:

C#
public enum Command_ID : uint 
    {
        none = 0x0,
        generic_nack = 0x80000000,
        bind_receiver = 0x00000001,
        bind_receiver_resp = 0x80000001,
        bind_transmitter = 0x00000002,
        bind_transmitter_resp = 0x80000002,
        query_sm = 0x00000003,
        query_sm_resp = 0x80000003,
        submit_sm = 0x00000004,
        submit_sm_resp = 0x80000004,
        deliver_sm = 0x00000005,
        deliver_sm_resp = 0x80000005,
        unbind = 0x00000006,
        unbind_resp = 0x80000006,
        replace_sm = 0x00000007,
        replace_sm_resp = 0x80000007,
        cancel_sm = 0x00000008,
        cancel_sm_resp = 0x80000008,
        bind_transceiver = 0x00000009,
        //bind_transceiver = 9,
        bind_transceiver_resp = 0x80000009,
        outbind = 0x0000000B,
        enquire_link = 0x00000015,
        enquire_link_resp = 0x80000015,
        submit_multi = 0x00000021,
        submit_multi_resp = 0x80000021,
        alert_notification = 0x00000102,
        data_sm = 0x00000103,
        data_sm_resp = 0x80000103,
    }


I am trying to use the enum as follow:

C#
packet.CmdID = PDU.Command_ID.bind_transceiver;


After this, I am decoding this into an PDU packet (Hex format). Please note, all other necessary information is presented, just not pasted here.

After this I am encoding the entire object to an PDU. When I send this to the SMSC (Short Message Service Centre) simulator, it return the error that the command id is incorrect.

what I would like to know is, what value is actually being returned by the enum Command_ID, is it "bind_transceiver"? if I use the following code
C#
uint x = (uint)Enum.Parse(typeof(PDU.Command_ID), Enum.GetName(typeof(PDU.Command_ID), id));


it returns 9. How can I get the Enum to return 0x00000009??

Thanks for any help in advance
Posted
Comments
Sergey Alexandrovich Kryukov 28-Mar-12 10:42am    
Why do you think 9 and 0x00000009 are not the same? :-)
--SA
Andrew797 28-Mar-12 10:49am    
sorry if I am mistaken, but when encoding to the pdu, will the 0x0000000 in front of the 9 not change the format of the pdu?
Sergey Alexandrovich Kryukov 28-Mar-12 21:32pm    
There is not such thing as "format". This is a value of some integer type, in two's complement binary standard:
http://en.wikipedia.org/wiki/Two%27s_complement
--SA
johannesnestler 28-Mar-12 12:16pm    
Command_ID is a string?
Andrew797 28-Mar-12 14:31pm    
here is the PDU.Packet class:

public class PDUPacket
{
public uint Length = 0x00;
public Command_ID CmdID = Command_ID.none;
public Command_status CmdStatus = Command_status.ESME_ROK;
public uint SeqNo = 0x00;
public List<object> Body = new List<object>();
}

should I add the encoder source code?? maybe something is wrong?

Please see my comment to the question. They are the same. Enumeration member values associated with each member are of one of the integer types, not of the string type. What you observe is some particular string representation, which you should not care of.

However, if you need to output strings somewhere in some certain format, learn string formatting. Please see:
http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx[^];

for example:
http://msdn.microsoft.com/en-us/library/cht2hdff.aspx[^],
http://msdn.microsoft.com/en-us/library/8wch342y.aspx[^],
http://msdn.microsoft.com/en-us/library/d830955a.aspx[^];

and the formats are:
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].

First of all, you might need to understand how numeric types work. Please see my article:
Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^].

—SA
 
Share this answer
 
Comments
ProEnggSoft 29-Mar-12 1:31am    
5!
Sergey Alexandrovich Kryukov 29-Mar-12 10:52am    
Thank you.
--SA
This should help:

C#
class Program
{
    public enum someEnums
    {
        someEnum = 0x00000009
    }
    static void Main(string[] args)
    {
       string x = string.Format("0X{0:X8}", (int)someEnums.someEnum);
        Console.WriteLine ( x);
        Console.ReadLine();
    }
}
 
Share this answer
 
Comments
Andrew797 29-Mar-12 6:05am    
Thanks for the help. It solved my problem :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900