feat: 무게데이터 받아올수 있도록 QW저울 모드 시리얼 포트 추가

This commit is contained in:
kje97 2025-06-23 17:56:29 +09:00
parent 6a9276c6d2
commit 4aa6d57d2a
5 changed files with 229 additions and 66 deletions

View File

@ -87,7 +87,7 @@
<HintPath>..\packages\MySql.Data.8.0.20\lib\net48\MySql.Data.dll</HintPath> <HintPath>..\packages\MySql.Data.8.0.20\lib\net48\MySql.Data.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="Npgsql, Version=8.0.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL"> <Reference Include="Npgsql, Version=8.0.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<HintPath>..\packages\Npgsql.8.0.1\lib\netstandard2.0\Npgsql.dll</HintPath> <HintPath>..\packages\Npgsql.8.0.1\lib\netstandard2.0\Npgsql.dll</HintPath>

View File

@ -4418,7 +4418,6 @@ Public Class mainForm
Return True Return True
End Try End Try
End Function End Function
Private SetPKCode As String = String.Empty Private SetPKCode As String = String.Empty
@ -5109,45 +5108,78 @@ Public Class mainForm
Try Try
If ckbWeight.Checked = True Then If ckbWeight.Checked = True Then
If serialName <> "" Or serialName <> Nothing Then If serialName <> "" Or serialName <> Nothing Then
If weightForm.cmdSerialPort.IsOpen = True Then Debug.Print("serialName: [" & serialName & "]")
weightForm.cmdSerialPort.Close() 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 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 Else
errorOut("통신설정오류") errorOut("통신설정오류")
errorGen("시리얼 포트를 설정하여 주십시오.") errorGen("시리얼 포트를 설정하여 주십시오.")
If pnMain.Visible = True Then If pnMain.Visible = True Then
btnOption.PerformClick() btnOption.PerformClick()
End If End If
Return True Return True
End If End If
End If End If
Return False Return False
Catch ex As Exception Catch ex As Exception
errorOut("통신설정오류") errorOut("통신설정오류")
errorGen("COM포트 에러 발생 : " & ex.Message) errorGen("COM포트 에러 발생 : " & ex.Message & " (포트: " & serialName & ")")
If pnMain.Visible = True Then If pnMain.Visible = True Then
btnOption.PerformClick() btnOption.PerformClick()
End If End If
Return True Return True
End Try End Try
End Function End Function
@ -5347,7 +5379,13 @@ Public Class mainForm
For cnt = 0 To cboComPort.Items.Count - 1 For cnt = 0 To cboComPort.Items.Count - 1
cboComPort.SelectedIndex = cnt cboComPort.SelectedIndex = cnt
If parsingCk = cboComPort.SelectedItem Then 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 End If
Next Next
End If End If
@ -5482,8 +5520,6 @@ Public Class mainForm
MsgBox("저장된 데이터를 불러올 수 없습니다." & saveType & "::" & ex.Message, vbCritical) MsgBox("저장된 데이터를 불러올 수 없습니다." & saveType & "::" & ex.Message, vbCritical)
End Try End Try
Debug.Print("Weight Radio Buttons: Auto=" & rdbWeightAuto.Checked & ", CAS=" & rdbWeightCAS.Checked & ", QW=" & rdbWeightQW.Checked)
End Sub 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 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

View File

