public static byte[] WriteZero(int[] theSumCurrent)
        { 
            List<byte> sc = new List<byte>();
            try
            {
                sc.Add(Convert.ToByte(0x10 & 0xff));
                sc.Add(Convert.ToByte(0x10 >> 8 & 0xff));
                sc.Add(Convert.ToByte(0x00 & 0xff));
                sc.Add(Convert.ToByte(0x00 >> 8 & 0xff));
                for (int i = 0; i < theSumCurrent.Length; i++)
                {

                    sc.Add(Convert.ToByte(theSumCurrent[i] & 0xff));
                    sc.Add(Convert.ToByte(theSumCurrent[i] >> 8 & 0xff));
                }

                string theLength = sc.Count.ToString("X2").PadLeft(4, '0');
                sc[2] = Convert.ToByte(ByteWithString.strToToHexByte(theLength)[1]);
                sc[3] = Convert.ToByte(ByteWithString.strToToHexByte(theLength)[0]);
               
            }
            catch (Exception msg)
            {
                throw msg;
            }
            return sc.ToArray();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发送设定的参数
        /// </summary>
        /// <param name="address"></param>
        /// <param name="groupNumber"></param>
        /// <param name="parameterCount"></param>
        /// <param name="addressArray"></param>
        /// <param name="valueArray"></param>
        public bool ResponseSettingParameter(byte[] address, string groupNumber, List <string> addressArray, List <string> valueArray)
        {
            bool flag = true;

            try
            {
                ResponseValueData theResponseValueData = new ResponseValueData();
                theResponseValueData.DEVICE_ADDRESS        = address;
                theResponseValueData.VALUE_TYPE            = ByteWithString.strToToHexByte(groupNumber)[0];
                theResponseValueData.VALUE_COUNT           = (byte)addressArray.Count;
                theResponseValueData.theResponseValueArray = new List <ResponseValue>();
                for (int i = 0; i < addressArray.Count; i++)
                {
                    byte[]        theBytes         = ByteWithString.strToToHexByte(addressArray[i]);
                    ResponseValue theResponseValue = new ResponseValue();
                    theResponseValue.VALUE_ADDRESS = new byte[] { theBytes[1], theBytes[0] };
                    theResponseValue.VALUE         = StringConvertByte(addressArray[i], valueArray[i]);
                    theResponseValue.VALUE_LENGTH  = (byte)theResponseValue.VALUE.Length;
                    theResponseValueData.theResponseValueArray.Add(theResponseValue);
                }
                ClientReport theClientReport = CreateClientReport <ResponseValueData>(0x15, theResponseValueData);
                byte[]       bytes           = theScoket.clientReportUnSerialize(theClientReport);
                if (bytes.Length > 0)
                {
                    theScoket.sendInfo(bytes);
                }
            }
            catch (Exception msg)
            {
                Log.LogWrite(msg);
            }
            return(flag);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 读取文件流转存到字节数组
 /// </summary>
 /// <param name="filePath"></param>
 /// <returns></returns>
 public static byte[] FileStreamTobyteArray(string filePath)
 {
     byte[] buffer;
     using (StreamReader sr = new StreamReader(filePath))
     {
         filePath = sr.ReadToEnd();
         buffer   = ByteWithString.strToToHexByte(filePath.Replace(" ", ""));
     }
     return(buffer);
 }
 public static string  WriteCFG(string filePath)
 {
     string showText = "";
     filePath = filePath.Replace(".dat", ".cfg");
     if (File.Exists(filePath))
     {
         //cfg
         using (StreamReader sr = new StreamReader(filePath))
         {
             showText = Encoding.ASCII.GetString(ByteWithString.strToToHexByte(sr.ReadToEnd()));
             showText = showText.Replace("\0", "").Replace(" ", "");
             string sunString = Regex.Match(showText, @"01,IA1(.*?)P").Groups[1].Value;
             string newShowText = Regex.Match(showText, @"06(.*?)P").Value;
             string reNewShowText = newShowText + "\r\n" + "07,IZ1" + sunString + "P";
             showText = showText.Replace(newShowText, reNewShowText);
             sr.Close();
         }
     }
     return showText;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 发送
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public byte[] clientReportUnSerialize(ClientReport data)
        {
            List <byte> reportList = new List <byte>();

            try
            {
                reportList.Add(0x03);
                reportList.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00 });
                reportList.Add(data.CONTROL_FIELD);
                switch (data.CONTROL_FIELD)
                {
                case 0x01:    //Login
                    LoginReport lr = (LoginReport)data.REPORT_BODY;
                    reportList.Add(lr.USERNAME_LENGTH);
                    reportList = reportList.Concat(lr.USERNAME).ToList();
                    reportList.Add(lr.PASSWORD_LENGTH);
                    reportList = reportList.Concat(lr.PASSWORD).ToList();
                    break;

                case 0x04:    //DataGridView
                    TheCatalog theCatalog = (TheCatalog)data.REPORT_BODY;
                    reportList = reportList.Concat(theCatalog.DEVICE_ADDRESS).ToList();
                    reportList = reportList.Concat(theCatalog.CATALOG_NAME).ToList();
                    break;

                case 0x06:    //UpdataFileInfo
                    CatalogFiles theCatalogFiles = (CatalogFiles)data.REPORT_BODY;
                    reportList = reportList.Concat(theCatalogFiles.DeviceAddress).ToList();
                    reportList.Add(theCatalogFiles.FILE_LENGTH);
                    reportList = reportList.Concat(theCatalogFiles.FILE_NAME).ToList();
                    break;

                case 0x09:    //RequestRemoteData(请求遥信)
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x13:    //设备状态
                    string[] str = (data.REPORT_BODY as string).Split('|');
                    reportList = reportList.Concat(ByteWithString.strToToHexByte(str[0])).ToList();
                    reportList = reportList.Concat(ByteWithString.strToToHexByte(str[1])).ToList();
                    break;

                case 0x15:    //
                    ResponseValueData theResponseValueData = (ResponseValueData)data.REPORT_BODY;
                    reportList = reportList.Concat(theResponseValueData.DEVICE_ADDRESS).ToList();
                    reportList.Add(theResponseValueData.VALUE_TYPE);
                    reportList.Add(theResponseValueData.VALUE_COUNT);
                    for (int i = 0; i < theResponseValueData.theResponseValueArray.Count; i++)
                    {
                        string ss = ByteWithString.byteToHexStr(theResponseValueData.theResponseValueArray[i].VALUE_ADDRESS);
                        reportList = reportList.Concat(theResponseValueData.theResponseValueArray[i].VALUE_ADDRESS).ToList();
                        reportList.Add(theResponseValueData.theResponseValueArray[i].VALUE_LENGTH);
                        reportList = reportList.Concat(theResponseValueData.theResponseValueArray[i].VALUE).ToList();
                    }
                    break;

                case 0x17:
                    reportList = reportList.Concat((data.REPORT_BODY as TheCatalog).CATALOG_NAME).ToList();
                    break;

                case 0x18:
                    reportList = reportList.Concat((data.REPORT_BODY as TheCatalog).CATALOG_NAME).ToList();
                    break;

                case 0x19:
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x20:
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x22:
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x27:    //维护变电站
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x28:    //维护变电站
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x29:    //维护变电站
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x30:    //维护变电站
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x31:    //维护变电站
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x32:
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x34:    //获取线路参数
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x36:    //设定定时执行参数
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x37:    //请求返回设定参数
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                case 0x39:    //上传文件
                    reportList = reportList.Concat((byte[])data.REPORT_BODY).ToList();
                    break;

                default: break;
                }
                reportList.Add(0x00);
                reportList.Add(0x16);
                reportList[reportList.Count - 2] = makeValidateField(reportList);
                reportList[1] = Convert.ToByte(reportList.Count >> 24 & 0xff);
                reportList[2] = Convert.ToByte(reportList.Count >> 16 & 0xff);
                reportList[3] = Convert.ToByte(reportList.Count >> 8 & 0xff);
                reportList[4] = Convert.ToByte(reportList.Count & 0xff);
            }
            catch (Exception msg)
            {
                Log.LogWrite(msg);
            }
            return(reportList.ToArray <byte>());
        }
Ejemplo n.º 6
0
 public static byte[] returnByteLength(string str, int count)
 {
     str = str.PadLeft(count, '0');
     return(ByteWithString.strToToHexByte(str));
 }