Unreadable data returned from Weighscale over Serial connection

captsx1
captsx1 used Ask the Experts™
on
Hi Experts,

As part of a projet I am working on, I have to query a weighscale to return the weigh of an object into my VB.NET (.NET 2.0) application. All my cabeling is correct, as when I use HyperTerminal i get human readable data display as a return. However, when I use my application, which uses io.Ports.SerialPorts i get the same number of characters back, how ever only a couple of them are readable. (please see the attached file as an example).

The scale, rather scale head is Mettler-Toleda Panther.
I have tried setting the ports encodeing to different types (ASCII, UTF-8, UTF-32) and while it changes the number of characters returned, it didn't change the readability.

I did note for one of the settings of HyperTerminal, the Terminal ID was ANSI, and when i changed it to VT100, I did get a couple of non-readable returned characters, however, i have no idea how to ensure my app is using the ANSI Termial type.

Thanks in advance for your assistance.

Steve


Panther.docx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
I believe because you are reading binary data from the serial connection, you are trying to insert NPCs into the text box. Because the text box does not recognize such non-printable characters as valid text, "random" characters appear.
Most Valuable Expert 2012
Top Expert 2014

Commented:

Author

Commented:
CodeCruiser;
I am using the ReadExising method in my Code (See snipped)

Kaufmed;
I'm not sure if this is the case, as I know that in my return data I get at least one correct charcter in the right place. However, i'm new to this, so i'm not ruling it out. How can i check to make sure that this is/sin't the case. and how do i format the binary data to be human readable.

Thanks
Steve
Public Sub updateTextBox()
        With txtDataReceived
            .AppendText(serialPort.ReadExisting)
            .ScrollToCaret()
        End With
    End Sub

Open in new window

JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Author

Commented:
I added the function (in the snippet below) into my code in order to convert the binary data before putting it in the text box. even after doing so, the results are still the same.

Any more ideas? Was my binary convertor correct? (i found it doing a google search)

Thanks
Steve
 Function SimpleBinaryToString(ByVal Binary) As String
        'SimpleBinaryToString converts binary data (VT_UI1 | VT_ARRAY Or MultiByte string)
        'to a string (BSTR) using MultiByte VBS functions
        Dim I As Integer
        Dim S As String
        S = ""
        For I = 1 To Len(Binary)
            S = S & Chr(Asc(Mid(Binary, I, 1)))
        Next
        SimpleBinaryToString = S
    End Function

Open in new window

Most Valuable Expert 2012
Top Expert 2014

Commented:
What format is the data sent in by the scale? Do you have access to the documentation for the scale? Are you sure its returned in Binary?
Commented:
Thanks for all your input. I figured it out. I was sat there jiust staring at HyperTerminal. Then at the bottom of the screen i noticed 9600-7-E-1, which i thought was weird as I made the settings as 9600-8-N-1. Sure enough, as soon as I updated my application to these new port settings then it began working and returning readable data.

I guess it ays to remember something maybe working correctly, but not in the manner you think it is. :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial