Click here to Skip to main content
15,936,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to receive or read data from RS232 port and USB port in visual basic .net for Digital Weighing Scale??
Can someone upload a finished code for my reference?
Posted

1 solution

In order to coomunicate with, you should know the protocol the digital weighting scale uses. Please check out the documentation provided by the manufacturer.
 
Share this answer
 
Comments
Visual Basic Net Communication 4-Jan-12 7:54am    
What is the protocol?
I don't see the digital weighing scale yet.
But I'm coding it now. Because the shop of Digital weighing scale is so far that's why I'm finishing my project in school before going in the weighing shop. The transportation expenses is very very expensive.

Can you give me a tutorial sir?
Thank you.
CPallini 4-Jan-12 7:59am    
How could I help you (without knowing myself the protocol)?
You possibly don't need the actual device for reading the protocol specifications: if you know the scale model then you may perhaps find some info about just Googling for.
Visual Basic Net Communication 4-Jan-12 8:02am    
Imports System.Text
Imports System
Imports System.IO.Ports
Imports System.IO
Imports Microsoft.VisualBasic
Module Module1
Public ComportSelect As String
Public test1 As String
Public filename As String = "standard"
Public labelString As String
Function getserialdata()
' GET DATA FROM COM PORT
ComportSelect = My.Forms.MainMenu.ComportSelect
Dim returnStr As String
Dim a As Int16 = 0
Dim b As Int16
returnStr = "1"
Do
Try
REM Dim buffer As New StringBuilder()
Using comPort As SerialPort = My.Computer.Ports.OpenSerialPort(ComportSelect)
' SEND "P" COMMAND TO SCALES TO START TRANSMITTING
Dim outgoing As String
outgoing = "P"
comPort.WriteLine(outgoing)
' READ DATA
comPort.ReadTimeout = 2000
Dim line As String = comPort.ReadLine()
returnStr = (line)
comPort.Close()
returnStr = returnStr.Substring(1)
End Using
' REMOVE ALL UNWANTED CHARACTERS
If returnStr.Length > 2 Then
a = 0
Dim TestString As String = returnStr
Dim TestArray() As String = Split(TestString)
' TestArray holds {"chr2)", "", "", "", "0.0", "lb", "gr", ""}
Dim LastNonEmpty As Integer = -1
For i As Integer = 0 To TestArray.Length - 1
If TestArray(i) <> "" Then
LastNonEmpty += 1
TestArray(LastNonEmpty) = TestArray(i)
End If
Next
If TestArray(0) = "-" Then
TestArray(1) = TestArray(0) + TestArray(1)
b = 1
returnStr = TestArray(1) + " " + TestArray(2)
Else : b = 0
returnStr = TestArray(0) + " " + TestArray(1)
End If
ReDim Preserve TestArray(LastNonEmpty)
' TestArray now holds {"10.9", "Lb", "Gr"
REM Test weight toloerence
Dim weightD As Decimal
'Dim weightS As String = "1"
Dim hightol As Decimal
Dim lowtol As Decimal
' TestArray now holds {"10.9", "Lb", "Gr"
weightD = Convert.ToDecimal(TestArray(b))
hightol = Convert.ToDecimal(My.Forms.MainMenu.maxweight.Text)
lowtol = Convert.ToDecimal(My.Forms.MainMenu.TextBox2.Text)
REM test for max weight
If weightD < hightol And weightD > lowtol Then Exit Do
If weightD > hightol Then
My.Forms.MainMenu.Comla.Text = "WEIGHT IS TO HIGH"
My.Forms.MainMenu.comlb.Text = "PRESS OK TO RE-MEASURE"
My.Forms.MainMenu.ShowDialog()
returnStr = "No Comport"
a = 1
End If
REM test for min weight
If weightD < lowtol Then
My.Forms.MainMenu.Comla.Text = "WEIGHT IS TO LOW"
My.Forms.MainMenu.comlb.Text = "PRESS OK TO RE-MEASURE"
My.Forms.MainMenu.ShowDialog()
returnStr = "No Comport"
a = 1
End If
Else
My.Forms.MainMenu.Comla.Text = "Comport Has no Connection, Check Connection"
My.Forms.MainMenu.comlb.Text = "PRESS CANCEL"
My.Forms.MainMenu.ShowDialog()
returnStr = "No Comport"
a = 0
E
Noe Chavarria 11-Nov-17 11:21am    
Muchisimas gracias!, esto me salvo la vida


Saludos
Visual Basic Net Communication 4-Jan-12 8:04am    
End If
Catch e As TimeoutException
If e Is Nothing Then
a = 0
Else
My.Forms.MainMenu.Comla.Text = "Scale in motion press ok to retry"
My.Forms.MainMenu.comlb.Text = "or TimeoutException, press cancel"
My.Forms.MainMenu.ShowDialog()
a = 1
returnStr = "No Comport"
End If
REM Console.WriteLine(e)

End Try
If My.Forms.MainMenu.DialogResult = System.Windows.Forms.DialogResult.Cancel Then Exit Do
If a = 0 Then Exit Do
Loop
Return returnStr
End Function
End Module

There's an error in the code ComportSelect = My.Forms.MainMenu.ComportSelect

What should I use in that code.
MSComlib or Serial port or what?

I don't have enough money in searching google because I just use prepaid broadband. My parent give all they can for me to graduate.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900