Merge pull request 'fix: 무게 수신 버퍼 및 안정성 임계값 기준 재측정 로직으로 수정' (#10) from fix/weight-timing-control into master
Reviewed-on: #10
This commit is contained in:
commit
a7379e7ebf
@ -61,6 +61,11 @@
|
||||
<HintPath>..\..\..\..\..\..\..\..\Program Files\Brother bPAC3 SDK\Samples\VBNET\Badge\bin\Release\Interop.bpac.DLL</HintPath>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="Ivi.Visa.Interop, Version=5.11.0.0, Culture=neutral, PublicKeyToken=a128c98f1d7717c1, processorArchitecture=AMD64">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
<HintPath>..\..\..\..\..\..\..\Windows\assembly\GAC_64\Ivi.Visa.Interop\5.11.0.0__a128c98f1d7717c1\Ivi.Visa.Interop.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="K4os.Compression.LZ4, Version=1.1.11.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\K4os.Compression.LZ4.1.1.11\lib\net46\K4os.Compression.LZ4.dll</HintPath>
|
||||
</Reference>
|
||||
|
@ -7,7 +7,7 @@ Imports Newtonsoft.Json.Linq
|
||||
|
||||
Public Class mainForm
|
||||
Public projectName As String = "DUALSONIC SalesPacking MES Program Ver."
|
||||
Public projectVer As String = "1.0.1"
|
||||
Public projectVer As String = "1.0.2"
|
||||
|
||||
Private apiItemOutURL As String = "item-outflows/page"
|
||||
|
||||
|
@ -18,6 +18,10 @@ Public Class weightForm
|
||||
Private weightResult2 As Double = 0
|
||||
Private zeroSet As Boolean = True
|
||||
|
||||
Private weightBuffer As New List(Of Double) ' 무게 버퍼
|
||||
Private Const BUFFER_SIZE As Integer = 3 ' 버퍼 크기 (3개로 축소)
|
||||
Private Const STABILITY_THRESHOLD As Double = 5.0 ' 안정성 임계값 (5g로 완화)
|
||||
|
||||
|
||||
Private weight(2)
|
||||
Private weight2(1) As String
|
||||
@ -70,16 +74,25 @@ Public Class weightForm
|
||||
|
||||
End If
|
||||
ElseIf mainForm.rdbWeightQW.Checked = True Then
|
||||
|
||||
If weightResult2 > 5 Then ' 5g 이상이면 측정 시작
|
||||
statusTimer.Enabled = False
|
||||
' 실시간 무게 표시
|
||||
lbNowWeight.Text = Math.Round(weightResult2, 0).ToString()
|
||||
lbWeight.BackColor = Color.Yellow
|
||||
lbWeight.Text = "측정중"
|
||||
playTimer.Enabled = False
|
||||
lbWeight.Text = "측정중 (" & Math.Round(weightResult2, 0).ToString() & "g)"
|
||||
|
||||
If AutoMeasureScale() Then
|
||||
lbNowWeight.Text = weightResult2
|
||||
' 무게 버퍼에 추가 (안정성 확인용)
|
||||
AddToWeightBuffer(weightResult2)
|
||||
|
||||
If weight_compare() Then
|
||||
' 버퍼가 충분히 쌓이면 안정성 검사
|
||||
If weightBuffer.Count >= 3 AndAlso IsWeightStable() Then
|
||||
statusTimer.Enabled = False
|
||||
playTimer.Enabled = False
|
||||
|
||||
Dim stableWeight As Double = GetStableWeight()
|
||||
lbNowWeight.Text = Math.Round(stableWeight, 0).ToString()
|
||||
|
||||
If weight_compare_improved(stableWeight) Then
|
||||
lbWeight.BackColor = Color.Green
|
||||
lbWeight.Text = "무게 일치"
|
||||
delay(2000)
|
||||
@ -93,9 +106,6 @@ Public Class weightForm
|
||||
lbWeight.Text = "무게 불일치"
|
||||
ZeroTimer.Enabled = True
|
||||
End If
|
||||
Else
|
||||
lbWeight.Text = "무게 측정 불안정"
|
||||
lbWeight.BackColor = Color.Red
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
@ -133,6 +143,47 @@ Public Class weightForm
|
||||
|
||||
End Sub
|
||||
|
||||
' 무게 버퍼에 추가하는 함수
|
||||
Private Sub AddToWeightBuffer(weight As Double)
|
||||
weightBuffer.Add(weight)
|
||||
|
||||
' 버퍼 크기 초과 시 가장 오래된 값 제거
|
||||
If weightBuffer.Count > BUFFER_SIZE Then
|
||||
weightBuffer.RemoveAt(0)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
' 무게가 안정한지 확인하는 함수
|
||||
Private Function IsWeightStable() As Boolean
|
||||
If weightBuffer.Count < BUFFER_SIZE Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim maxWeight As Double = weightBuffer.Max()
|
||||
Dim minWeight As Double = weightBuffer.Min()
|
||||
|
||||
' 최대값과 최소값의 차이가 임계값보다 작으면 안정
|
||||
Return (maxWeight - minWeight) <= STABILITY_THRESHOLD
|
||||
End Function
|
||||
|
||||
' 안정된 무게값을 얻는 함수 (평균값 사용)
|
||||
Private Function GetStableWeight() As Double
|
||||
If weightBuffer.Count = 0 Then
|
||||
Return 0
|
||||
End If
|
||||
|
||||
Return weightBuffer.Average()
|
||||
End Function
|
||||
|
||||
' 개선된 무게 비교 함수
|
||||
Private Function weight_compare_improved(currentWeight As Double) As Boolean
|
||||
Dim targetWeight As Double = weightSum
|
||||
Dim upperLimit As Double = targetWeight + weightErrorPlus
|
||||
Dim lowerLimit As Double = targetWeight - weightErrorMinus
|
||||
|
||||
Return currentWeight >= lowerLimit And currentWeight <= upperLimit
|
||||
End Function
|
||||
|
||||
Private Sub Status_timer_Tick(sender As Object, e As EventArgs) Handles statusTimer.Tick
|
||||
If switchMotion = True Then
|
||||
lbWeight.BackColor = Color.MediumSlateBlue
|
||||
@ -159,10 +210,33 @@ Public Class weightForm
|
||||
|
||||
ElseIf mainForm.rdbWeightQW.Checked = True Then
|
||||
|
||||
lbNowWeight.Text = weightResult2
|
||||
lbNowWeight.Text = Math.Round(weightResult2, 0).ToString()
|
||||
' 무게 불일치 후 재측정 모드를 먼저 체크
|
||||
If zeroSet = False Then
|
||||
' 무게가 변경되었는지 확인 (이전 측정값과 5g 이상 차이나면 재측정 시작)
|
||||
Static previousWeight As Double = 0
|
||||
|
||||
' 실제 시리얼 데이터 직접 사용
|
||||
If weightResult2 <= 0 Then ' 1g 이하면 비어있음
|
||||
If Math.Abs(weightResult2 - previousWeight) >= 5 Then
|
||||
' 무게 변화 감지 - 재측정 시작
|
||||
statusTimer.Enabled = True
|
||||
playTimer.Enabled = True
|
||||
ZeroTimer.Enabled = False
|
||||
lbWeightEX.Text = weightSum
|
||||
lbWeight.Text = "재측정 중..."
|
||||
lbWeight.BackColor = Color.Yellow
|
||||
|
||||
' 버퍼 초기화
|
||||
weightBuffer.Clear()
|
||||
previousWeight = weightResult2
|
||||
Else
|
||||
' 무게 변화 없음 - 계속 대기
|
||||
lbWeight.Text = "무게를 조정해주세요"
|
||||
lbWeight.BackColor = Color.Orange
|
||||
ZeroTimer.Enabled = True
|
||||
previousWeight = weightResult2
|
||||
End If
|
||||
|
||||
ElseIf weightResult2 <= 0 Then
|
||||
statusTimer.Enabled = True
|
||||
playTimer.Enabled = True
|
||||
ZeroTimer.Enabled = False
|
||||
@ -286,7 +360,7 @@ Public Class weightForm
|
||||
|
||||
Private Sub QWSerialPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles QWSerialPort.DataReceived
|
||||
Try
|
||||
System.Threading.Thread.Sleep(100) ' 100ms 딜레이
|
||||
System.Threading.Thread.Sleep(300) '딜레이
|
||||
|
||||
Dim incoming As String = QWSerialPort.ReadExisting()
|
||||
'Debug.Print("수신 데이터: " & incoming)
|
||||
|
Loading…
x
Reference in New Issue
Block a user