First of all, a google docs is no way to share code bear that in mind for next questions. I cant really test your code, but from what i read in the documentacion of this GPS. I can tell you that your IMEI problem is that you are not desearializing it well.
According to the documentacion the Login Message Packet has 18 bytes, and its divided this way in order
- 2 as start bit
- 1 for the length of the package
- 1 for the protocol number (in this case protocol 1 or 0x01)
- 8 for the IMEI as a example this IMEI 123456789123456 gets sent like this: 0x01 0x23 0x45 0x67 0x89 0x120x34 0x56
- 2 for serial information on the number
- 2 for error check
- and 2 more for stop
Here is your line where you deserialize it:
string IMEI = Encoding.ASCII.GetString(receiveMessage.Skip(4).Take(messageLength - 5).ToArray());
To begin with there is no need to make a calculation on how many you should take, they will always be 8 so receiveMessage.Skip(4).Take(8).ToArray()
Then there is the problem with the encoding, you dont want to convert those numbers into their ascii char, you want only to take the numbers being writen as a hex string, removing the dashes that generates the method, and removing the leading zero if any exists
BitConverter.ToString(ByteArr).Replace("-","").TrimStart('0')
This is how your IMEI variable should look like:
string IMEI = BitConverter.ToString(receiveMessage.Skip(4).Take(8).ToArray()).Replace("-","").TrimStart('0');
CLICK HERE to find out more related problems solutions.