diff --git a/SalesPacking_MES_API_Project/OrderPackingProcessor.vbproj b/SalesPacking_MES_API_Project/OrderPackingProcessor.vbproj
index 38fcd37..aafb537 100644
--- a/SalesPacking_MES_API_Project/OrderPackingProcessor.vbproj
+++ b/SalesPacking_MES_API_Project/OrderPackingProcessor.vbproj
@@ -87,7 +87,7 @@
..\packages\MySql.Data.8.0.20\lib\net48\MySql.Data.dll
- ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll
+ ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
..\packages\Npgsql.8.0.1\lib\netstandard2.0\Npgsql.dll
diff --git a/SalesPacking_MES_API_Project/mainForm.vb b/SalesPacking_MES_API_Project/mainForm.vb
index 44e13ac..9a0addd 100644
--- a/SalesPacking_MES_API_Project/mainForm.vb
+++ b/SalesPacking_MES_API_Project/mainForm.vb
@@ -4418,7 +4418,6 @@ Public Class mainForm
Return True
End Try
-
End Function
Private SetPKCode As String = String.Empty
@@ -5109,45 +5108,78 @@ Public Class mainForm
Try
If ckbWeight.Checked = True Then
If serialName <> "" Or serialName <> Nothing Then
- If weightForm.cmdSerialPort.IsOpen = True Then
- weightForm.cmdSerialPort.Close()
+ Debug.Print("serialName: [" & serialName & "]")
+ Debug.Print("QW 체크 여부: " & rdbWeightQW.Checked)
+
+ If rdbWeightQW.Checked Then
+ ' QW 모드: QWSerialPort 사용
+ Debug.Print("QW 시리얼 포트 설정 시작")
+
+ ' 기존 포트들 정리
+ If weightForm.QWSerialPort.IsOpen = True Then
+ weightForm.QWSerialPort.Close()
+ End If
+ If weightForm.cmdSerialPort.IsOpen = True Then
+ weightForm.cmdSerialPort.Close()
+ End If
+
+ With weightForm.QWSerialPort
+ .PortName = serialName
+ .BaudRate = 4800
+ .DataBits = 8
+ .Parity = Parity.None
+ .StopBits = StopBits.One
+ .Handshake = Handshake.None
+ .Encoding = System.Text.Encoding.ASCII
+ End With
+
+ weightForm.QWSerialPort.Open()
+ Debug.Print("QW 시리얼 통신 성공: " & serialName)
+ Return False
+
+ Else
+ ' 일반 모드: cmdSerialPort 사용
+ Debug.Print("일반 시리얼 포트 설정 시작")
+
+ ' 기존 포트들 정리
+ If weightForm.cmdSerialPort.IsOpen = True Then
+ weightForm.cmdSerialPort.Close()
+ End If
+ If weightForm.QWSerialPort.IsOpen = True Then
+ weightForm.QWSerialPort.Close()
+ End If
+
+ With weightForm.cmdSerialPort
+ .PortName = serialName
+ .BaudRate = 9600
+ .DataBits = 8
+ .Parity = Parity.None
+ .StopBits = StopBits.One
+ .Handshake = Handshake.None
+ End With
+
+ weightForm.cmdSerialPort.Open()
+ Debug.Print("일반 시리얼 통신 성공: " & serialName)
+ Return False
End If
- With weightForm.cmdSerialPort
- .PortName = serialName
- If rdbWeightQW.Checked Then
- .BaudRate = 4800
- Else
- .BaudRate = 9600
- End If
- .DataBits = 8
- .Parity = Parity.None
- .StopBits = StopBits.One
- .Handshake = Handshake.None
- End With
-
- weightForm.cmdSerialPort.Open()
-
- Return False
Else
errorOut("통신설정오류")
errorGen("시리얼 포트를 설정하여 주십시오.")
If pnMain.Visible = True Then
btnOption.PerformClick()
End If
-
Return True
End If
End If
-
Return False
+
Catch ex As Exception
errorOut("통신설정오류")
- errorGen("COM포트 에러 발생 : " & ex.Message)
+ errorGen("COM포트 에러 발생 : " & ex.Message & " (포트: " & serialName & ")")
If pnMain.Visible = True Then
btnOption.PerformClick()
End If
-
Return True
End Try
End Function
@@ -5347,7 +5379,13 @@ Public Class mainForm
For cnt = 0 To cboComPort.Items.Count - 1
cboComPort.SelectedIndex = cnt
If parsingCk = cboComPort.SelectedItem Then
- openSerial(parsingCk)
+ 'openSerial(parsingCk)
+ ' QW 모드라면 라디오 버튼 체크 후 한 번만 openSerial 호출
+ If rdbWeightQW.Checked = True Then
+ openSerial(parsingCk) ' parsingCk는 포트명(예: "COM5")이어야 함
+ Else
+ openSerial(parsingCk)
+ End If
End If
Next
End If
@@ -5482,8 +5520,6 @@ Public Class mainForm
MsgBox("저장된 데이터를 불러올 수 없습니다." & saveType & "::" & ex.Message, vbCritical)
End Try
- Debug.Print("Weight Radio Buttons: Auto=" & rdbWeightAuto.Checked & ", CAS=" & rdbWeightCAS.Checked & ", QW=" & rdbWeightQW.Checked)
-
End Sub
Private Sub ckbWeight_Click(sender As Object, e As EventArgs) Handles ckbWeight.Click, chbUseBarcode.Click, ckbPrinter.Click, ckbAPIuse.Click, rdbMode1.Click, rdbMode2.Click, rdbAuto1.Click, rdbAuto2.Click, rdbWeightAuto.Click, rdbWeightCAS.Click, rdbWeightQW.Click, rdbMesDbAPI.Click, rdbMesDbPg.Click, rdbNew.Click, rdbBef.Click
diff --git a/SalesPacking_MES_API_Project/weightForm.Designer.vb b/SalesPacking_MES_API_Project/weightForm.Designer.vb
index 5582552..94a4564 100644
--- a/SalesPacking_MES_API_Project/weightForm.Designer.vb
+++ b/SalesPacking_MES_API_Project/weightForm.Designer.vb
@@ -45,6 +45,7 @@ Partial Class weightForm
Me.playTimer = New System.Windows.Forms.Timer(Me.components)
Me.statusTimer = New System.Windows.Forms.Timer(Me.components)
Me.cmdSerialPort = New System.IO.Ports.SerialPort(Me.components)
+ Me.QWSerialPort = New System.IO.Ports.SerialPort(Me.components)
Me.pnWeightTop.SuspendLayout()
Me.pnWeightMid.SuspendLayout()
Me.gbWeightBot.SuspendLayout()
@@ -59,9 +60,10 @@ Partial Class weightForm
'
Me.pnWeightTop.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.pnWeightTop.Controls.Add(Me.lbWeightTop)
- Me.pnWeightTop.Location = New System.Drawing.Point(12, 7)
+ Me.pnWeightTop.Location = New System.Drawing.Point(14, 9)
+ Me.pnWeightTop.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.pnWeightTop.Name = "pnWeightTop"
- Me.pnWeightTop.Size = New System.Drawing.Size(940, 85)
+ Me.pnWeightTop.Size = New System.Drawing.Size(1074, 106)
Me.pnWeightTop.TabIndex = 17
'
'lbWeightTop
@@ -69,9 +71,9 @@ Partial Class weightForm
Me.lbWeightTop.AutoSize = True
Me.lbWeightTop.Font = New System.Drawing.Font("함초롬바탕", 36.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
Me.lbWeightTop.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(192, Byte), Integer))
- Me.lbWeightTop.Location = New System.Drawing.Point(215, 9)
+ Me.lbWeightTop.Location = New System.Drawing.Point(246, 11)
Me.lbWeightTop.Name = "lbWeightTop"
- Me.lbWeightTop.Size = New System.Drawing.Size(501, 62)
+ Me.lbWeightTop.Size = New System.Drawing.Size(623, 78)
Me.lbWeightTop.TabIndex = 3
Me.lbWeightTop.Text = "패 킹 박 스 무 게 측 정"
'
@@ -79,9 +81,10 @@ Partial Class weightForm
'
Me.pnWeightMid.BackColor = System.Drawing.Color.Black
Me.pnWeightMid.Controls.Add(Me.lbWeight)
- Me.pnWeightMid.Location = New System.Drawing.Point(12, 100)
+ Me.pnWeightMid.Location = New System.Drawing.Point(14, 125)
+ Me.pnWeightMid.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.pnWeightMid.Name = "pnWeightMid"
- Me.pnWeightMid.Size = New System.Drawing.Size(940, 168)
+ Me.pnWeightMid.Size = New System.Drawing.Size(1074, 210)
Me.pnWeightMid.TabIndex = 18
'
'lbWeight
@@ -89,9 +92,9 @@ Partial Class weightForm
Me.lbWeight.BackColor = System.Drawing.Color.Gold
Me.lbWeight.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lbWeight.Font = New System.Drawing.Font("함초롬바탕", 69.74999!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
- Me.lbWeight.Location = New System.Drawing.Point(51, 14)
+ Me.lbWeight.Location = New System.Drawing.Point(58, 18)
Me.lbWeight.Name = "lbWeight"
- Me.lbWeight.Size = New System.Drawing.Size(842, 139)
+ Me.lbWeight.Size = New System.Drawing.Size(962, 174)
Me.lbWeight.TabIndex = 14
Me.lbWeight.Text = "측정중"
Me.lbWeight.TextAlign = System.Drawing.ContentAlignment.TopCenter
@@ -105,62 +108,67 @@ Partial Class weightForm
Me.gbWeightBot.Controls.Add(Me.lbNowg)
Me.gbWeightBot.Controls.Add(Me.lbNowWeight)
Me.gbWeightBot.Controls.Add(Me.picb_scale)
- Me.gbWeightBot.Location = New System.Drawing.Point(12, 270)
+ Me.gbWeightBot.Location = New System.Drawing.Point(14, 338)
+ Me.gbWeightBot.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.gbWeightBot.Name = "gbWeightBot"
- Me.gbWeightBot.Size = New System.Drawing.Size(940, 279)
+ Me.gbWeightBot.Padding = New System.Windows.Forms.Padding(3, 4, 3, 4)
+ Me.gbWeightBot.Size = New System.Drawing.Size(1074, 349)
Me.gbWeightBot.TabIndex = 23
Me.gbWeightBot.TabStop = False
'
'pnNow
'
Me.pnNow.Controls.Add(Me.lbNow)
- Me.pnNow.Location = New System.Drawing.Point(7, 54)
+ Me.pnNow.Location = New System.Drawing.Point(8, 68)
+ Me.pnNow.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.pnNow.Name = "pnNow"
- Me.pnNow.Size = New System.Drawing.Size(264, 72)
+ Me.pnNow.Size = New System.Drawing.Size(302, 90)
Me.pnNow.TabIndex = 21
'
'lbNow
'
Me.lbNow.AutoSize = True
Me.lbNow.Font = New System.Drawing.Font("함초롬바탕", 36.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
- Me.lbNow.Location = New System.Drawing.Point(3, 5)
+ Me.lbNow.Location = New System.Drawing.Point(3, 6)
Me.lbNow.Name = "lbNow"
- Me.lbNow.Size = New System.Drawing.Size(258, 62)
+ Me.lbNow.Size = New System.Drawing.Size(320, 78)
Me.lbNow.TabIndex = 7
Me.lbNow.Text = "현재 무게 :"
'
'pnExpect
'
Me.pnExpect.Controls.Add(Me.lbExpect)
- Me.pnExpect.Location = New System.Drawing.Point(21, 149)
+ Me.pnExpect.Location = New System.Drawing.Point(24, 186)
+ Me.pnExpect.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.pnExpect.Name = "pnExpect"
- Me.pnExpect.Size = New System.Drawing.Size(213, 76)
+ Me.pnExpect.Size = New System.Drawing.Size(243, 95)
Me.pnExpect.TabIndex = 18
'
'lbExpect
'
Me.lbExpect.AutoSize = True
Me.lbExpect.Font = New System.Drawing.Font("함초롬바탕", 27.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
- Me.lbExpect.Location = New System.Drawing.Point(11, 13)
+ Me.lbExpect.Location = New System.Drawing.Point(13, 16)
Me.lbExpect.Name = "lbExpect"
- Me.lbExpect.Size = New System.Drawing.Size(200, 49)
+ Me.lbExpect.Size = New System.Drawing.Size(254, 61)
Me.lbExpect.TabIndex = 9
Me.lbExpect.Text = "예상 무게 :"
'
'pnError
'
Me.pnError.Controls.Add(Me.lbError)
- Me.pnError.Location = New System.Drawing.Point(292, 214)
+ Me.pnError.Location = New System.Drawing.Point(334, 268)
+ Me.pnError.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.pnError.Name = "pnError"
- Me.pnError.Size = New System.Drawing.Size(329, 62)
+ Me.pnError.Size = New System.Drawing.Size(376, 78)
Me.pnError.TabIndex = 20
'
'lbError
'
Me.lbError.Font = New System.Drawing.Font("함초롬바탕", 27.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
- Me.lbError.Location = New System.Drawing.Point(1, 4)
+ Me.lbError.Location = New System.Drawing.Point(1, 5)
Me.lbError.Name = "lbError"
- Me.lbError.Size = New System.Drawing.Size(339, 52)
+ Me.lbError.Size = New System.Drawing.Size(387, 65)
Me.lbError.TabIndex = 15
Me.lbError.Text = "(오차: +100, -100)"
'
@@ -168,17 +176,18 @@ Partial Class weightForm
'
Me.pnWeightEX.Controls.Add(Me.lbWeightEX)
Me.pnWeightEX.Controls.Add(Me.lbWeightEXg)
- Me.pnWeightEX.Location = New System.Drawing.Point(240, 149)
+ Me.pnWeightEX.Location = New System.Drawing.Point(274, 186)
+ Me.pnWeightEX.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.pnWeightEX.Name = "pnWeightEX"
- Me.pnWeightEX.Size = New System.Drawing.Size(197, 76)
+ Me.pnWeightEX.Size = New System.Drawing.Size(225, 95)
Me.pnWeightEX.TabIndex = 19
'
'lbWeightEX
'
Me.lbWeightEX.Font = New System.Drawing.Font("함초롬바탕", 32.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
- Me.lbWeightEX.Location = New System.Drawing.Point(6, 10)
+ Me.lbWeightEX.Location = New System.Drawing.Point(7, 12)
Me.lbWeightEX.Name = "lbWeightEX"
- Me.lbWeightEX.Size = New System.Drawing.Size(151, 57)
+ Me.lbWeightEX.Size = New System.Drawing.Size(173, 71)
Me.lbWeightEX.TabIndex = 13
Me.lbWeightEX.Text = "0"
Me.lbWeightEX.TextAlign = System.Drawing.ContentAlignment.MiddleRight
@@ -187,9 +196,9 @@ Partial Class weightForm
'
Me.lbWeightEXg.AutoSize = True
Me.lbWeightEXg.Font = New System.Drawing.Font("함초롬바탕", 24.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
- Me.lbWeightEXg.Location = New System.Drawing.Point(152, 19)
+ Me.lbWeightEXg.Location = New System.Drawing.Point(174, 24)
Me.lbWeightEXg.Name = "lbWeightEXg"
- Me.lbWeightEXg.Size = New System.Drawing.Size(36, 41)
+ Me.lbWeightEXg.Size = New System.Drawing.Size(44, 52)
Me.lbWeightEXg.TabIndex = 8
Me.lbWeightEXg.Text = "g"
'
@@ -197,9 +206,9 @@ Partial Class weightForm
'
Me.lbNowg.AutoSize = True
Me.lbNowg.Font = New System.Drawing.Font("함초롬바탕", 36.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
- Me.lbNowg.Location = New System.Drawing.Point(587, 64)
+ Me.lbNowg.Location = New System.Drawing.Point(671, 80)
Me.lbNowg.Name = "lbNowg"
- Me.lbNowg.Size = New System.Drawing.Size(54, 62)
+ Me.lbNowg.Size = New System.Drawing.Size(67, 78)
Me.lbNowg.TabIndex = 2
Me.lbNowg.Text = "g"
'
@@ -208,9 +217,9 @@ Partial Class weightForm
Me.lbNowWeight.BackColor = System.Drawing.SystemColors.Control
Me.lbNowWeight.Font = New System.Drawing.Font("함초롬바탕", 60.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte))
Me.lbNowWeight.ForeColor = System.Drawing.Color.DarkBlue
- Me.lbNowWeight.Location = New System.Drawing.Point(274, 29)
+ Me.lbNowWeight.Location = New System.Drawing.Point(313, 36)
Me.lbNowWeight.Name = "lbNowWeight"
- Me.lbNowWeight.Size = New System.Drawing.Size(313, 104)
+ Me.lbNowWeight.Size = New System.Drawing.Size(358, 130)
Me.lbNowWeight.TabIndex = 12
Me.lbNowWeight.Text = "0"
Me.lbNowWeight.TextAlign = System.Drawing.ContentAlignment.MiddleRight
@@ -218,9 +227,10 @@ Partial Class weightForm
'picb_scale
'
Me.picb_scale.Image = CType(resources.GetObject("picb_scale.Image"), System.Drawing.Image)
- Me.picb_scale.Location = New System.Drawing.Point(627, 42)
+ Me.picb_scale.Location = New System.Drawing.Point(717, 52)
+ Me.picb_scale.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
Me.picb_scale.Name = "picb_scale"
- Me.picb_scale.Size = New System.Drawing.Size(284, 231)
+ Me.picb_scale.Size = New System.Drawing.Size(325, 289)
Me.picb_scale.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
Me.picb_scale.TabIndex = 11
Me.picb_scale.TabStop = False
@@ -242,14 +252,14 @@ Partial Class weightForm
'
'weightForm
'
- Me.AutoScaleDimensions = New System.Drawing.SizeF(7.0!, 12.0!)
+ Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
- Me.ClientSize = New System.Drawing.Size(964, 561)
+ Me.ClientSize = New System.Drawing.Size(1102, 701)
Me.Controls.Add(Me.gbWeightBot)
Me.Controls.Add(Me.pnWeightMid)
Me.Controls.Add(Me.pnWeightTop)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
- Me.Margin = New System.Windows.Forms.Padding(4, 3, 4, 3)
+ Me.Margin = New System.Windows.Forms.Padding(5, 4, 5, 4)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "weightForm"
@@ -293,4 +303,5 @@ Partial Class weightForm
Friend WithEvents playTimer As Timer
Friend WithEvents statusTimer As Timer
Friend WithEvents cmdSerialPort As IO.Ports.SerialPort
+ Friend WithEvents QWSerialPort As IO.Ports.SerialPort
End Class
diff --git a/SalesPacking_MES_API_Project/weightForm.resx b/SalesPacking_MES_API_Project/weightForm.resx
index f88c8f5..64c3306 100644
--- a/SalesPacking_MES_API_Project/weightForm.resx
+++ b/SalesPacking_MES_API_Project/weightForm.resx
@@ -121,7 +121,7 @@
iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
- vwAADr8BOAVTJAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACe7SURBVHhe7d0J
+ vgAADr4B6kKxwAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACe7SURBVHhe7d0J
tHx5Wd/rbpp5FEQZBEEUiOIVRUER4YYh2JggieAN0wWH4HgTE5BJBBGDoKKi4MQSBBQVMAy5IsqgDRgg
CUYcEEEZjMzIPA/NzfddYje5vr/6n33Oqdq7aj/PWp+1WNr/ql/Vqar9VtWuvc8CAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAB25krphumm6TbSCrp5ulG6agJYjUulu6anprem/09ace9Nv52+J9Uw
@@ -306,6 +306,9 @@
348, 17
+
+ 491, 19
+
AAABAAEApa4AAAEAIAAQ0QEAFgAAACgAAAClAAAAXAEAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
diff --git a/SalesPacking_MES_API_Project/weightForm.vb b/SalesPacking_MES_API_Project/weightForm.vb
index c16092e..1f0efee 100644
--- a/SalesPacking_MES_API_Project/weightForm.vb
+++ b/SalesPacking_MES_API_Project/weightForm.vb
@@ -1,4 +1,5 @@
-Imports System.Windows.Forms
+Imports System.IO.Ports
+Imports System.Windows.Forms
Public Class weightForm
Private weightSum As Integer
@@ -14,10 +15,12 @@ Public Class weightForm
Private Delegate Sub serialDelegate()
Private updateDelegate As serialDelegate
Private weightResult As Integer
+ Private weightResult2 As Double = 0
Private zeroSet As Boolean = True
Private weight(2)
+ Private weight2(1) As String
Private Sub weightForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ZeroTimer.Enabled = True
lbNowWeight.Text = Nothing
@@ -66,6 +69,35 @@ Public Class weightForm
End If
End If
+ ElseIf mainForm.rdbWeightQW.Checked = True Then
+ If weightResult2 > 5 Then ' 5g 이상이면 측정 시작
+ statusTimer.Enabled = False
+ lbWeight.BackColor = Color.Yellow
+ lbWeight.Text = "측정중"
+ playTimer.Enabled = False
+
+ If AutoMeasureScale() Then
+ lbNowWeight.Text = weightResult2 ' 실제 측정값 표시
+
+ If weight_compare() Then
+ lbWeight.BackColor = Color.Green
+ lbWeight.Text = "무게 일치"
+ delay(2000)
+ mainForm.weightResult = lbNowWeight.Text
+ mainForm.txbCheckWeight.Text = lbNowWeight.Text
+ mainForm.weightOkNg = True
+ Me.DialogResult = DialogResult.OK
+ Else
+ zeroSet = False
+ lbWeight.BackColor = Color.Red
+ lbWeight.Text = "무게 불일치"
+ ZeroTimer.Enabled = True
+ End If
+ Else
+ lbWeight.Text = "무게 측정 불안정"
+ lbWeight.BackColor = Color.Red
+ End If
+ End If
Else
scaleData = Mid(MeasureScale(200), 2, weight.Length)
@@ -113,6 +145,7 @@ Public Class weightForm
Private Sub Zero_Timer_Tick(sender As Object, e As EventArgs) Handles ZeroTimer.Tick
Dim scaledata As String
+ Dim weightValue As Double
Try
@@ -124,6 +157,22 @@ Public Class weightForm
lbWeightEX.Text = weightSum
lbWeight.Text = "저울에 올려주세요"
End If
+
+ ElseIf mainForm.rdbWeightQW.Checked = True Then
+ ' 실제 시리얼 데이터 직접 사용
+ If weightResult2 <= 0 Then ' 1g 이하면 비어있음
+ statusTimer.Enabled = True
+ playTimer.Enabled = True
+ ZeroTimer.Enabled = False
+ lbWeightEX.Text = weightSum
+ lbWeight.Text = "저울에 올려주세요"
+ lbWeight.BackColor = Color.White
+ Else
+ ZeroTimer.Enabled = False
+ lbWeight.Text = "저울을 비워주세요 (현재: " & weightResult2.ToString("F0") & "g)"
+ lbWeight.BackColor = Color.Red
+ ZeroTimer.Enabled = True
+ End If
Else
scaledata = Mid(MeasureScale(200), 2, weight.Length)
@@ -162,9 +211,28 @@ Public Class weightForm
Application.DoEvents()
Loop
End Sub
+ Private Function MeasureScale2(timeout As Integer) As String
+ 'Return "US,GS, " & weightResult.ToString("F3") & " kg"
+ Return "US,GS, " & (weightResult2 * 1000).ToString("F0") & " g"
+ End Function
Private Function AutoMeasureScale() As Boolean
Try
+ If mainForm.rdbWeightQW.Checked = True Then
+ ' 2번 측정해서 무게가 거의 같으면 OK
+ For i = 0 To 1
+ weight2(i) = MeasureScale2(200) ' 예: "US,GS, 0.901 kg"
+ Next
+
+ Dim w0 As Double = ParseWeightData(weight2(0))
+ Dim w1 As Double = ParseWeightData(weight2(1))
+
+ If Math.Abs(w0 - w1) < 10 Then ' 10g 이내 차이 (kg 단위면 0.01)
+ Return True
+ Else
+ Return False
+ End If
+ End If
Do
For i = 0 To 1
weight(i) = MeasureScale(200)
@@ -196,6 +264,51 @@ Public Class weightForm
statusTimer.Enabled = False
playTimer.Enabled = False
End Sub
+ Private Function ParseWeightData(data As String) As Double
+ Try
+ Dim m = System.Text.RegularExpressions.Regex.Match(data, "([-+]?\d+\.\d+|\d+)\s*(kg|g)")
+ If m.Success Then
+ Dim value As Double = Convert.ToDouble(m.Groups(1).Value)
+ Dim unit As String = m.Groups(2).Value.ToLower()
+ If unit = "kg" Then
+ value = value * 1000 ' kg → g 변환
+ End If
+ Return value ' g 단위로 반환
+ End If
+ Catch ex As Exception
+ Debug.Print("파싱 오류: " & ex.Message)
+ End Try
+ Return 0
+ End Function
+
+ Private Sub QWSerialPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles QWSerialPort.DataReceived
+ Try
+ Dim incoming As String = QWSerialPort.ReadExisting()
+ Debug.Print("수신 데이터: " & incoming)
+
+ ' 여러 줄이 들어올 수 있으니, 줄 단위로 분리
+ Dim lines() As String = incoming.Split({vbCr, vbLf}, StringSplitOptions.RemoveEmptyEntries)
+ Dim maxWeight As Double = 0
+
+ For Each line As String In lines
+ Dim w As Double = ParseWeightData(line)
+ If w > maxWeight Then maxWeight = w
+ Next
+
+ weightResult2 = maxWeight
+ 'Debug.Print(maxWeight)
+ 'Debug.Print(weightResult2)
+
+ If weightResult2 = 0 Then
+ zeroSet = True
+ Else
+ zeroSet = False
+ End If
+
+ Catch ex As Exception
+ Debug.Print("수신 오류: " & ex.Message)
+ End Try
+ End Sub
Private Sub cmdSerialPort_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles cmdSerialPort.DataReceived
Try