public void ReadAddressCsv() { try { if (string.IsNullOrWhiteSpace(AddressPath)) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID" , $"IsAddressPathNull={string.IsNullOrWhiteSpace(AddressPath)}")); return; } Vehicle.MapInfo.addressMap.Clear(); Vehicle.MapInfo.chargerAddressMap.Clear(); string[] allRows = File.ReadAllLines(AddressPath); if (allRows == null || allRows.Length < 2) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID" , $"There are no address in file")); return; } string[] titleRow = allRows[0].Split(','); allRows = allRows.Skip(1).ToArray(); int nRows = allRows.Length; int nColumns = titleRow.Length; Dictionary <string, int> dicHeaderIndexes = new Dictionary <string, int>(); for (int i = 0; i < nColumns; i++) { var keyword = titleRow[i].Trim(); if (!string.IsNullOrWhiteSpace(keyword)) { dicHeaderIndexes.Add(keyword, i); } } for (int i = 0; i < nRows; i++) { string[] getThisRow = allRows[i].Split(','); MapAddress oneRow = new MapAddress(); MapAddressOffset offset = new MapAddressOffset(); try { oneRow.Id = getThisRow[dicHeaderIndexes["Id"]]; oneRow.Position.X = double.Parse(getThisRow[dicHeaderIndexes["PositionX"]]); oneRow.Position.Y = double.Parse(getThisRow[dicHeaderIndexes["PositionY"]]); if (dicHeaderIndexes.ContainsKey("TransferPortDirection")) { oneRow.TransferPortDirection = oneRow.AddressDirectionParse(getThisRow[dicHeaderIndexes["TransferPortDirection"]]); } if (dicHeaderIndexes.ContainsKey("GateType")) { oneRow.GateType = getThisRow[dicHeaderIndexes["GateType"]]; } if (dicHeaderIndexes.ContainsKey("ChargeDirection")) { oneRow.ChargeDirection = oneRow.AddressDirectionParse(getThisRow[dicHeaderIndexes["ChargeDirection"]]); } if (dicHeaderIndexes.ContainsKey("PioDirection")) { oneRow.PioDirection = oneRow.AddressDirectionParse(getThisRow[dicHeaderIndexes["PioDirection"]]); } //oneRow.CanSpin = bool.Parse(getThisRow[dicHeaderIndexes["CanSpin"]]); //oneRow.IsTR50 = bool.Parse(getThisRow[dicHeaderIndexes["IsTR50"]]); if (dicHeaderIndexes.ContainsKey("InsideSectionId")) { oneRow.InsideSectionId = FitZero(getThisRow[dicHeaderIndexes["InsideSectionId"]]); } if (dicHeaderIndexes.ContainsKey("OffsetX")) { offset.OffsetX = double.Parse(getThisRow[dicHeaderIndexes["OffsetX"]]); offset.OffsetY = double.Parse(getThisRow[dicHeaderIndexes["OffsetY"]]); offset.OffsetTheta = double.Parse(getThisRow[dicHeaderIndexes["OffsetTheta"]]); } oneRow.AddressOffset = offset; if (dicHeaderIndexes.ContainsKey("VehicleHeadAngle")) { oneRow.VehicleHeadAngle = double.Parse(getThisRow[dicHeaderIndexes["VehicleHeadAngle"]]); } } catch (Exception ex) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID", $"LoadAddressCsv read oneRow : [lastReadAdrId={lastReadAdrId}]")); LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, ex.Message); } lastReadAdrId = oneRow.Id; Vehicle.MapInfo.addressMap.TryAdd(oneRow.Id, oneRow); if (oneRow.IsCharger()) { Vehicle.MapInfo.chargerAddressMap.Add(oneRow); } Vehicle.MapInfo.gateTypeMap.Add(oneRow.Id, oneRow.GateType); } LogDebug(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"Load Address File Ok. [lastReadAdrId={lastReadAdrId}]"); } catch (Exception ex) { LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, $"LoadAddressCsv : [lastReadAdrId={lastReadAdrId}]"); LogException(GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, ex.Message); } }
private void LogException(string classMethodName, string exMsg) { mirleLogger.Log(new LogFormat("Error", "5", classMethodName, "Device", "CarrierID", exMsg)); }
private void LogException(string classMethodName, string exMsg) { mirleLogger.Log(new LogFormat("Error", "5", classMethodName, Vehicle.AgvcConnectorConfig.ClientName, "CarrierID", exMsg)); }
private void LoadAlarmFile() { try { if (string.IsNullOrEmpty(Vehicle.AlarmConfig.AlarmFileName)) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID" , $"string.IsNullOrEmpty(alarmConfig.AlarmFileName)={string.IsNullOrEmpty(Vehicle.AlarmConfig.AlarmFileName)}")); return; } string alarmFullPath = Path.Combine(Environment.CurrentDirectory, Vehicle.AlarmConfig.AlarmFileName); Dictionary <string, int> dicAlarmIndexes = new Dictionary <string, int>(); allAlarms.Clear(); string[] allRows = File.ReadAllLines(alarmFullPath); if (allRows == null || allRows.Length < 2) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID" , "There are no alarms in file")); return; } string[] titleRow = allRows[0].Split(','); allRows = allRows.Skip(1).ToArray(); int nRows = allRows.Length; int nColumns = titleRow.Length; //Id, AlarmText, PlcAddress, PlcBitNumber, Level, Description for (int i = 0; i < nColumns; i++) { var keyword = titleRow[i].Trim(); if (!string.IsNullOrWhiteSpace(keyword)) { dicAlarmIndexes.Add(keyword, i); } } for (int i = 0; i < nRows; i++) { string[] getThisRow = allRows[i].Split(','); Alarm oneRow = new Alarm(); oneRow.Id = int.Parse(getThisRow[dicAlarmIndexes["Id"]]); oneRow.AlarmText = getThisRow[dicAlarmIndexes["AlarmText"]]; if (Enum.TryParse(getThisRow[dicAlarmIndexes["Level"]], out EnumAlarmLevel level)) { oneRow.Level = level; } oneRow.Description = getThisRow[dicAlarmIndexes["Description"]]; allAlarms.Add(oneRow.Id, oneRow); } mirleLogger.Log(new LogFormat("Debug", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID" , "Load Alarm File Ok")); } catch (Exception ex) { mirleLogger.Log(new LogFormat("Error", "5", GetType().Name + ":" + MethodBase.GetCurrentMethod().Name, "Device", "CarrierID", ex.Message)); } }