@ -45,6 +45,7 @@ Partial Class weightForm
Me.playTimer = New System.Windows.Forms.Timer(Me.components) Me.playTimer = New System.Windows.Forms.Timer(Me.components)
Me.statusTimer = 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.cmdSerialPort = New System.IO.Ports.SerialPort(Me.components)
Me.QWSerialPort = New System.IO.Ports.SerialPort(Me.components)
Me.pnWeightTop.SuspendLayout() Me.pnWeightTop.SuspendLayout()
Me.pnWeightMid.SuspendLayout() Me.pnWeightMid.SuspendLayout()
Me.gbWeightBot.SuspendLayout() Me.gbWeightBot.SuspendLayout()
@ -59,9 +60,10 @@ Partial Class weightForm
' '
Me.pnWeightTop.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.pnWeightTop.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.pnWeightTop.Controls.Add(Me.lbWeightTop) 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.Name = "pnWeightTop"
Me.pnWeightTop.Size = New System.Drawing.Size(940, 85) Me.pnWeightTop.Size = New System.Drawing.Size(1074, 106)
Me.pnWeightTop.TabIndex = 17 Me.pnWeightTop.TabIndex = 17
' '
'lbWeightTop 'lbWeightTop
@ -69,9 +71,9 @@ Partial Class weightForm
Me.lbWeightTop.AutoSize = True 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.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.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.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.TabIndex = 3
Me.lbWeightTop.Text = "패 킹 박 스 무 게 측 정" Me.lbWeightTop.Text = "패 킹 박 스 무 게 측 정"
' '
@ -79,9 +81,10 @@ Partial Class weightForm
' '
Me.pnWeightMid.BackColor = System.Drawing.Color.Black Me.pnWeightMid.BackColor = System.Drawing.Color.Black
Me.pnWeightMid.Controls.Add(Me.lbWeight) 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.Name = "pnWeightMid"
Me.pnWeightMid.Size = New System.Drawing.Size(940, 168) Me.pnWeightMid.Size = New System.Drawing.Size(1074, 210)
Me.pnWeightMid.TabIndex = 18 Me.pnWeightMid.TabIndex = 18
' '
'lbWeight 'lbWeight
@ -89,9 +92,9 @@ Partial Class weightForm
Me.lbWeight.BackColor = System.Drawing.Color.Gold Me.lbWeight.BackColor = System.Drawing.Color.Gold
Me.lbWeight.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D 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.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.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.TabIndex = 14
Me.lbWeight.Text = "측정중" Me.lbWeight.Text = "측정중"
Me.lbWeight.TextAlign = System.Drawing.ContentAlignment.TopCenter 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.lbNowg)
Me.gbWeightBot.Controls.Add(Me.lbNowWeight) Me.gbWeightBot.Controls.Add(Me.lbNowWeight)
Me.gbWeightBot.Controls.Add(Me.picb_scale) 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.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.TabIndex = 23
Me.gbWeightBot.TabStop = False Me.gbWeightBot.TabStop = False
' '
'pnNow 'pnNow
' '
Me.pnNow.Controls.Add(Me.lbNow) 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.Name = "pnNow"
Me.pnNow.Size = New System.Drawing.Size(264, 72) Me.pnNow.Size = New System.Drawing.Size(302, 90)
Me.pnNow.TabIndex = 21 Me.pnNow.TabIndex = 21
' '
'lbNow 'lbNow
' '
Me.lbNow.AutoSize = True 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.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.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.TabIndex = 7
Me.lbNow.Text = "현재 무게 :" Me.lbNow.Text = "현재 무게 :"
' '
'pnExpect 'pnExpect
' '
Me.pnExpect.Controls.Add(Me.lbExpect) 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.Name = "pnExpect"
Me.pnExpect.Size = New System.Drawing.Size(213, 76) Me.pnExpect.Size = New System.Drawing.Size(243, 95)
Me.pnExpect.TabIndex = 18 Me.pnExpect.TabIndex = 18
' '
'lbExpect 'lbExpect
' '
Me.lbExpect.AutoSize = True 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.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.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.TabIndex = 9
Me.lbExpect.Text = "예상 무게 :" Me.lbExpect.Text = "예상 무게 :"
' '
'pnError 'pnError
' '
Me.pnError.Controls.Add(Me.lbError) 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.Name = "pnError"
Me.pnError.Size = New System.Drawing.Size(329, 62) Me.pnError.Size = New System.Drawing.Size(376, 78)
Me.pnError.TabIndex = 20 Me.pnError.TabIndex = 20
' '
'lbError 'lbError
' '
Me.lbError.Font = New System.Drawing.Font("함초롬바탕", 27.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte)) 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.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.TabIndex = 15
Me.lbError.Text = "(오차: +100, -100)" Me.lbError.Text = "(오차: +100, -100)"
' '
@ -168,17 +176,18 @@ Partial Class weightForm
' '
Me.pnWeightEX.Controls.Add(Me.lbWeightEX) Me.pnWeightEX.Controls.Add(Me.lbWeightEX)
Me.pnWeightEX.Controls.Add(Me.lbWeightEXg) 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.Name = "pnWeightEX"
Me.pnWeightEX.Size = New System.Drawing.Size(197, 76) Me.pnWeightEX.Size = New System.Drawing.Size(225, 95)
Me.pnWeightEX.TabIndex = 19 Me.pnWeightEX.TabIndex = 19
' '
'lbWeightEX 'lbWeightEX
' '
Me.lbWeightEX.Font = New System.Drawing.Font("함초롬바탕", 32.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(129, Byte)) 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.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.TabIndex = 13
Me.lbWeightEX.Text = "0" Me.lbWeightEX.Text = "0"
Me.lbWeightEX.TextAlign = System.Drawing.ContentAlignment.MiddleRight Me.lbWeightEX.TextAlign = System.Drawing.ContentAlignment.MiddleRight
@ -187,9 +196,9 @@ Partial Class weightForm
' '
Me.lbWeightEXg.AutoSize = True 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.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.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.TabIndex = 8
Me.lbWeightEXg.Text = "g" Me.lbWeightEXg.Text = "g"
' '
@ -197,9 +206,9 @@ Partial Class weightForm
' '
Me.lbNowg.AutoSize = True 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.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.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.TabIndex = 2
Me.lbNowg.Text = "g" Me.lbNowg.Text = "g"
' '
@ -208,9 +217,9 @@ Partial Class weightForm
Me.lbNowWeight.BackColor = System.Drawing.SystemColors.Control 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.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.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.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.TabIndex = 12
Me.lbNowWeight.Text = "0" Me.lbNowWeight.Text = "0"
Me.lbNowWeight.TextAlign = System.Drawing.ContentAlignment.MiddleRight Me.lbNowWeight.TextAlign = System.Drawing.ContentAlignment.MiddleRight
@ -218,9 +227,10 @@ Partial Class weightForm
'picb_scale 'picb_scale
' '
Me.picb_scale.Image = CType(resources.GetObject("picb_scale.Image"), System.Drawing.Image) 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.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.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
Me.picb_scale.TabIndex = 11 Me.picb_scale.TabIndex = 11
Me.picb_scale.TabStop = False Me.picb_scale.TabStop = False
@ -242,14 +252,14 @@ Partial Class weightForm
' '
'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.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.gbWeightBot)
Me.Controls.Add(Me.pnWeightMid) Me.Controls.Add(Me.pnWeightMid)
Me.Controls.Add(Me.pnWeightTop) Me.Controls.Add(Me.pnWeightTop)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) 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.MaximizeBox = False
Me.MinimizeBox = False Me.MinimizeBox = False
Me.Name = "weightForm" Me.Name = "weightForm"
@ -293,4 +303,5 @@ Partial Class weightForm
Friend WithEvents playTimer As Timer Friend WithEvents playTimer As Timer
Friend WithEvents statusTimer As Timer Friend WithEvents statusTimer As Timer
Friend WithEvents cmdSerialPort As IO.Ports.SerialPort Friend WithEvents cmdSerialPort As IO.Ports.SerialPort
Friend WithEvents QWSerialPort As IO.Ports.SerialPort
End Class End Class

