分享

How to read weight from scale using ethernet connection

 quasiceo 2016-09-26

Hi this is my first post so please bare with me.

I have a Mettler Toledo XS32000L scale and I am simply trying to read the weight via an Ethernet connection and a VB.net (2010) application. I have found plenty of information/code for a serial(COM) connection but nothing for an Ethernet connection.

Communication mode: Client & Server Remote Host Address: 192.168.0.2. Remote Host Port Number: 8001 Local server Port Number: 8000 (Scale IP: 192.168.0.1)

I am able to ping the scale with a reply. I have tried using a HyperTerminal but with no luck. Any help would be greatly appreciated, and hopefully this post can help many others to come. Thanks!

Other Resources

Code for a VB application with a SERIAL connection: http:///thread/1240210560

Another helpful link(but not for me): http://vb./communications/vb.net_socket_programming.htm

asked Jul 8 '15 at 19:49
Dallas
397

closed as too broad by KevinDTimm, Alex P., OIS, rene, gunr2171 Jul 20 '15 at 19:32

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

    
This is probably going to be closed FYI. While it's an interesting question, this site is focused on broken code; not general guides. – Carcigenicate Jul 8 '15 at 19:51
    
As @Carcigenicate said, please review the help page for how SO works. – KevinDTimm Jul 8 '15 at 19:52
    
I appreciate the advice - however what I would really like is some code to figure out how to do this in VB.net, so although I do not have any source code to share, I would appreciate any help on what code to write – Dallas Jul 8 '15 at 20:03

Alright - despite the criticism, I am going to post the solution after hours of researching. I created a TCP client and the modified the settings (IP, port, etc.) Hopefully this helps some future programmers!

Imports System.Net.Sockets

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Call Connect("192.168.0.1", "S" & vbCrLf)
End Sub

Shared Sub Connect(ByVal server As [String], ByVal message As [String])
    Try
        ' Create a TcpClient. 
        ' Note, for this client to work you need to have a TcpServer  
        ' connected to the same address as specified by the server, port 
        ' combination. 
        Dim port As Int32 = 8000
        Dim client As New TcpClient(server, port)

        ' Translate the passed message into ASCII and store it as a Byte array. 
        Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)

        ' Get a client stream for reading and writing. 
        '  Stream stream = client.GetStream(); 
        Dim stream As NetworkStream = client.GetStream()

        ' Send the message to the connected TcpServer. 
        stream.Write(data, 0, data.Length)

        'Console.WriteLine("Sent: {0}", message)
        MsgBox("Sent: {0} " & message)
        ' Receive the TcpServer.response. 
        ' Buffer to store the response bytes.
        data = New [Byte](256) {}

        ' String to store the response ASCII representation. 
        Dim responseData As [String] = [String].Empty

        ' Read the first batch of the TcpServer response bytes. 
        Dim bytes As Int32 = stream.Read(data, 0, data.Length)
        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
        'Console.WriteLine("Received: {0}", responseData)
        MsgBox("Received: {0} " & responseData)

        ' Close everything.
        stream.Close()
        client.Close()
    Catch e As ArgumentNullException
        'Console.WriteLine("ArgumentNullException: {0}", e)
        MsgBox("ArgumentNullException: {0}" & e.Message)
    Catch e As SocketException
        'Console.WriteLine("SocketException: {0}", e)
        MsgBox("SocketException: {0}" & e.Message)
    End Try

    MsgBox("Got to this point in code")

    'Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
    'Console.Read()
End Sub 'Connect

End Class
answered Jul 9 '15 at 20:50
Dallas
397

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多