Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How we take input from electronic weight machine in over windows application. which connect with cabinet in Serial Port (IOIOI A) (4-5 male Pin). (like a canta)
Posted
Updated 2-Apr-10 21:38pm
v3
Comments
Rahul JR 8-Jul-15 3:21am    
Hi Vinod have you completed your task of Take input of weight from electronic weight machine.Than provide me details of Which Machine you used (Manufacture name and Machine Name) please provide if you does it. I need to purchase a machine that can be interfaced with software.

What you need is:
- the interface documentation of your weight machine;
- the SerialPort class;
- and some programming.

The level of difficulty will depend on how well they structured the software interface; ASCII messages ending on a NewLine would be easiest.

I would recommend C# or VB.NET; whatever you do, don't go ancient VB.

:)
 
Share this answer
 
 
Share this answer
 
There are several Ways to do this and everyone has some kind of drawback because of the serial port setup in .net. But I succeeded in do this in VB. This example sends a P command to the serial port which tells the scale to send the weight data. The scales have a lot of different data can be sent. This is with the scales seutup just to send the weight as follows {"10.9", "Lb", "Gr"). Also the scales esttings have to set the same as your port or visversa (Baud= 9600,Data= 8, Parity= none, 1 stop.
Now it has other characters that have to be removed and this depends on the scale. So it takes some playing with to get exactly what you want. This can be used with a serialport to usb adapter but some adapters just will not work correctly so if one type doesn't work try a different one. Radio Shack has one that worked for me.


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.LABELSELECT.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.LABELSELECT.maxweight.Text)
                    lowtol = Convert.ToDecimal(My.Forms.LABELSELECT.minweight.Text)
                    REM test for max weight
                    If weightD < hightol And weightD > lowtol Then Exit Do
                    If weightD > hightol Then
                        My.Forms.COMPORT.Comla.Text = "WEIGHT IS TO HIGH"
                        My.Forms.COMPORT.comlb.Text = "PRESS OK TO RE-MEASURE"
                        My.Forms.COMPORT.ShowDialog()
                        returnStr = "No Comport"
                        a = 1
                    End If
                    REM test for min weight
                    If weightD < lowtol Then
                        My.Forms.COMPORT.Comla.Text = "WEIGHT IS TO LOW"
                        My.Forms.COMPORT.comlb.Text = "PRESS OK TO RE-MEASURE"
                        My.Forms.COMPORT.ShowDialog()
                        returnStr = "No Comport"
                        a = 1
                    End If
                Else
                    My.Forms.COMPORT.Comla.Text = "Comport Has no Connection, Check Connection"
                    My.Forms.COMPORT.comlb.Text = "PRESS CANCEL"
                    My.Forms.COMPORT.ShowDialog()
                    returnStr = "No Comport"
                    a = 0
                End If

            Catch e As System.ArgumentException
                If e Is Nothing Then
                Else
                    My.Forms.COMPORT.Comla.Text = "No Comport selected"
                    My.Forms.COMPORT.comlb.Text = "ArgumentException, PRESS CANCEL"
                    My.Forms.COMPORT.ShowDialog()
                    returnStr = "No Comport"
                    a = 0
                End If
            Catch e As System.UnauthorizedAccessException
                If e Is Nothing Then
                Else
                    My.Forms.COMPORT.Comla.Text = "Comport Has no Connection, Select another port"
                    My.Forms.COMPORT.comlb.Text = "or UnauthorizedAccessException, press cancel"
                    My.Forms.COMPORT.ShowDialog()
                    returnStr = "No Comport"
                    a = 0
                End If
            Catch e As TimeoutException
                If e Is Nothing Then
                    a = 0
                Else
                    My.Forms.COMPORT.Comla.Text = "Scale in motion press ok to retry"
                    My.Forms.COMPORT.comlb.Text = "or TimeoutException, press cancel"
                    My.Forms.COMPORT.ShowDialog()
                    a = 1
                    returnStr = "No Comport"
                End If
                REM Console.WriteLine(e)

            End Try
            If My.Forms.COMPORT.DialogResult = System.Windows.Forms.DialogResult.Cancel Then Exit Do
            If a = 0 Then Exit Do
        Loop
        Return returnStr
    End Function
End Module
 
Share this answer
 
Comments
Visual Basic Net Communication 4-Jan-12 7:45am    
Can you upload the source code compiled in visual basic .net?
I don't know how to assemble this code.
Thank you.
Visual Basic Net Communication 4-Jan-12 7:56am    
My.Forms.MainMenu.ComportSelect is the only one error in VB.

Error: Value of type 'AxMSCommLib.AxMSComm' cannot be converted to 'String'.

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