View File

@ -121,7 +121,7 @@
<data name="picb_scale.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="picb_scale.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vwAADr8BOAVTJAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACe7SURBVHhe7d0J vgAADr4B6kKxwAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACe7SURBVHhe7d0J
tHx5Wd/rbpp5FEQZBEEUiOIVRUER4YYh2JggieAN0wWH4HgTE5BJBBGDoKKi4MQSBBQVMAy5IsqgDRgg tHx5Wd/rbpp5FEQZBEEUiOIVRUER4YYh2JggieAN0wWH4HgTE5BJBBGDoKKi4MQSBBQVMAy5IsqgDRgg
CUYcEEEZjMzIPA/NzfddYje5vr/6n33Oqdq7aj/PWp+1WNr/ql/Vqar9VtWuvc8CAAAAAAAAAAAAAAAA CUYcEEEZjMzIPA/NzfddYje5vr/6n33Oqdq7aj/PWp+1WNr/ql/Vqar9VtWuvc8CAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAB25krphumm6TbSCrp5ulG6agJYjUulu6anprem/09ace9Nv52+J9Uw AAAAAAAAAAAAAAAAAAAAAAAAAAB25krphumm6TbSCrp5ulG6agJYjUulu6anprem/09ace9Nv52+J9Uw
@ -306,6 +306,9 @@
<metadata name="cmdSerialPort.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="cmdSerialPort.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>348, 17</value> <value>348, 17</value>
</metadata> </metadata>
<metadata name="QWSerialPort.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>491, 19</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
AAABAAEApa4AAAEAIAAQ0QEAFgAAACgAAAClAAAAXAEAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAABAAEApa4AAAEAIAAQ0QEAFgAAACgAAAClAAAAXAEAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

