10 Replies - 2181 Views - Last Post: 24 February 2015 - 06:52 AM Rate Topic: ****- 2 Votes

#1 Hyadain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-February 15

Need help about Weighing Software using RS232 in VB.Net

Posted 22 February 2015 - 01:50 AM

Good Day to everyone! :)/>/>


I was developing a digital weighing scale for the additional features for our thesis. Now i am having a problem in my program, the serial port was working just fine but i receive many data from it. I am using an RS232 Weighing Sensor by e-Gizmo. Documentation about the hardware is here: https://docs.google....VBRRWN0WVU/edit

Here's the actual hardware that i have:
http://i.imgur.com/4co1dVT.jpg
http://i.imgur.com/gG7uYFO.jpg


In my simple program (just to see what my device is sending me) im having this output:
http://i.imgur.com/Bnxv17j.png?1

I also want to remove the "ES" on the end of the number given by my device if possible.

I just want the label consistently change when i recieve data from my device like on this video:
https://www.youtube....h?v=W-d1TvMlBUs




Now Here's my code:
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Dim incomingByte As String = ""
Dim sec As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With SerialPort1 'Connection for my serial port
.Close()
.PortName = "COM3"
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.DtrEnable = True
.RtsEnable = True
.ReceivedBytesThreshold = 1
End With
SerialPort1.Open()
Label1.Text = SerialPort1.ReadExisting() 'read data from device

Timer1.Interval = 1000
Timer1.Enabled = True
sec = 0

End Sub

Private Sub readport()
Label1.Text = SerialPort1.ReadExisting() 'declaration for calling data in timer tick
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Call readport()
sec = sec + 1
Label2.Text = sec
End Sub
End Class





