Retrieve Weight From Mettler Toledo Scale via RS232

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 11196 Views - Last Post: 17 October 2012 - 10:50 PM Rate Topic: -----

#1 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Retrieve Weight From Mettler Toledo Scale via RS232

Posted 10 October 2012 - 06:07 AM

I am trying to get weight data from a Mettler Toledo Scale using RS232 port into my program. With continuous mode output setting into the COM1 port of the scale, i am able to trigger the DataReceived event. However, the data that I am receiving from the scale is "?{????}?{m?........"

Here is my code:

Imports System
Imports System.IO.Ports

Public Class Form1
    Public Delegate Sub myDelegate()

    Dim WithEvents port As SerialPort = New System.IO.Ports.SerialPort("COM5", 9600, Parity.Even, 8, StopBits.One)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CheckForIllegalCrossThreadCalls = False
        If port.IsOpen = False Then
            Try
                port.Open()
                'MessageBox.Show("Open")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

        End If

    End Sub

    Public Sub updateTextBox()
        Dim strarr(8) As String
        Dim str1 As String
        str1 = port.ReadLine
        txtreceive.AppendText(str1)
        strarr = str1.Split(",")
        Dim x1 As Double
        x1 = Val(strarr(0))
        MsgBox(x1)
        txtreceive.ScrollToCaret()
    End Sub

    Private Sub port_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles port.DataReceived
        txtreceive.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Retrieve Weight From Mettler Toledo Scale via RS232

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 10 October 2012 - 06:38 AM

You say "COM1" in your text, but "COM5" in the code. Are you looking at the right port?

Is the scale autobaud?

There are a number of serial port settings that the scale might be using. If it's on the right port, it sounds a lot like a wrong setting for parity, number of data bits, stop bits, or even baud rate.

Can you tell us the model number of the scale?
Was This Post Helpful? 0
  • +
  • -

#3 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 10 October 2012 - 06:59 AM

In the mettler, there are two ports available for me to connect
1. COM1 > this is the only vacant port
2. COM2 > this is the port for the printer.

