Hello experts,

I'm currently trying to make program that sends commands to my home security system. I have it connected to my computer trough the COM port, this feature allow me to control my system by sending hex ASCII codes.

I hope that someone could help me make a function that converts the command numbers into hex ASCII codes, calculates the checksum and adds the end of packet codes.

Here is an example of a complete command:

One of the commands I want to send is: “6543”.
The ASCII codes for this would be: 36 35 34 33

The Checksum = 36+35+34+33 = D2
D = 44 (ASCII)
2 = 32 (ASCII)

“0D” and “0A” needs to be added at the end of the transmission (End of Packet).

The complete transmission need to be in a continuous string. In this example the finalized string would be: 3635343344320D0A.


Thanks,
Salomon

I have made some progress but I am struggling with calculating the checksum and adding the end of packet signs.

I will use this code to convert the numbers into Hex ASCII code:

#region StringToHex

        public string ConvertToHex(string msgtext)
        {
            string hex = "";
            foreach (char c in msgtext)
            {
                int tmp = c;
                hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));
            }

            return hex;
        }
        #endregion
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.