View File

@ -1,4 +1,5 @@
Imports System.Windows.Forms Imports System.IO.Ports
Imports System.Windows.Forms
Public Class weightForm Public Class weightForm
Private weightSum As Integer Private weightSum As Integer
@ -14,10 +15,12 @@ Public Class weightForm
Private Delegate Sub serialDelegate() Private Delegate Sub serialDelegate()
Private updateDelegate As serialDelegate Private updateDelegate As serialDelegate
Private weightResult As Integer Private weightResult As Integer
Private weightResult2 As Double = 0
Private zeroSet As Boolean = True Private zeroSet As Boolean = True
Private weight(2) Private weight(2)
Private weight2(1) As String
Private Sub weightForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub weightForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ZeroTimer.Enabled = True ZeroTimer.Enabled = True
lbNowWeight.Text = Nothing lbNowWeight.Text = Nothing
@ -66,6 +69,35 @@ Public Class weightForm
End If End If
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 Else
scaleData = Mid(MeasureScale(200), 2, weight.Length) 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 Private Sub Zero_Timer_Tick(sender As Object, e As EventArgs) Handles ZeroTimer.Tick
Dim scaledata As String Dim scaledata As String
Dim weightValue As Double
Try Try
@ -124,6 +157,22 @@ Public Class weightForm
lbWeightEX.Text = weightSum lbWeightEX.Text = weightSum
lbWeight.Text = "저울에 올려주세요" lbWeight.Text = "저울에 올려주세요"
End If 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 Else
scaledata = Mid(MeasureScale(200), 2, weight.Length) scaledata = Mid(MeasureScale(200), 2, weight.Length)
@ -162,9 +211,28 @@ Public Class weightForm
Application.DoEvents() Application.DoEvents()
Loop Loop
End Sub 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 Private Function AutoMeasureScale() As Boolean
Try 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 Do
For i = 0 To 1 For i = 0 To 1
weight(i) = MeasureScale(200) weight(i) = MeasureScale(200)
@ -196,6 +264,51 @@ Public Class weightForm
statusTimer.Enabled = False statusTimer.Enabled = False
playTimer.Enabled = False playTimer.Enabled = False
End Sub 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 Private Sub cmdSerialPort_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles cmdSerialPort.DataReceived
Try Try