123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- namespace FileAnalysis
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- TCPClient client;
- private const int bufferSize = 8000;
- private void Analysis_Click(object sender, EventArgs e)
- {
- //client.Send("A110S001H01B1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
- //client.Send("41 31 31 30 53 30 30 31 48 30 31 42 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 AF E4");
- //string sss= BinTohex("A110S001H10R1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
- string sss = BinTohex("B008S001GM");
- client.Send(sss);
- }
- private string GETMD5(string password)
- {
- //初始化MD5对象
- MD5 md5 = MD5.Create();
- //将源字符串转化为byte数组
- Byte[] soucebyte = Encoding.Default.GetBytes(password);
- //soucebyte转化为mf5的byte数组
- Byte[] md5bytes = md5.ComputeHash(soucebyte);
- //将md5的byte数组再转化为MD5数组
- StringBuilder sb = new StringBuilder();
- foreach (Byte b in md5bytes)
- {
- //x表示16进制,2表示2位
- sb.Append(b.ToString("x2"));
- }
- return sb.ToString();
- }
- public static ushort CalculateCRC(byte[] data)
- {
- ushort crc = 0xFFFF;
- foreach (byte b in data)
- {
- crc ^= b;
- for (int i = 0; i < 8; i++)
- {
- if ((crc & 0x0001) != 0)
- {
- crc >>= 1;
- crc ^= 0xA001;
- }
- else
- {
- crc >>= 1;
- }
- }
- }
- // Swap bytes to get the correct Modbus CRC16 format
- return (ushort)((crc << 8) | (crc >> 8));
- }
- public static string BinTohex(string mBin)
- {
- char[] values = mBin.ToCharArray();
- int tempI;
- StringBuilder WRSCodeSB = new StringBuilder();
- foreach (char value in values)
- {
- tempI = Convert.ToInt32(value);
- WRSCodeSB.Append(Convert.ToString(tempI, 16).PadLeft(2, '0'));
- }
- return WRSCodeSB.ToString();
- }
- public static int[] GetDecimalData(string HexStr, int[] DataSize, int[] NotShow)
- {
- List<int> ReturnData = new List<int>();
- try
- {
- //去除前面的指令字符和数据长度字符
- HexStr = HexStr.Replace(":", "");
- if (HexStr != "")
- {
- int ValueDataSize = Convert.ToInt32("0x" + (HexStr.Substring(4, 2)), 16) * 2;
- string RealData = HexStr.Substring(6);
- RealData = RealData.Substring(0, ValueDataSize);
- int SubIndex = 0;
- for (int i = 0; i < DataSize.Length; i = i + 1)
- {
- if (SubIndex + DataSize[i] < RealData.Length)
- {
- bool notshow = false;
- for (int j = 0; j < NotShow.Length; j++)
- {
- if (i == NotShow[j])
- notshow = true;
- }
- if (notshow)
- {
- SubIndex += DataSize[i];
- continue;
- }
- if (DataSize[i] == 8)
- {
- Console.WriteLine("0x" + (RealData.Substring(SubIndex, DataSize[i]).Substring(4, 4)) + (RealData.Substring(SubIndex, DataSize[i]).Substring(0, 4)));
- ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(SubIndex, DataSize[i]).Substring(4, 4)) + (RealData.Substring(SubIndex, DataSize[i]).Substring(0, 4)), 16));
- }
- else if (DataSize[i] == 4)
- {
- Console.WriteLine("0x" + (RealData.Substring(SubIndex, DataSize[i])));
- ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(SubIndex, DataSize[i])), 16));
- }
- }
- SubIndex += DataSize[i];
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- return ReturnData.ToArray();
- }
- string nextLine;
- private void Form1_Load(object sender, EventArgs e)
- {
- client = new TCPClient("172.16.15.10", "1030", "", "");
- //label1.BackColor = Color.GreenYellow;
- //string json = "";
- //string json1 = "";
- //MESHelper mes = new MESHelper();
- //mes.GetMobileAllInfo("Q32024040002", out json1, out json);
- //////mes.GetMobileAllInfo("F45112235030001", out json1, out json);
- //Console.WriteLine(json1);
- //Console.WriteLine(json);
- //StreamReader sR = new StreamReader(@"C:\Users\callm\Desktop\Android\036653943B010A11-C.txt", Encoding.Default);
- //while ((nextLine = sR.ReadLine()) != null)
- //{
- // ReturnData.AppendText(nextLine.ToString() + "\n");
- //}
- }
-
- }
- }
|