I have connected to the COM1 using RS232 to USB Connector. When I call the port name, "COM5" is showing. The connection is ok. It connects to the port but when it fires data, it returns unknown characters like ???{[]m??

No, the scale is not autobaud. The model of the scale is Mettler Toledo IND310. Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 10 October 2012 - 07:05 AM

Here, I attached the image of the setting of the port that I connected to.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 10 October 2012 - 07:20 AM

I'm sorry I posted the wrong image. That image is the setting of the COM2 Port.
The config of the COM1 Port is this:

Baud Rate: 9600
Parity: Even
Data Bits: 8
Stop Bits: One
Was This Post Helpful? 0
  • +
  • -

#6 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 10 October 2012 - 07:21 AM

I couldn't find much on the net about the serial protocol for the IND310. If it was my program, and if I didn't have the specs for the serial port, I'd try changing all the port settings one at a time, watching the serial port with a terminal program.

There is one other thing. Not all serial->USB adapters are good. The lower-cost ones often use TTL levels instead of proper RS232 levels on the serial port side. This can result in sporadic databit loss, or even comlete loss of communication. Whether or not a TTL-level adapter works is entirely dependent on the device attached to the serial port side of the adapter.
Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 10 October 2012 - 07:45 AM

Mettler Toledo IND310 Technical Manual

It's a pdf in case you don't already have it.

Sorry, that's all the help I can give, It's been too long since I worked with scales and a whole other job altogether :(
Was This Post Helpful? 0
  • +
  • -

#8 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 15 October 2012 - 05:12 AM

Hi ! I recently updated my program, and this is what i am getting (see attachment)
weight on the scale is 830 kg.
Attached Image
Was This Post Helpful? 0
  • +
  • -

#9 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 15 October 2012 - 05:32 AM

Here are other details:

Attached Image
Attached Image


Code of PROGRAM:

Imports PCComm
Public Class frmMain
    Private comm As New CommManager()
    Private transType As String = String.Empty

    Private Sub cboPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPort.SelectedIndexChanged
        comm.PortName = cboPort.Text()
    End Sub

    ''' <summary>
    ''' Method to initialize serial port
    ''' values to standard defaults
    ''' </summary>
    Private Sub SetDefaults()
        cboPort.SelectedIndex = 0
        cboBaud.SelectedText = "9600"
        cboParity.SelectedIndex = 0
        cboStop.SelectedIndex = 1
        cboData.SelectedIndex = 1
    End Sub

    ''' <summary>
    ''' methos to load our serial
    ''' port option values
    ''' </summary>
    Private Sub LoadValues()
        comm.SetPortNameValues(cboPort)
        comm.SetParityValues(cboParity)
        comm.SetStopBitValues(cboStop)
    End Sub

    ''' <summary>
    ''' method to set the state of controls
    ''' when the form first loads
    ''' </summary>
    Private Sub SetControlState()
        rdoText.Checked = True
        cmdSend.Enabled = False
        cmdClose.Enabled = False
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadValues()
        SetDefaults()
        SetControlState()
    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        comm.ClosePort()
        SetControlState()
        SetDefaults()
    End Sub

    Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
        comm.Parity = cboParity.Text
        comm.StopBits = cboStop.Text
        comm.DataBits = cboData.Text
        comm.BaudRate = cboBaud.Text
        comm.DisplayWindow = rtbDisplay
        comm.OpenPort()

        cmdOpen.Enabled = False
        cmdClose.Enabled = True
        cmdSend.Enabled = True
    End Sub

    Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
        comm.Message = txtSend.Text
        comm.Type = CommManager.MessageType.Normal
        comm.WriteData(txtSend.Text)
        txtSend.Text = String.Empty
        txtSend.Focus()
    End Sub

    Private Sub rdoHex_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoHex.CheckedChanged
        If rdoHex.Checked() Then
            comm.CurrentTransmissionType = PCComm.CommManager.TransmissionType.Hex
        Else
            comm.CurrentTransmissionType = PCComm.CommManager.TransmissionType.Text
        End If
    End Sub

    Private Sub cboBaud_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBaud.SelectedIndexChanged
        comm.BaudRate = cboBaud.Text()
    End Sub

    Private Sub cboParity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboParity.SelectedIndexChanged
        comm.Parity = cboParity.Text()
    End Sub

    Private Sub cboStop_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboStop.SelectedIndexChanged
        comm.StopBits = cboStop.Text()
    End Sub

    Private Sub cboData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboData.SelectedIndexChanged
        comm.StopBits = cboStop.Text()
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#10 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 15 October 2012 - 05:46 AM

View PostCharlieMay, on 10 October 2012 - 07:45 AM, said:

Mettler Toledo IND310 Technical Manual

It's a pdf in case you don't already have it.

Sorry, that's all the help I can give, It's been too long since I worked with scales and a whole other job altogether :(


Yes I have this manual, thanks anyway! :)
Was This Post Helpful? 0
  • +
  • -

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 15 October 2012 - 06:44 AM

What command are you sending to the scale?
Was This Post Helpful? 0
  • +
  • -

#12 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 15 October 2012 - 12:43 PM

I haven't checked it yet, but there is a tutorial on this site;
Serial Port Communications in VB.Net

Might be worth looking at, if you haven't already. I'll peek in later today to see if that helped.
Was This Post Helpful? 0
  • +
  • -

#13 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 15 October 2012 - 09:54 PM

View PostCharlieMay, on 15 October 2012 - 06:44 AM, said:

What command are you sending to the scale?



Actually, I've been trying the S<CR><LF> Command but it doesn't work, and I don't know any other commands to send. Do you know any?

View Postlar3ry, on 15 October 2012 - 12:43 PM, said:

I haven't checked it yet, but there is a tutorial on this site;
Serial Port Communications in VB.Net

Might be worth looking at, if you haven't already. I'll peek in later today to see if that helped.




Actually, that is the code that I used in my latest post (with the screen capture from the program, but still the same problem :(
Was This Post Helpful? 0
  • +
  • -

#14 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 15 October 2012 - 10:15 PM

I thought that code looked familiar!
I haven't been able to get it running at all.

What version of VB.Net/Visual Studio are you running?
Was This Post Helpful? 0
  • +
  • -

#15 mikyerii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Retrieve Weight From Mettler Toledo Scale via RS232

Posted 15 October 2012 - 10:20 PM

Yes, I downloaded the attachment and tested it right away into my scale. I'm using Visual Studio 2010 by the way..
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2