fix
This commit is contained in:
@@ -53,8 +53,8 @@ namespace arDev
|
||||
else sb.Append("0S");
|
||||
sb.Append("00");
|
||||
sb.Append("0000"); //재기동시간
|
||||
if (opt == eStopOpt.MarkStop)
|
||||
VAR.BOOL[eVarBool.NEXTSTOP_MARK] = true;
|
||||
//if (opt == eStopOpt.MarkStop)
|
||||
// VAR.BOOL[eVarBool.NEXTSTOP_MARK] = true;
|
||||
|
||||
//동작중이면 이 멈춤 명령을 기록으로 남긴다 230116
|
||||
if (this.system1.agv_run)
|
||||
|
||||
22
Cs_HMI/SubProject/BMS/.gitignore
vendored
22
Cs_HMI/SubProject/BMS/.gitignore
vendored
@@ -1,12 +1,12 @@
|
||||
*.suo
|
||||
*.user
|
||||
*.pdb
|
||||
bin
|
||||
obj
|
||||
desktop.ini
|
||||
.vs
|
||||
.git
|
||||
packages
|
||||
*.patch
|
||||
/Project/SourceSetup.exe
|
||||
*.suo
|
||||
*.user
|
||||
*.pdb
|
||||
bin
|
||||
obj
|
||||
desktop.ini
|
||||
.vs
|
||||
.git
|
||||
packages
|
||||
*.patch
|
||||
/Project/SourceSetup.exe
|
||||
*.zip
|
||||
|
||||
@@ -11,15 +11,9 @@ namespace arDev
|
||||
{
|
||||
public class BMS : arRS232
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 데이터조회간격(초)
|
||||
/// </summary>
|
||||
public float ScanInterval { get; set; }
|
||||
|
||||
public BMS()
|
||||
{
|
||||
ScanInterval = 1000;
|
||||
|
||||
MinRecvLength = 34;
|
||||
}
|
||||
|
||||
@@ -29,7 +23,6 @@ namespace arDev
|
||||
public event EventHandler<BMSInformationEventArgs> BMSDataReceive;
|
||||
public event EventHandler<BMSCelvoltageEventArgs> BMSCellDataReceive;
|
||||
|
||||
|
||||
protected override bool CustomParser(byte[] buf, out byte[] remainBuffer)
|
||||
{
|
||||
List<byte> remain = new List<byte>();
|
||||
@@ -91,10 +84,7 @@ namespace arDev
|
||||
}
|
||||
|
||||
bool Recv0 = false;
|
||||
int Recv0Cnt = 0;
|
||||
bool Recv1 = false;
|
||||
int Recv1Cnt = 0;
|
||||
|
||||
public event EventHandler<ChargetDetectArgs> ChargeDetect;
|
||||
public override bool ProcessRecvData(byte[] data)
|
||||
{
|
||||
@@ -112,29 +102,19 @@ namespace arDev
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (VerifyChecksum(data) == false)
|
||||
{
|
||||
RaiseMessage(MessageType.Error, "Checksum error");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (data[1] == 0x03)
|
||||
if (QueryIndex == 0)
|
||||
{
|
||||
return ParseBMSInfo();
|
||||
}
|
||||
else if (data[1] == 0x04)
|
||||
else
|
||||
{
|
||||
return ParseBMSCellVoltage();
|
||||
}
|
||||
else return false;
|
||||
|
||||
|
||||
}
|
||||
bool ParseBMSCellVoltage()
|
||||
{
|
||||
if (UseCmdLogging == true)
|
||||
RaiseMessage(MessageType.Recv, ByteListToHexString(LastReceiveBuffer.ToList()));
|
||||
//var i = 0;
|
||||
var BatteryCell_Checksum = 0xffff;// - (LastReceiveBuffer[i + 3] + LastReceiveBuffer[i + 4] + LastReceiveBuffer[i + 5] + LastReceiveBuffer[i + 6] + LastReceiveBuffer[i + 7] + LastReceiveBuffer[i + 8] + LastReceiveBuffer[i + 9] + LastReceiveBuffer[i + 10] + LastReceiveBuffer[i + 11] + LastReceiveBuffer[i + 12] + LastReceiveBuffer[i + 13] + LastReceiveBuffer[i + 14] + LastReceiveBuffer[i + 15] + LastReceiveBuffer[i + 16] + LastReceiveBuffer[i + 17] + LastReceiveBuffer[i + 18] + LastReceiveBuffer[i + 19])) + 1;
|
||||
for (int i = 3; i < 20; i++)
|
||||
@@ -170,6 +150,7 @@ namespace arDev
|
||||
try
|
||||
{
|
||||
BMSCellDataReceive?.Invoke(this, new BMSCelvoltageEventArgs(v1, v2, v3, v4, v5, v6, v7, v8));
|
||||
Current_CellTime = DateTime.Now;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -182,62 +163,8 @@ namespace arDev
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static bool VerifyChecksum(byte[] dataBytes)
|
||||
{
|
||||
// 길이 바이트 (byte[3])
|
||||
byte length = dataBytes[3];
|
||||
|
||||
if (dataBytes[1] == 0x03)
|
||||
{
|
||||
|
||||
// 데이터 바이트 (byte[4] ~ byte[30])
|
||||
byte[] data = dataBytes.Skip(4).Take(27).ToArray();
|
||||
|
||||
// 길이와 데이터의 합을 계산
|
||||
ushort sum = (ushort)(length + data.Sum(b => b));
|
||||
|
||||
// 반전시키고 높은 위치부터 낮은 위치로 더한 후 1을 더함
|
||||
ushort checksum = (ushort)((~sum + 1) & 0xFFFF);
|
||||
|
||||
// 받은 체크섬 (byte[31] ~ byte[32])
|
||||
ushort receivedChecksum = (ushort)((dataBytes[31] << 8) | dataBytes[32]);
|
||||
|
||||
//252 1: 64514
|
||||
// 계산된 체크섬과 받은 체크섬을 비교
|
||||
return checksum == receivedChecksum;
|
||||
|
||||
}
|
||||
else if (dataBytes[1] == 0x04)
|
||||
{
|
||||
// 데이터 바이트 (byte[4] ~ byte[30])
|
||||
byte[] data = dataBytes.Skip(4).Take(16).ToArray();
|
||||
|
||||
// 길이와 데이터의 합을 계산
|
||||
ushort sum = (ushort)(length + data.Sum(b => b));
|
||||
|
||||
// 반전시키고 높은 위치부터 낮은 위치로 더한 후 1을 더함
|
||||
ushort checksum = (ushort)((~sum + 1) & 0xFFFF);
|
||||
|
||||
// 받은 체크섬 (byte[31] ~ byte[32])
|
||||
ushort receivedChecksum = (ushort)((dataBytes[20] << 8) | dataBytes[21]);
|
||||
|
||||
//252 1: 64514
|
||||
// 계산된 체크섬과 받은 체크섬을 비교
|
||||
return checksum == receivedChecksum;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ParseBMSInfo()
|
||||
{
|
||||
if(UseCmdLogging == true)
|
||||
RaiseMessage(MessageType.Recv, ByteListToHexString(LastReceiveBuffer.ToList()));
|
||||
|
||||
//전압확인
|
||||
UInt16 batH = (UInt16)LastReceiveBuffer[4];
|
||||
UInt16 batL = (UInt16)LastReceiveBuffer[5];
|
||||
@@ -265,7 +192,6 @@ namespace arDev
|
||||
float levraw = (float)(Current_Amp / (Current_MaxAmp * 1.0));
|
||||
Current_Level = (float)(levraw * 100.0);// (float)(map(remain, 0, total, 0, 100));
|
||||
Current_LevelA = LastReceiveBuffer[23]; //<- 23번자료는 byte이므로 소수점이잇는 데이터로 직접 계산한다
|
||||
Current_DataTime = DateTime.Now;
|
||||
|
||||
|
||||
//250620 jwlee 추가
|
||||
@@ -282,6 +208,7 @@ namespace arDev
|
||||
try
|
||||
{
|
||||
BMSDataReceive?.Invoke(this, new BMSInformationEventArgs(Current_Volt, Current_Amp, Current_MaxAmp, Current_Level, Changed));
|
||||
Current_DataTime = DateTime.Now;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -424,13 +351,10 @@ namespace arDev
|
||||
public int Current_MaxAmp { get; set; }
|
||||
|
||||
public DateTime Current_DataTime = DateTime.Parse("1982-11-23");
|
||||
public DateTime Current_CellTime = DateTime.Parse("1982-11-23");
|
||||
|
||||
public int QueryIndex { get; set; } = 0;
|
||||
|
||||
public int CMDOutCnt { get; set; } = 3;
|
||||
|
||||
public bool UseCmdLogging { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 상태읽기와 전압읽기명령을 반복합니다
|
||||
/// </summary>
|
||||
@@ -447,19 +371,7 @@ namespace arDev
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Recv0Cnt > CMDOutCnt)
|
||||
{
|
||||
Recv0Cnt = 0;
|
||||
RaiseMessage(MessageType.Error, "0 명령 Count Out");
|
||||
QueryIndex = 1;
|
||||
Recv1 = false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SendQuery_ReadStatue();
|
||||
}
|
||||
|
||||
return SendQuery_ReadStatue();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -472,25 +384,13 @@ namespace arDev
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Recv1Cnt > CMDOutCnt)
|
||||
{
|
||||
Recv1Cnt = 0;
|
||||
RaiseMessage(MessageType.Error, "1 명령 Count Out");
|
||||
QueryIndex = 0;
|
||||
Recv0 = false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SendQuery_ReadCellvoltage();
|
||||
}
|
||||
return SendQuery_ReadCellvoltage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean SendQuery_ReadStatue()
|
||||
{
|
||||
Recv0Cnt++;
|
||||
Recv0 = false;
|
||||
var cmd = new List<byte>();
|
||||
cmd.Add(0xDD);
|
||||
@@ -501,16 +401,12 @@ namespace arDev
|
||||
cmd.Add(0xFD);
|
||||
cmd.Add(0x77);
|
||||
cmd.Add(0x0D);
|
||||
if (UseCmdLogging == true)
|
||||
RaiseMessage(MessageType.Normal, ByteListToHexString(cmd));
|
||||
|
||||
return WriteData(cmd.ToArray());
|
||||
}
|
||||
|
||||
|
||||
public Boolean SendQuery_ReadCellvoltage()
|
||||
{
|
||||
Recv1Cnt++;
|
||||
Recv1 = false;
|
||||
var cmd = new List<byte>();
|
||||
cmd.Add(0xDD);
|
||||
@@ -521,21 +417,8 @@ namespace arDev
|
||||
cmd.Add(0xFC);
|
||||
cmd.Add(0x77);
|
||||
cmd.Add(0x0D);
|
||||
if (UseCmdLogging == true)
|
||||
RaiseMessage(MessageType.Normal, ByteListToHexString(cmd));
|
||||
return WriteData(cmd.ToArray());
|
||||
}
|
||||
|
||||
|
||||
public string ByteListToHexString(List<byte> byteList)
|
||||
{
|
||||
StringBuilder hex = new StringBuilder(byteList.Count * 2);
|
||||
foreach (byte b in byteList)
|
||||
{
|
||||
hex.AppendFormat("{0:X2} ", b);
|
||||
}
|
||||
return hex.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>arDevice</RootNamespace>
|
||||
<AssemblyName>BMS</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
@@ -46,7 +46,12 @@
|
||||
<Compile Include="BMSInformationEventArgs.cs" />
|
||||
<Compile Include="BMS.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RS232.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CommData\CommData.csproj">
|
||||
<Project>{14e8c9a5-013e-49ba-b435-efefc77dd623}</Project>
|
||||
<Name>CommData</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
public abstract partial class arRS232 : IDisposable
|
||||
{
|
||||
@@ -15,7 +15,7 @@ public abstract partial class arRS232 : IDisposable
|
||||
/// 최종 전송 메세지
|
||||
/// </summary>
|
||||
public byte[] lastSendBuffer = new byte[] { };
|
||||
|
||||
//public int ValidCheckTimeMSec { get; set; } = 5000;
|
||||
protected List<byte> tempBuffer = new List<byte>();
|
||||
protected Boolean findSTX = false;
|
||||
public string errorMessage { get; set; }
|
||||
@@ -26,7 +26,10 @@ public abstract partial class arRS232 : IDisposable
|
||||
/// 메세지 수신시 사용하는 내부버퍼
|
||||
/// </summary>
|
||||
protected List<byte> _buffer = new List<byte>();
|
||||
|
||||
/// <summary>
|
||||
/// 데이터조회간격(초)
|
||||
/// </summary>
|
||||
public float ScanInterval { get; set; }
|
||||
|
||||
// public byte[] LastRecvData;
|
||||
public string LastRecvString
|
||||
@@ -98,7 +101,7 @@ public abstract partial class arRS232 : IDisposable
|
||||
{
|
||||
_device = new System.IO.Ports.SerialPort();
|
||||
this.BaudRate = 9600;
|
||||
|
||||
ScanInterval = 10;
|
||||
_device.DataReceived += barcode_DataReceived;
|
||||
_device.ErrorReceived += this.barcode_ErrorReceived;
|
||||
_device.WriteTimeout = 5000;
|
||||
@@ -292,11 +295,11 @@ public abstract partial class arRS232 : IDisposable
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (IsOpen)
|
||||
{
|
||||
//_device.DiscardInBuffer();
|
||||
//_device.DiscardOutBuffer();
|
||||
}
|
||||
//if (IsOpen)
|
||||
//{
|
||||
// //_device.DiscardInBuffer();
|
||||
// //_device.DiscardOutBuffer();
|
||||
//}
|
||||
errorMessage = ex.Message;
|
||||
this.Message?.Invoke(this, new MessageEventArgs(ex.Message, true));
|
||||
}
|
||||
@@ -413,7 +416,7 @@ public abstract partial class arRS232 : IDisposable
|
||||
protected abstract bool CustomParser(byte[] buf, out byte[] remainBuffer);
|
||||
|
||||
/// <summary>
|
||||
/// 데이터수신시간이 설정값보다 x 2.5를 초과하면 false 가 반환됨
|
||||
/// 포트가 열려있거나 데이터 수신시간이 없는경우 false를 반환합니다
|
||||
/// </summary>
|
||||
public Boolean IsValid
|
||||
{
|
||||
@@ -422,10 +425,16 @@ public abstract partial class arRS232 : IDisposable
|
||||
if (IsOpen == false) return false;
|
||||
if (lastRecvTime.Year == 1982) return false;
|
||||
var ts = DateTime.Now - lastRecvTime;
|
||||
if (ts.TotalSeconds > 5) return false;
|
||||
if (ts.TotalSeconds > (this.ScanInterval * 2.5)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected string ByteListToHexString(List<byte> src)
|
||||
{
|
||||
return string.Join(" ", src.Select(t => t.ToString("X2")));
|
||||
}
|
||||
|
||||
protected bool WriteData(string cmd)
|
||||
{
|
||||
return WriteData(System.Text.Encoding.Default.GetBytes(cmd));
|
||||
@@ -482,4 +491,5 @@ public abstract partial class arRS232 : IDisposable
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace arDev
|
||||
/// 최종 전송 메세지
|
||||
/// </summary>
|
||||
public byte[] lastSendBuffer = new byte[] { };
|
||||
|
||||
//public int ValidCheckTimeMSec { get; set; } = 5000;
|
||||
protected List<byte> tempBuffer = new List<byte>();
|
||||
protected Boolean findSTX = false;
|
||||
public string errorMessage { get; set; }
|
||||
@@ -27,7 +27,10 @@ namespace arDev
|
||||
/// 메세지 수신시 사용하는 내부버퍼
|
||||
/// </summary>
|
||||
protected List<byte> _buffer = new List<byte>();
|
||||
|
||||
/// <summary>
|
||||
/// 데이터조회간격(초)
|
||||
/// </summary>
|
||||
public float ScanInterval { get; set; }
|
||||
|
||||
// public byte[] LastRecvData;
|
||||
public string LastRecvString
|
||||
@@ -99,7 +102,7 @@ namespace arDev
|
||||
{
|
||||
_device = new System.IO.Ports.SerialPort();
|
||||
this.BaudRate = 9600;
|
||||
|
||||
ScanInterval = 10;
|
||||
_device.DataReceived += barcode_DataReceived;
|
||||
_device.ErrorReceived += this.barcode_ErrorReceived;
|
||||
_device.WriteTimeout = 5000;
|
||||
@@ -293,11 +296,11 @@ namespace arDev
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (IsOpen)
|
||||
{
|
||||
//_device.DiscardInBuffer();
|
||||
//_device.DiscardOutBuffer();
|
||||
}
|
||||
//if (IsOpen)
|
||||
//{
|
||||
// //_device.DiscardInBuffer();
|
||||
// //_device.DiscardOutBuffer();
|
||||
//}
|
||||
errorMessage = ex.Message;
|
||||
this.Message?.Invoke(this, new MessageEventArgs(ex.Message, true));
|
||||
}
|
||||
@@ -414,16 +417,16 @@ namespace arDev
|
||||
protected abstract bool CustomParser(byte[] buf, out byte[] remainBuffer);
|
||||
|
||||
/// <summary>
|
||||
/// 데이터수신시간이 설정값보다 x 2.5를 초과하면 false 가 반환됨
|
||||
/// 포트가 열려있거나 데이터 수신시간이 없는경우 false를 반환합니다
|
||||
/// </summary>
|
||||
public Boolean IsValid
|
||||
public Boolean IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsOpen == false) return false;
|
||||
if (lastRecvTime.Year == 1982) return false;
|
||||
var ts = DateTime.Now - lastRecvTime;
|
||||
if (ts.TotalSeconds > 5) return false;
|
||||
if (ts.TotalSeconds > (this.ScanInterval * 2.5)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Submodule Cs_HMI/SubProject/EnigProtocol updated: 77a9d40662...070aa848c9
Reference in New Issue
Block a user