(Original)-Intelligent Energy Meter SM1 algorithm development kit (main station interface) development

Source: Internet
Author: User

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 ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.