I am using Visual Basic 2013 for my program.
I hope someone can help me, im so desperate to finish this program. :(/>/>
Thanks in Advance~!


Is This A Good Question/Topic? 0
  • +

Replies To: Need help about Weighing Software using RS232 in VB.Net

#2 Hyadain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-February 15

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 22 February 2015 - 08:00 AM

Please Help :(
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 22 February 2015 - 10:35 AM

You might download this and check it out. It appears from the file extensions to be an old VisualBasic program. I haven't looked at the source but I'm sure if this helps, it wouldn't take much to convert it. Also seems to be some documentation in there.
Was This Post Helpful? 1
  • +
  • -

#4 Hyadain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-February 15

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 22 February 2015 - 08:47 PM

ok i will try to upgrade it and see if it will work. thanks
Was This Post Helpful? 0
  • +
  • -

#5 Hyadain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-February 15

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 22 February 2015 - 10:52 PM

Hello! i've downloaded vb6 to test the code..

this is what i get:

Posted Image


now here's the code:

Private Sub Form_Load()
    MSComm1.CommPort = 3
    MSComm1.PortOpen = True
End Sub

Private Sub MSComm1_OnComm()
    On Error GoTo Error
    x = x + MSComm1.Input
    If Right$(x, 1) = "E" Then
        Text1.Text = x
        x = ""
    End If
    Exit Sub
    
Error:
End Sub


Was This Post Helpful? 0
  • +
  • -

#6 Hyadain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-February 15

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 23 February 2015 - 08:39 AM

i haven't solve this yet..please help :(
our due date will come soon T.T
Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 23 February 2015 - 10:00 AM

In your first post, do you know what that number coming in represents? Does it correlate to the weight you're placing on the scale? There's really not a lot of info to base anything on other than giving a bunch of links for us to research.

There are numerous string functions that can be used to remove ES. The first one that comes to mind is String.Replace

dim s as string = "This is a string"
s = s.replace("This", "Here")
msgbox(s)


Notice how I just took "This is a string" and made it print out "Here is a string"

You can also replace characters and strings with a blank string. Using this method, it should become pretty apparent how you can take the string coming in and remove ES from it.

Have you tried emailing support for the item in question? I don't really see a lot of example code other than using the tool and language that they link to in that video.
Was This Post Helpful? 1
  • +
  • -

#8 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,810
  • Joined: 01-February 13

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 23 February 2015 - 11:17 AM

I looked through the links and searched about using the e-Gizmo yesterday and i, could not find anything useful on how the data is sent from it to the computer.

I would contact the company and ask for some help or at least some technical data on this, not just pictures and how to use it but, the actual serial data format that is sent from it to the computer.

If it sends the data automatically or weather you need to send a certain byte or set of bytes to it to get the new data sent back to the computer would be nice to know.

Also, if you look into the SerialPort Class, it has a DataReceived event that can be used to notify your app that it has received data so you know when to read new data.

It also has a DiscardInBuffer method that may need to be used to clear the buffer after each set of data is received, i don`t know i have never used the SerialPort class in VB.Net but, i did with other programming languages years ago.

This post has been edited by IronRazer: 23 February 2015 - 11:20 AM

Was This Post Helpful? 1
  • +
  • -

#9 Hyadain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-February 15

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 24 February 2015 - 03:21 AM

View PostCharlieMay, on 23 February 2015 - 10:00 AM, said:

In your first post, do you know what that number coming in represents? Does it correlate to the weight you're placing on the scale? There's really not a lot of info to base anything on other than giving a bunch of links for us to research.

There are numerous string functions that can be used to remove ES. The first one that comes to mind is String.Replace

dim s as string = "This is a string"
s = s.replace("This", "Here")
msgbox(s)


Notice how I just took "This is a string" and made it print out "Here is a string"

You can also replace characters and strings with a blank string. Using this method, it should become pretty apparent how you can take the string coming in and remove ES from it.

Have you tried emailing support for the item in question? I don't really see a lot of example code other than using the tool and language that they link to in that video.




On my first post, the weight is correct. It was "0269". i tried reading my port in Hex. it reads "20 30 30 30 30 45 53" on ASCII it was " 0000ES". the "20" in hex indicates the weight is possitive, if it is negative it reads as "2D".

here's my screenshot: Posted Image

But the weighing sensor sends me data continuously. The only way to stop it is to disconnect from the port in the program.


View PostIronRazer, on 23 February 2015 - 11:17 AM, said:

I looked through the links and searched about using the e-Gizmo yesterday and i, could not find anything useful on how the data is sent from it to the computer.

I would contact the company and ask for some help or at least some technical data on this, not just pictures and how to use it but, the actual serial data format that is sent from it to the computer.

If it sends the data automatically or weather you need to send a certain byte or set of bytes to it to get the new data sent back to the computer would be nice to know.

Also, if you look into the SerialPort Class, it has a DataReceived event that can be used to notify your app that it has received data so you know when to read new data.

It also has a DiscardInBuffer method that may need to be used to clear the buffer after each set of data is received, i don`t know i have never used the SerialPort class in VB.Net but, i did with other programming languages years ago.


Thank you for the response. I hope you can help me.
It is my second time programming a serial port connection, last time is just a simple led lighting. I really dont have any idea what to do to those data i receive.
Was This Post Helpful? 0
  • +
  • -

#10 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,810
  • Joined: 01-February 13

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 24 February 2015 - 05:15 AM

Hi,

Well, as i said i never used the SerialPort class in VB.Net so there might be a better way using the DataReceived event but, you can try it using the setup you have with the timer and use some of the String Class Methods as CharlieMay has already mentioned.

If your received numbers are always the same length like
" 0296ES" or "-0053ES" then it is pretty simple to use the LastIndexOf and the Substring methods to get the numbers you want.

It would probably be a good idea to wrap the Reading and Parsing code in a Try Catch block to catch any errors and handle them too. You can try it like this and see what happens.
Imports System.IO.Ports

Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        With SerialPort1 'Connection for my serial port
            .Close()
            .PortName = "COM3"
            .BaudRate = 9600
            .Parity = Parity.None
            .DataBits = 8
            .StopBits = StopBits.One
            .DtrEnable = True
            .RtsEnable = True
            .ReceivedBytesThreshold = 1
        End With
        SerialPort1.Open()
        Timer1.Interval = 1000
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
        ReadData()
    End Sub

    Private Sub ReadData()
        Try
            Dim strRead As String = SerialPort1.ReadExisting

            Dim i As Integer = strRead.LastIndexOf("ES") 'find the index of the last "ES" in the string

            'if i is -1 then "ES" was not found in the string
            If i > -1 Then
                strRead = strRead.Substring(i - 5, 5) 'get the substring of the leading space or leading "-" and the 4 numbers after it
                Label1.Text = strRead 'set the text to the parsed string
            End If
        Catch ex As Exception
            Timer1.Stop() 'stop the timer and alert the user of an error
            MessageBox.Show("Error Reading and Parsing Received Data")
        End Try
    End Sub
End Class


This post has been edited by IronRazer: 24 February 2015 - 06:30 AM

Was This Post Helpful? 1
  • +
  • -

#11 Hyadain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-February 15

Re: Need help about Weighing Software using RS232 in VB.Net

Posted 24 February 2015 - 06:52 AM

Thank you so much IronRazer!
the code that you give to me works!

Also i wanna thank CharlieMay for responding and helping :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1