reading a scale through a com port....

  • 13 years ago

    I need some help trying to capture a weight on a scale that is hooked to the PC via a COM port. 

    I would like to be able to have the user click a button and have the weight captured.  Anyone done this before and could offer some code examples.

     Your help would be greatly appreciated.

  • 13 years ago

    Have you installed an OPOS driver for the scale?  If so then you can get a library of OPOS command objects, including a scale, from here.

  • 13 years ago

    Here's some code of mine used to claim and release an OPOS scale:

    Public ReadOnly Property Scale() As OPOSScale
    Get
    Return Me._scale
    End Get
    End Property

    Private Function ClaimScale() As Boolean
    Dim result As Boolean = False

    Me._scale = New OPOSScale

    If Me._scale.Open(Me.BusinessRules.Register.ScaleName) = 0 Then
    Dim retry As Boolean

    Do
    retry = False
    Me._scale.ClaimDevice(1000)

    If Me._scale.Claimed Then
    Me._scale.DeviceEnabled = True
    result = True
    Else
    Select Case MessageBox.Show(String.Format(My.Resources.ClaimScaleErrorString, _
    Me.BusinessRules.Register.ScaleName), _
    "TouchScreen Plus", _
    MessageBoxButtons.YesNoCancel, _
    MessageBoxIcon.Warning)
    Case DialogResult.Yes
    'Try again to claim the scale.
    retry = True
    Case DialogResult.No
    'Continue without integrated weighing.
    result = True
    End Select
    End If
    Loop While retry
    ElseIf MessageBox.Show(String.Format(My.Resources.OpenScaleErrorString, _
    Me.BusinessRules.Register.ScaleName), _
    "TouchScreen Plus", _
    MessageBoxButtons.OKCancel, _
    MessageBoxIcon.Warning) = DialogResult.OK Then
    'Continue without integrated weighing.
    result = True
    End If

    If Not Me._scale.Claimed Then
    Me._scale = Nothing
    Me.BusinessRules.Configuration.IntegratedWeighing = False
    End If

    Return result
    End Function

    Private Sub ReleaseScale()
    If Me._scale IsNot Nothing AndAlso Me._scale.Claimed Then
    Me._scale.ReleaseDevice()
    End If
    End Sub

    Here's some code used to read the weight from the scale:

    Private Sub scaleTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim scaleWeight As Integer = Me.GetScaleWeight()

    If scaleWeight <> -1 Then
    Me.Weight = scaleWeight / 1000
    Me.weightText.Text = Me.Weight.ToString("f3")
    End If
    End Sub

    Private Function GetScaleWeight() As Integer
    Dim weightData As Integer = 0

    My.Application.Scale.ReadWeight(weightData, 5000)

    Return weightData
    End Function
  • 13 years ago

    Where and How can i find out if i have a OPOSScale Driver.  Any other help you can provide on using this code would be great. 

  • 13 years ago
    If you haven't installed one then you won't have one.  Where did you get your scale from?  The supplier should be able to provide the driver for you.
  • 13 years ago

    Scale is made by weighttronix and will be used for weighing packages in a pack application.  It looks like your code is dealing more with Point of Sales systems so i am not even sure if mine is capable of having an OPOS driver.  Could be wrong.  If you have any other advice please let me know......Thanks

  • 13 years ago
    My advice, as it would be for any piece of hardware, is to speak to the supplier and ask them what interface(s) is available to speak to their hardware.  If it doesn't support OPOS then they will tell be able to tell you.  They will also be able to tell you what protocol(s) the scale supports and if there are any other drivers or components you can use to interface with the hardware.  If you need to listen directly to the serial port then .NET provides a SerialPort class.  That doesn't help you if you don't know what you're listening for though.
  • 13 years ago

    Just wanted to say thanks for the feedback.  It was my frist time communicating with a scale, so it was a bit of a learning process which turned out to be alot easier then i thought with the built in commands the scale comes with.  I was able to get the exact results i needed and now have a much better understanding of the product and the process of communicating with such objects.  

  • 12 years ago
    hi all, how about if i want to read a scale through com port by using PHP?if anyone ever tried this? thanks a lot
  • 12 years ago
    The command to request the weight from a scale weight-tronix is: W[ENTER] *** ascii value of [ENTER] is 13 To save time ... You can easily do this with the software BillRedirect http://www.billproduction.com/billscalebalance/ This software inputs your Weight-Tronix scale data directly into your Windows applications or in MS Excel, MS Access. Jack
  • 12 years ago
    Hi all, I am using WTCOMM.OCX and having problems coding it in ASP.NET. I am using it with an
  • 12 years ago
    I am not sure why my earlier message got truncated. I mean to write using an
  • 12 years ago
    object tag. sorry it stripped off HTML
  • Post a reply

    Enter your message below

    Sign in or Join us (it's free).

    Contribute

    Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

    Our tools

    We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

    “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald Knuth