A few days ago, I gave a rough idea about the basis of smart energy meter development. Today I want to develop and control the trip, closing, alarm, alarm relief, power preservation and power cancellation of the remote smart electric meter;
Let's take a look at the functions in testzhuzhan. dll.
1. Identity Authentication Functions
Function Name identityauthentication (char * Div, char * randandendata)
Function Identity Authentication random number and ciphertext
Div, input parameter, 8-byte dispersion factor, hexadecimal string.
Parameter description randandendata, output parameter, bytes type, 8-byte Random Number + 8 bytes
Ciphertext.
Success indicates 0. Success;
200. Failed to connect to the encryptor;
201. An error occurred while obtaining random number 1;
202. An error occurred while obtaining random number 2;
203. Key dispersion failed;
204. Data Encryption failed;
205. failed to retrieve the ciphertext;
2. Remote Control Functions
Function Name usercontrol (char * randdivesamnumdata, char * dataout)
Function remote control
Randdivesamnumdata, input parameter, random type, 4-byte Random Number
Parameter description + 8-byte dispersion factor + 8-byte Esam serial number + Data plaintext.
Dataout, ciphertext, 20-byte ciphertext
Success indicates 0. Success;
200. Failed to connect to the encryptor;
201. failed to write the card;
202. card reading failed;
203. ciphertext calculation failed;
(The above function test in the RD-1000 Card Reader plug in the test mother card.
C # code
Reference DLL first:
/// <Summary> /// identity authentication function Author: longyi // </Summary> /// <Param name = "Div"> 8-byte dispersion factor, hexadecimal string </param> /// <Param name = "randandendata"> 8-byte Random Number + 8-byte ciphertext. </Param> /// <returns> 0, successful; 200, failed to connect to the encryptor; 201, failed to get random number 1; 202, failed to get random number 2; 203, failed to scatter key; 204, data encryption failed; 205, ciphertext retrieval failed; </returns> [dllimport ("testzhuzhan. DLL ")] public static extern int identityauthentication (string Div, byte [] randandendata); // <summary> // Remote Control Function Author: longyi // </Summary> /// <Param name = "randdivesamnumdata"> 4-byte Random Number + 8-byte dispersion factor + 8-byte Esam serial number + Data plaintext </param>/ // <Param name = "dataout"> 20-byte ciphertext </param> /// <returns> 0, successful; 200, failed to connect to the encryptor; 201, failed to write the card; 202, failed to read the card; 203, failed to calculate the ciphertext; </returns> [dllimport ("testzhuzhan. DLL ", charset = charset. ANSI)] public static extern int usercontrol (string randdivesamnumdata, byte [] dataout );
Call DLL files
String DIV = "0000000000000008"; // <summary> // Identity Authentication random number and ciphertext Author: longyi // </Summary> /// <Param name = "randandendata"> returns an 8-byte Random Number + 8-byte ciphertext. </Param> /// <returns> 0, successful; 200, failed to connect to the encryptor; 201, failed to get random number 1; 202, failed to get random number 2; 203, failed to scatter key; 204, data encryption failed; 205, ciphertext retrieval failed </returns> Public int getidentityauthentication (out string randandendata) {byte [] value = new byte [32]; int Index = testzhuzhan. identityauthentication (DIV, value); randandendata = encoding. utf8.getstring (value); Return Index ;}/// <summary> /// obtain the 20-byte ciphertext: longyi // </Summary> // <Param name = "N1"> Control Code </param> /// <Param name = "random2"> Random Number 2 </param> // <Param name = "esamid"> Esam serial number </param> /// <Param name = "Date "> command validity deadline </param> // <Param name =" ciphertext "> return: 20-byte ciphertext </param> // <returns> 0, successful; 200, failed to connect to the encryptor; 201, failed to write the card; 202, failed to read the card; 203, failed to calculate ciphertext </returns> Public int getpassword2 (string N1, byte [] random2, byte [] esamid, datetime date, out string ciphertext) {// 4-byte Random Number + 8-byte dispersion factor + 8-byte Esam serial number + Data plaintext (N1-Nm ). Stringbuilder STR = new stringbuilder (); // 4-byte random number Str. append (Common. gethex (random2 [3]); Str. append (Common. gethex (random2 [2]); Str. append (Common. gethex (random2 [1]); Str. append (Common. gethex (random2 [0]); // 8-byte dispersion factor "0000000000000002" str. append (DIV); // 8-byte Esam serial number Str. append (Common. gethex (esamid [7]); Str. append (Common. gethex (esamid [6]); Str. append (Common. gethex (esamid [5]); Str. append (Common. gethex (esamid [4]); Str. append (Common. gethex (esamid [3]); Str. append (Common. gethex (esamid [2]); Str. append (Common. gethex (esamid [1]); Str. append (Common. gethex (esamid [0]); // N1 control code Str. append (N1); // reserved character Str. append ("00"); // effective end date of the command Str. append (date. tostring ("yymmddhhmmss"); byte [] readdata = new byte [40]; int Index = testzhuzhan. usercontrol (Str. tostring (), readdata); ciphertext = encoding. utf8.getstring (readdata); Return Index ;}