Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day 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.com/file/d/0BxdLxDCD6HidMEs4ZVBRRWN0WVU/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.com/watch?v=W-d1TvMlBUs


Now Here's my Code

VB
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~!
Posted
Comments
Hyadain 23-Feb-15 10:48am    
Haven't solve this yet, Please help me :(
our due date will be soon. :(

Using timer migth not be the best approach. Use listener approach[^] instead. Be aware of the buffer and the flow control used by the link. So you might need to treat incomming data as chunk, and use an internak buffer. ES and the space will be probably the terminator you will need to look for in this buffer. Removing it is simple text processing.
Putting this in a windows forms application is just straightforward.
 
Share this answer
 
Comments
Hyadain 22-Feb-15 7:32am    
here's what i get from that: http://i.imgur.com/WRF3scz.png

still dont know what to do, it is just my second time coding for serial port. Last time is just a simple led lighting.
Zoltán Zörgő 22-Feb-15 13:24pm    
Well, no problem, use internal buffer, and gather all those bytes you get. If your buffer ends with "ES ", strip the terminator, and convert the rest to number. Empty the buffer go ahead.
Hyadain 23-Feb-15 0:33am    
Hello! can you give me example codes about it? im not sure that i am doing it right.
Zoltán Zörgő 23-Feb-15 12:25pm    
Show me your code.
Hyadain 23-Feb-15 20:56pm    
Dim buffer As Byte()
Dim offset As Integer = 0
Dim count As Integer = SerialPort1.BytesToRead
Dim Value As Integer = SerialPort1.Read(buffer, offset, count) 'Got Problem here. said variable buffer is used before it is assigned a value
For Each B As Byte In buffer
Q.Enqueue(B)
Next

While Q.Count > 0
Label1.Text &= Hex(Q.Dequeue) & " "
End While
Here's the code that makes my program works~!

VB
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 wanna thank those people who help me!

discussion about this problem can view here: http://www.dreamincode.net/forums/topic/370788-need-help-about-weighing-software-using-rs232-in-vbnet/[^]
 
Share this answer
 

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