/// <summary> /// 更新SQLLite数据库的遥测/遥信数据 /// </summary> /// <param name="theRemoteData"></param> /// <param name="list">设备地址</param> /// <param name="name">遥测/遥信</param> /// <returns></returns> internal ReadSqlLiteData toReadSqlLiteData(TheRemoteData theRemoteData, List <byte> list, string name) { ReadSqlLiteData theReadSqlLiteData = new ReadSqlLiteData(); switch (name) { case "遥测": theReadSqlLiteData.theAddress = ByteWithString.byteToHexStr(list.ToArray());//设备地址 theReadSqlLiteData.theDataAddress = ByteWithString.byteToHexStr(theRemoteData.RemoteAddress).ToLower(); theReadSqlLiteData.theNumber = ((theRemoteData.RemoteValue[1] << 8) | theRemoteData.RemoteValue[0]).ToString(); theReadSqlLiteData.theValue = theRemoteData.quility.ToString("X2").ToLower(); break; case "遥信": theReadSqlLiteData.theAddress = ByteWithString.byteToHexStr(list.ToArray()); //设备地址 theReadSqlLiteData.theDataAddress = ByteWithString.byteToHexStr(theRemoteData.RemoteAddress); theReadSqlLiteData.theNumber = ByteWithString.byteToHexStr(theRemoteData.RemoteValue); //值 if (theRemoteData.LastestModify != null && theRemoteData.LastestModify.Length > 0) { theReadSqlLiteData.theValue = ByteWithString.ConvertCP56TIME2aToDateTime(theRemoteData.LastestModify).ToString("yyyy-MM-dd HH:mm:ss"); } else { theReadSqlLiteData.theValue = ""; } break; default: break; } return(theReadSqlLiteData); }
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(); }
internal string ToCodeValue(string address, byte[] responseValue) { string retValue = ""; switch (theKeyValueAddress.SearchKey(address)) { case "ASCII": retValue = Encoding.ASCII.GetString(responseValue); break; case "HEX": retValue = ByteWithString.byteToHexStrAppend(responseValue, " "); break; case "DEC": retValue = (responseValue[1] << 8 | responseValue[0]).ToString(); break; case "IP": retValue = responseValue[0].ToString() + "." + responseValue[1].ToString() + "." + responseValue[2].ToString() + "." + responseValue[3].ToString(); break; default: break; } return(retValue); }
/// <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); }
/// <summary> /// 获得设备状态 0x01 /// </summary> /// <param name="p"></param> internal void RequestDeviceStar(byte[] p, string code) { ClientReport theClientReport = CreateClientReport <string>(0x13, ByteWithString.byteToHexStr(p) + "|" + code); byte[] bytes = theScoket.clientReportUnSerialize(theClientReport); if (bytes.Length > 0) { theScoket.sendInfo(bytes); } }
/// <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 string ToSixString(byte[] p, int number) { string strKeyValue = ByteWithString.byteToHexStr(p); if (number >= 1) { strKeyValue = theKeyValueRemote.SearchKey(strKeyValue);//遥信 } else { strKeyValue = theKeyValueTelemetering.SearchKey(strKeyValue);//遥测 } return(strKeyValue); }
internal List <TheRemoteData> UpdateTheRemoteDataArray(List <TheRemoteData> theRemoteData) { for (int i = 0; i < theRemoteData.Count; i++) { theRemoteData[i].RemoteName = ToSixString(theRemoteData[i].RemoteAddress, 1); theRemoteData[i].RemoteValueStr = ByteWithString.byteToHexStr(theRemoteData[i].RemoteValue); theRemoteData[i].RemoteAddressStr = ByteWithString.byteToHexStr(theRemoteData[i].RemoteAddress); if (theRemoteData[i].LastestModify != null && theRemoteData[i].LastestModify.Length > 0) { theRemoteData[i].LastestModifStr = ByteWithString.ConvertCP56TIME2aToDateTime(theRemoteData[i].LastestModify).ToString("yyyy-MM-dd HH:mm:ss"); } } return(theRemoteData); }
/// <summary> /// 封装删除的方法 /// </summary> /// <param name="dt">操作的表名</param> /// <param name="name">选中的列明</param> /// <param name="byt">操作标识</param> /// <param name="msg">要提示的消息</param> public void deleteSelectRow(DataGridView dt, string name, byte byt, string msg) { if (dt.SelectedRows.Count <= 0) { HandelControls.Msg("请选择要删除的数据"); return; } if (HandelControls.Msg(msg, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { List <byte> bytes = new List <byte>(); bytes.Add(byt); string id = dt.SelectedRows[0].Cells[name].Value.ToString(); bytes.AddRange(ByteWithString.intTo4Byte(int.Parse(id)).ToList()); theScoket.theSocketSend <byte[]>(0x32, bytes.ToArray()); } }
internal List <PortChartData> ChartShowNew(string pullPathFile, out List <string> listName) { List <PortChartData> theListPortChartData = new List <PortChartData>(); int Index = 1; listName = new List <string>(); int nowIndex = 0; try { string newPath = pullPathFile.Replace(".dat", ".cfg"); using (StreamReader sr = new StreamReader(newPath)) { sr.ReadLine(); int myCount = int.Parse(Regex.Match(sr.ReadLine().Split(',')[1].Trim(), @"^[0-9]+").Value); for (int i = 0; i < myCount; i++) { listName.Add(sr.ReadLine().Split(',')[1]); } using (FileStream sf = new FileStream(Path.GetFullPath(pullPathFile), FileMode.Open)) { byte[] bytes = new byte[sf.Length]; sf.Read(bytes, 0, bytes.Length); int count = bytes.Length / 48; List <PortChartLineData> lines = new List <PortChartLineData>(); for (nowIndex = 0; nowIndex < count; nowIndex++) { List <byte> bs = bytes.Skip(nowIndex * 48).Take(myCount * 2 + 8).ToList(); PortChartData thePortChartData = new PortChartData(); thePortChartData.V_X = BytesSerialize.returnByteLengthRightLeft(bs.Skip(4).Take(4).ToArray()); //竖坐标X thePortChartData.H_Y = (ByteWithString.ByteArrayToInt(bs.Skip(8).Take(myCount * 2).ToArray())); //竖坐标Y theListPortChartData.Add(thePortChartData); } } } } catch (Exception r) { int ss = nowIndex; int dddv = Index; //string ss = ""; } return(theListPortChartData); }
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; }
private string GetConBoxItemToBytes(byte[] bytes) { string CatalogName = string.Empty; byte[] historicalLoadData = new byte[4] { 0x06, 0x68, 0x00, 0x00 }; byte[] LogFile = new byte[4] { 0x07, 0x68, 0x00, 0x00 }; byte[] recordFile = new byte[4] { 0x0a, 0x68, 0x00, 0x00 }; byte[] setAsideFirst = new byte[4] { 0x08, 0x68, 0x00, 0x00 }; byte[] setAsideSecond = new byte[4] { 0x09, 0x68, 0x00, 0x00 }; if (ByteWithString.compareArray(bytes, historicalLoadData)) { CatalogName = "历史负荷数据"; } else if (ByteWithString.compareArray(bytes, LogFile)) { CatalogName = "Log文件"; } else if (ByteWithString.compareArray(bytes, recordFile)) { CatalogName = "录波文件"; } else if (ByteWithString.compareArray(bytes, setAsideFirst)) { CatalogName = "预留1"; } else if (ByteWithString.compareArray(bytes, setAsideSecond)) { CatalogName = "预留2"; } return(CatalogName); }
/// <summary> /// Socket接收 /// </summary> public void ReceiveInfo() { while (true) { try { byte[] result = new byte[1024 * 1024 * 3]; int receiveLength = SOCKET_SEND.Receive(result); if (receiveLength == 0) { stopSocket(); break; } result = result.Skip(0).Take(receiveLength).ToArray(); //string dd = ByteWithString.byteToHexStr(result); //Log.LogWrite("REC:"+dd); //登录标识... if (ByteWithString.byteToHexStrAppend(result, "").Equals("1049FFFF4716".ToLower())) { Thread.Sleep(500); LoginReport theLoginReport = new LoginReport(); theLoginReport.USERNAME = Encoding.ASCII.GetBytes(USER_NAME); theLoginReport.USERNAME_LENGTH = (byte)theLoginReport.USERNAME.Length; theLoginReport.PASSWORD = Encoding.ASCII.GetBytes(PASSWORD); theLoginReport.PASSWORD_LENGTH = (byte)theLoginReport.PASSWORD.Length; theSocketSend(0x01, theLoginReport); } else { //处理报文... reportSel(result); } } catch (Exception msg) { Log.LogWrite(msg); break; } } }
/// <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>()); }
/// <summary> /// 接收 /// </summary> /// <param name="data"></param> /// <returns></returns> public ClientReport clientReportSerialize(byte[] data) { HandelControls theHandelControls = HandelControls.createHandelControls(); ClientReport theClientReport = new ClientReport(); try { theClientReport.HEAD_FIELD = data[0]; theClientReport.REPORT_LENGTH = data.Skip(1).Take(4).ToArray(); byte[] dataLength = data.Skip(1).Take(4).ToArray(); int dataLengthInt = returnByteLengthRight(dataLength); data = data.Skip(0).Take(dataLengthInt).ToArray(); theClientReport.CONTROL_FIELD = data[5]; // theClientReport.REPORT_BODY = data.Skip(6).Take(dataLengthInt-8); theClientReport.END_FIELD = data[data.Length - 1]; data = data.Skip(6).Take(dataLengthInt - 8).ToArray(); int fileCount = 0; //默认文件长度; int nowIndex = 0; //当前位置; int dataCount = 0; TheCatalog theCatalog = new TheCatalog(); //文件目录 CatalogFiles theCatalogFiles = new CatalogFiles(); //文件 TheRemoteDataArray theRemoteDataArray = new TheRemoteDataArray(); //遥信 ResponseValueData theResponseValue = new ResponseValueData(); //设定值 switch (theClientReport.CONTROL_FIELD) { case 0x02: returnLoginInfo theReturnLoginInfo = new returnLoginInfo(); byte[] theByte = data; theReturnLoginInfo.isOk = theByte[0]; theClientReport.REPORT_BODY = theReturnLoginInfo; break; case 0x03: byte[] checkData = data; DeviceData theTreeArrayData = new DeviceData(); theTreeArrayData.theDeviceData = new List <DeviceDataInfo>(); int count = checkData[0]; checkData = checkData.Skip(1).ToArray(); while (count > 0) { DeviceDataInfo theDeviceDataInfo = new DeviceDataInfo(); int ct = checkData.Skip(nowIndex).Take(1).ToArray()[0];//设备名称长度 theDeviceDataInfo.DeviceName = checkData.Skip(nowIndex + 1).Take(ct).ToArray <byte>(); theDeviceDataInfo.DeviceAddress = checkData.Skip(nowIndex + ct + 1).Take(2).ToArray <byte>(); theDeviceDataInfo.DeviceStatue = checkData.Skip(nowIndex + ct + 3).Take(1).ToArray()[0]; theDeviceDataInfo.DeviceLastOnline = checkData.Skip(nowIndex + ct + 4).Take(7).ToArray(); nowIndex += ct + 11; theTreeArrayData.theDeviceData.Add(theDeviceDataInfo); count--; } theClientReport.REPORT_BODY = theTreeArrayData; break; case 0x05: byte[] checkCatalogData = data; theCatalog.DEVICE_ADDRESS = checkCatalogData.Take(2).ToArray <byte>(); //设备地址 theCatalog.FILES_COUNT = checkCatalogData[2]; //文件数量 fileCount = theCatalog.FILES_COUNT; theCatalog.THE_CATALOG_FILES = new List <CatalogFiles>(); byte[] nowCatalogData = checkCatalogData.Skip(3).Take(checkCatalogData.Length - 2).ToArray <byte>(); while (fileCount > 0) { CatalogFiles catalogFiles = new CatalogFiles(); catalogFiles.FILE_LENGTH = nowCatalogData[nowIndex]; catalogFiles.FILE_NAME = nowCatalogData.Skip(nowIndex + 1).Take(catalogFiles.FILE_LENGTH).ToArray <byte>(); theCatalog.THE_CATALOG_FILES.Add(catalogFiles); nowIndex += catalogFiles.FILE_LENGTH + 1; fileCount--; } theClientReport.REPORT_BODY = theCatalog; break; case 0x07: byte[] updateCatalogData = data; theCatalogFiles.DeviceAddress = updateCatalogData.Take(2).ToArray <byte>(); //文件地址 theCatalogFiles.FILE_LENGTH = updateCatalogData[2]; //文件名长度 theCatalogFiles.FILE_NAME = updateCatalogData.Skip(3).Take(theCatalogFiles.FILE_LENGTH).ToArray <byte>(); //文件名 int fileContent = theCatalogFiles.FILE_NAME.Length + 3; theCatalogFiles.FILE_CONTENT = updateCatalogData.Skip(fileContent).ToArray <byte>(); //文件长度 theClientReport.REPORT_BODY = theCatalogFiles; break; case 0x10: //遥信返回(不带时标) byte[] notHaveTimeMark = data; theRemoteDataArray.DEVICE_ADDRESS = notHaveTimeMark.Take(2).ToArray <byte>(); theRemoteDataArray.THE_COUNT = notHaveTimeMark[2]; theRemoteDataArray.THE_TYPE_NAME = "遥信"; fileCount = theRemoteDataArray.THE_COUNT; theRemoteDataArray.THE_REMOTE_DATA = new List <TheRemoteData>(); notHaveTimeMark = notHaveTimeMark.Skip(3).ToArray <byte>(); while (fileCount > 0) { TheRemoteData theRemoteData = new TheRemoteData(); theRemoteData.RemoteAddress = notHaveTimeMark.Skip(nowIndex).Take(2).ToArray <byte>(); theRemoteData.RemoteValue = notHaveTimeMark.Skip(nowIndex + 2).Take(1).ToArray <byte>(); nowIndex = nowIndex + 3; fileCount--; theRemoteDataArray.THE_REMOTE_DATA.Add(theRemoteData); } theClientReport.REPORT_BODY = theRemoteDataArray; theThreadMethod = new Thread(forEachList); theThreadMethod.IsBackground = true; theThreadMethod.Start(theRemoteDataArray); break; case 0x11: //遥信返回(带时标) byte[] haveTimeMark = data; theRemoteDataArray.DEVICE_ADDRESS = haveTimeMark.Take(2).ToArray <byte>(); theRemoteDataArray.THE_COUNT = haveTimeMark[2]; theRemoteDataArray.THE_COUNT = haveTimeMark[2]; theRemoteDataArray.THE_TYPE_NAME = "遥信"; fileCount = theRemoteDataArray.THE_COUNT; theRemoteDataArray.THE_REMOTE_DATA = new List <TheRemoteData>(); haveTimeMark = haveTimeMark.Skip(3).ToArray <byte>(); while (fileCount > 0) { TheRemoteData theRemoteData = new TheRemoteData(); theRemoteData.RemoteAddress = haveTimeMark.Skip(nowIndex).Take(2).ToArray <byte>(); theRemoteData.RemoteValue = haveTimeMark.Skip(nowIndex + 2).Take(1).ToArray <byte>(); theRemoteData.LastestModify = haveTimeMark.Skip(nowIndex + 3).Take(7).ToArray <byte>(); nowIndex = nowIndex + 10; fileCount--; theRemoteDataArray.THE_REMOTE_DATA.Add(theRemoteData); } theClientReport.REPORT_BODY = theRemoteDataArray; theThreadMethod = new Thread(forEachList); theThreadMethod.IsBackground = true; theThreadMethod.Start(theRemoteDataArray); break; case 0x12: //遥测 byte[] telemeteringTimeMark = data; theRemoteDataArray.DEVICE_ADDRESS = telemeteringTimeMark.Take(2).ToArray <byte>(); theRemoteDataArray.THE_COUNT = telemeteringTimeMark[2]; theRemoteDataArray.THE_TYPE_NAME = "遥测"; fileCount = theRemoteDataArray.THE_COUNT; theRemoteDataArray.THE_REMOTE_DATA = new List <TheRemoteData>(); telemeteringTimeMark = telemeteringTimeMark.Skip(3).ToArray <byte>(); while (fileCount > 0) { TheRemoteData theRemoteData = new TheRemoteData(); theRemoteData.LastestModify = new byte[] { 0x00 }; theRemoteData.RemoteAddress = telemeteringTimeMark.Skip(nowIndex).Take(2).ToArray <byte>(); theRemoteData.RemoteValue = telemeteringTimeMark.Skip(nowIndex + 2).Take(2).ToArray <byte>(); theRemoteData.quility = telemeteringTimeMark.Skip(nowIndex + 4).Take(1).ToArray <byte>()[0]; nowIndex = nowIndex + 5; fileCount--; theRemoteDataArray.THE_REMOTE_DATA.Add(theRemoteData); } theClientReport.REPORT_BODY = theRemoteDataArray; theThreadMethod = new Thread(forEachList); theThreadMethod.IsBackground = true; theThreadMethod.Start(theRemoteDataArray); break; case 0x14: byte[] responseValueTimeMark = data; theResponseValue.DEVICE_ADDRESS = responseValueTimeMark.Take(2).ToArray <byte>(); theResponseValue.VALUE_TYPE = responseValueTimeMark[2]; theResponseValue.VALUE_COUNT = responseValueTimeMark[3]; fileCount = theResponseValue.VALUE_COUNT; theResponseValue.theResponseValueArray = new List <ResponseValue>(); responseValueTimeMark = responseValueTimeMark.Skip(4).ToArray <byte>(); while (fileCount > 0) { ResponseValue rsponseValue = new ResponseValue(); rsponseValue.VALUE_ADDRESS = responseValueTimeMark.Skip(nowIndex).Take(2).ToArray <byte>(); int length = responseValueTimeMark.Skip(nowIndex + 2).Take(1).ToArray <byte>()[0]; rsponseValue.VALUE = responseValueTimeMark.Skip(nowIndex + 3).Take(length).ToArray <byte>(); nowIndex = nowIndex + 3 + length; theResponseValue.theResponseValueArray.Add(rsponseValue); fileCount--; } theClientReport.REPORT_BODY = theResponseValue; break; case 0x0a: byte[] contentText = data; ReportContentText theReportContent = new ReportContentText(); theReportContent.ReportType = contentText[0]; theReportContent.ReportDateTime = contentText.Skip(1).Take(7).ToArray <byte>(); theReportContent.ReportContent = contentText.Skip(8).ToArray <byte>(); theClientReport.REPORT_BODY = theReportContent; break; case 0x21: byte[] writeBytes = data; WriteFile theWriteFile = new WriteFile(); theWriteFile.DEVICE_ADDRESS = writeBytes.Take(2).ToArray(); theWriteFile.FILE_LENGTH = writeBytes.Skip(2).Take(1).ToArray()[0]; theWriteFile.FILE_NAME = writeBytes.Skip(3).Take(theWriteFile.FILE_LENGTH).ToArray(); theWriteFile.FILE_COUNT = writeBytes.Skip(3 + theWriteFile.FILE_LENGTH).ToArray(); break; case 0x23: //接收变电站 List <ConvertingStation> theConvertingStationArray = new List <ConvertingStation>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { ConvertingStation theConvertingStation = new ConvertingStation(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theConvertingStation.stationName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); nowIndex += convertingNameLength; int remarksLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theConvertingStation.stationRemarks = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(remarksLength).ToArray(), "utf-8"); nowIndex += remarksLength; theConvertingStation.stationID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theConvertingStationArray.Add(theConvertingStation); } theClientReport.REPORT_BODY = theConvertingStationArray; break; case 0x24: //接收母线 List <Generatrix> theGeneratrixArray = new List <Generatrix>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { Generatrix theGeneratrix = new Generatrix(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theGeneratrix.GeneratrixName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); nowIndex += convertingNameLength; int remarksLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theGeneratrix.GeneratrixNumber = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(remarksLength).ToArray(), "utf-8"); nowIndex += remarksLength; theGeneratrix.GeneratrixID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int convertingLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theGeneratrix.GeneratrixToName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingLength).ToArray(), "utf-8"); nowIndex += convertingLength; theGeneratrix.GeneratrixToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theGeneratrixArray.Add(theGeneratrix); } theClientReport.REPORT_BODY = theGeneratrixArray; break; case 0x25: //接收线路 List <Circuit> theCircuitArray = new List <Circuit>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { Circuit theCircuit = new Circuit(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theCircuit.CircuitName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); nowIndex += convertingNameLength; int remarksLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theCircuit.CircuitNumber = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(remarksLength).ToArray(), "utf-8"); nowIndex += remarksLength; theCircuit.CircuitID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int convertingLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theCircuit.CircuitToName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingLength).ToArray(), "utf-8"); nowIndex += convertingLength; theCircuit.CircuitToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theCircuitArray.Add(theCircuit); } theClientReport.REPORT_BODY = theCircuitArray; break; case 0x26: //接收检测点 List <Detection> theDetectionArray = new List <Detection>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { Detection theDetection = new Detection(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DetectionName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); nowIndex += convertingNameLength; int theNumber = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DetectionNumber = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(theNumber).ToArray(), "utf-8"); nowIndex += theNumber; theDetection.DetectionID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int detectionToSecondName = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DetectionToSecondName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(detectionToSecondName).ToArray(), "utf-8"); nowIndex += detectionToSecondName; theDetection.DetectionToSecondID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; theDetection.RemoteA = ByteWithString.byteToHexStr(data.Skip(nowIndex).Take(2).ToArray()); nowIndex += 2; theDetection.RemoteB = ByteWithString.byteToHexStr(data.Skip(nowIndex).Take(2).ToArray()); nowIndex += 2; theDetection.RemoteC = ByteWithString.byteToHexStr(data.Skip(nowIndex).Take(2).ToArray()); nowIndex += 2; int circuitLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DetectionToName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(circuitLength).ToArray(), "utf-8"); nowIndex += circuitLength; theDetection.DetectionToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theDetectionArray.Add(theDetection); } theClientReport.REPORT_BODY = theDetectionArray; break; case 0x33: List <DeviceDataSetting> theDeviceDataArray = new List <DeviceDataSetting>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { DeviceDataSetting theDetection = new DeviceDataSetting(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DeviceDataName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); //ok nowIndex += convertingNameLength; theDetection.DeviceDataID = ByteWithString.byteToHexStr(data.Skip(nowIndex).Take(2).ToArray()).ToString(); nowIndex += 2; theDetection.LastDateTime = ByteWithString.ConvertCP56TIME2aToDateTime(data.Skip(nowIndex).Take(7).ToArray()).ToString("yyyy-MM-dd HH:mm:ss"); nowIndex += 7; int ALength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.TheRemoteA = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(ALength).ToArray(), "utf-8"); nowIndex += ALength; theDetection.RemoteAToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int BLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.TheRemoteB = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(BLength).ToArray(), "utf-8"); nowIndex += BLength; theDetection.RemoteBToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int CLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.TheRemoteC = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(CLength).ToArray(), "utf-8"); nowIndex += CLength; theDetection.RemoteCToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; theDetection.DeviceDataToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theDeviceDataArray.Add(theDetection); } theClientReport.REPORT_BODY = theDeviceDataArray; break; case 0x35: List <int> valueBuilder = new List <int>(); valueBuilder.Add(returnByteLengthRight(data.Skip(0).Take(4).ToArray())); valueBuilder.Add(returnByteLengthRight(data.Skip(4).Take(4).ToArray())); valueBuilder.Add(returnByteLengthRight(data.Skip(8).Take(4).ToArray())); theClientReport.REPORT_BODY = valueBuilder; break; case 0x38: Hitch theHitch = new Hitch(); theHitch.COUNT = dataCount = returnByteLengthRight(data.Take(4).ToArray()); theHitch.NOW_ID = new List <int>(); data = data.Skip(4).ToArray(); while (dataCount > 0) { theHitch.NOW_ID.Add(returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray())); nowIndex += 4; dataCount--; } theClientReport.REPORT_BODY = theHitch; break; default: break; } theClientReport.VALIDATE_FIELD = data.Skip(data.Length - 2).Take(1).ToArray()[0]; theClientReport.END_FIELD = 0x16; } catch (Exception msg) { Log.LogWrite(msg); } return(theClientReport); }
/// <summary> /// 获得图表所需的数据 /// </summary> /// <param name="pullPathFile">文件路径</param> /// <returns></returns> public WaveData ChartShow(string pullPathFile) { HandleWaveData theHandleWaveData = new HandleWaveData(); return(theHandleWaveData.hexadecimalFileSerialize(theHandleWaveData.binaryFileSerialize(ByteWithString.FileStreamTobyteArray(pullPathFile)))); }
/// <summary> /// 设置表格属性 /// </summary> /// <param name="theCatalog"></param> /// <param name="dt"></param> public void GetDataGridViewInfo(TheCatalog theCatalog, DataGridView dt) { try { string deviceAdddress = ByteWithString.byteToHexStrAppend(theCatalog.DEVICE_ADDRESS, ""); //地址 string catalogName = GetConBoxItemToBytes(theCatalog.CATALOG_NAME); //选择的文件目录 string deviceCatalog = filePath + "/" + deviceAdddress + "/" + catalogName; if (!Directory.Exists(deviceCatalog)) { DirectoryInfo theDirectory = Directory.CreateDirectory(deviceCatalog); } if (theCatalog != null && theCatalog.THE_CATALOG_FILES != null && theCatalog.THE_CATALOG_FILES.Count > 0) { for (int i = 0; i < theCatalog.THE_CATALOG_FILES.Count; i++) { dt.Rows.Add(); //当前文件名 string fileName = Encoding.ASCII.GetString(theCatalog.THE_CATALOG_FILES[i].FILE_NAME); if (fileName.Contains(".Hex") || fileName.Contains(".Binary")) { continue; } //文件的绝对路径 string filePathName = deviceCatalog + "/" + fileName; //当前目录 DirectoryInfo directoryInfo = new DirectoryInfo(deviceCatalog); //当前目录下的所有文件 FileInfo[] fileInfo = directoryInfo.GetFiles();//获得所有文件 //当前目录下是否存在此文件 FileInfo isHaveFile = (from a in fileInfo where a.Name == fileName select a).FirstOrDefault <FileInfo>(); if (isHaveFile == null)//不存在 { dt.Rows[i].Cells["filestate"].Value = "未下载"; dt.Rows[i].Cells["updateFileData"].Value = "------"; } else { dt.Rows[i].Cells["filestate"].Value = "已下载"; string dataFormat = "yyyy-MM-dd HH:mm:ss"; dt.Rows[i].Cells["updateFileData"].Value = File.GetLastWriteTime(filePathName).ToString(dataFormat); } dt.Rows[i].Cells["fileName"].Value = fileName; dt.Rows[i].Cells["filestate"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; if (dt.Rows[i].Cells["filestate"].Value.ToString() == "读取中") { dt.Rows[i].Cells["filestate"].Style.ForeColor = Color.Gray; } DataGridViewLinkCell soureFileDown = new DataGridViewLinkCell(); SetCellLinkColor(soureFileDown); soureFileDown.Value = "源文件下载"; DataGridViewLinkCell towFileBtn = new DataGridViewLinkCell(); SetCellLinkColor(towFileBtn); DataGridViewLinkCell sixFileBtn = new DataGridViewLinkCell(); SetCellLinkColor(sixFileBtn); DataGridViewLinkCell ImgBtn = new DataGridViewLinkCell(); SetCellLinkColor(ImgBtn); DataGridViewButtonCell updateFile = new DataGridViewButtonCell(); updateFile.Style.ForeColor = Color.White; updateFile.Style.BackColor = Color.Black; updateFile.Value = "更新文件"; updateFile.FlatStyle = FlatStyle.Popup; if (!fileName.Contains(".dat")) { ImgBtn.Value = "---"; sixFileBtn.Value = "---"; if (catalogName.Equals("历史负荷数据")) { towFileBtn.Value = "二进制文件下载"; } else { towFileBtn.Value = "---"; } } else { ImgBtn.Value = "波形图"; sixFileBtn.Value = "十六进制文件下载"; towFileBtn.Value = "二进制文件下载"; } dt.Rows[i].Cells["soureFileDown"] = soureFileDown; dt.Rows[i].Cells["soureFileDown"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dt.Rows[i].Cells["towFileBtn"] = towFileBtn; dt.Rows[i].Cells["towFileBtn"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dt.Rows[i].Cells["sixFileBtn"] = sixFileBtn; dt.Rows[i].Cells["sixFileBtn"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dt.Rows[i].Cells["ImgBtn"] = ImgBtn; dt.Rows[i].Cells["ImgBtn"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dt.Rows[i].Cells["updateFile"] = updateFile; dt.Rows[i].Cells["updateFile"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; HideGridViewColumn(catalogName, dt);//要隐藏的列明 } } } catch (Exception msg) { Log.LogWrite(msg); } }
public static byte[] returnByteLength(string str, int count) { str = str.PadLeft(count, '0'); return(ByteWithString.strToToHexByte(str)); }