digital scale/ indicator in vb
digital scale/ indicator in vb
digital scale/ indicator in vb
digital scale/ indicator in vb
digital scale/ indicator in vb
digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb
digital scale/ indicator in vb digital scale/ indicator in vb
digital scale/ indicator in vb
Go Back  Xtreme Visual Basic Talk > > > digital scale/ indicator in vb


Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2011, 12:16 AM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Question digital scale/ indicator in vb


hi, im new in vb programming especially when come to getting connection through serial port.

my final year project title is monitoring weight changes in digital scale / indicator.
i bought one digital scale online from A&D in order to test out my system.

however unlikely other device (GSM MODEM, RFID...) there are no drivers or libraries (DLL) from this device.. with only the digital scale and (rs232 9-pins to usb convertor i bought) i was like lost wondering how to get communicate with the device.

i have been search around in the internet for similar post.. but there are most likely dealing with the data receiving already. is there any journals or manuals for references? i willing to study over this and not simply ask for full codings.

- how to communicate with the device (serial port communication)
- is there any driver / libraries need to install bfore everything?

OS using - windows 7 ultimate (laptop)
model of device - A&D JM-SERIES 150lb

hope experts in here can give me some guidance and references to study.
many thanks in advance.

Last edited by vdex; 04-03-2011 at 12:18 AM. Reason: spelling errors
Reply With Quote
  #2  
Old 04-03-2011, 02:13 AM
PlausiblyDamp's Avatar
PlausiblyDampdigital scale/ indicator in vb PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Looking at the manual on http://www.andscales.discountscales....ingscales.htm# it would appear there is no driver - it just uses a serial connection to the PC.

The Serial Port Class is probably the best starting point under .Net
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 04-03-2011, 03:44 AM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

wow.. thx thx.. i will read thru the manuals right away.
Reply With Quote
  #4  
Old 04-04-2011, 08:30 PM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

Using visual studio 2010 (visual basic)

Imports System
Imports System.IO.Ports
Imports System.Threading

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.SerialPort1.Close()
Me.SerialPort1.PortName = "COM4"
Me.SerialPort1.BaudRate = 9600
Me.SerialPort1.Parity = IO.Ports.Parity.None
Me.SerialPort1.DataBits = 7
Me.SerialPort1.StopBits = IO.Ports.StopBits.One
Me.SerialPort1.Open()

Dim trial As String
trial = Me.SerialPort1.ReadLine
Me.lbltrial.Text = trial


End Sub

still there are nothing come out.. did i miss out something?
Reply With Quote
  #5  
Old 04-05-2011, 03:15 AM
PlausiblyDamp's Avatar
PlausiblyDampdigital scale/ indicator in vb PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

According to the link above it looks like parity should be set to odd, other than than I haven't got any other real ideas....

Are you getting anything from the device at all or is there no data coming from it? Is everything connected up with the correct cable types?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #6  
Old 04-05-2011, 03:31 AM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

i will try the "odd" in parity tomorrow morning as the device is kept in the laboratory for security purpose.

as for the data - there are nothing at all shown in the label (empty in the label)
i thought it might cause of i failed to specify parameters in <Me.SerialPort1.ReadLine()>

as the cable i had used USB TO RS232 Serial 9Pin Converter - VZ-UC1052(from vztec.com - Prolific) i guess its a correct cable in communicate with rs232 port.
Reply With Quote
  #7  
Old 04-05-2011, 03:37 AM
PlausiblyDamp's Avatar
PlausiblyDampdigital scale/ indicator in vb PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Does the device return data as a string? If not you will probably find that ReadLine isn't going to be much use as it is based on the idea of string input. You may need to use .ReadByte directly or even consider the DataReceived event as an alternate way of getting data from the device.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #8  
Old 04-05-2011, 03:40 AM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

yes sir. took note.
parity -> odd
readbyte
if still cant try out datareceived event

thank you so much for the guide. will try out tomorrow. will update again tomorrow for the progress.
Reply With Quote
  #9  
Old 04-05-2011, 08:52 PM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

it seems to be readbyte doesnt result anything as well
so i tried out the datareceived event..
but i don`t quite understand how the addressof functions
i add on the textbox to test out if the connection of serial port really doest open or not..

Imports System
Imports System.IO.Ports
Imports System.Threading

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.SerialPort1.Close()
Me.SerialPort1.PortName = "COM4"
Me.SerialPort1.BaudRate = 9600
Me.SerialPort1.Parity = IO.Ports.Parity.Odd
Me.SerialPort1.DataBits = 7
Me.SerialPort1.StopBits = IO.Ports.StopBits.One
AddHandler Me.SerialPort1.DataReceived, AddressOf DataReceviedHandler
Me.SerialPort1.Open()

If Me.SerialPort1.IsOpen Then
Me.TextBox1.Text = "yes"
Else
Me.TextBox1.Text = "no"
End If

Me.lbltrial.Text = Console.Read()
Me.SerialPort1.Close()
End Sub
Private Shared Sub DataReceviedHandler(
ByVal sender As Object,
ByVal e As SerialDataReceivedEventArgs)
Dim sp As SerialPort = CType(sender, SerialPort)
Dim indata As String = sp.ReadExisting()
Console.WriteLine("Data Received:")
Console.Write(indata)
End Sub

End Class


the result is -1
i dont think its from the weight, which parameter to be adjust in order to get this right?
Reply With Quote
  #10  
Old 04-06-2011, 05:27 AM
PlausiblyDamp's Avatar
PlausiblyDampdigital scale/ indicator in vb PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The code you are using is getting a couple of things wrong the first bit
Code:
Me.SerialPort1.Close()
Me.SerialPort1.PortName = "COM4"
Me.SerialPort1.BaudRate = 9600
Me.SerialPort1.Parity = IO.Ports.Parity.Odd
Me.SerialPort1.DataBits = 7
Me.SerialPort1.StopBits = IO.Ports.StopBits.One
AddHandler Me.SerialPort1.DataReceived, AddressOf DataReceviedHandler
Me.SerialPort1.Open()
Is opening the serial port and registering an event handler - this event will be called when data is received from the serial port. This bit looks ok.

The next bit of code
Code:
If Me.SerialPort1.IsOpen Then
Me.TextBox1.Text = "yes"
Else
Me.TextBox1.Text = "no"
End If

Me.lbltrial.Text = Console.Read()
Me.SerialPort1.Close()
is checking if the port opened ok and then reads from it regardless of the fact data may not be there and then closes the port, effectively stopping any more data being received.

If you are using the event you should open the port and then leave it open, when data arrives the event handler will be called by the framework to notify you there is something for you to do.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #11  
Old 04-06-2011, 10:41 PM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

i understood that the close of my serial connection stop the data from being received. so i removed the "Me.SerialPort1.Close()"

however, there are still no any data in the label except the -1

is there anything i need to enable, add services, or add references before these codes?

or there are any parameters to be set for returning values from my weighting scale?
Reply With Quote
  #12  
Old 04-07-2011, 02:35 AM
PlausiblyDamp's Avatar
PlausiblyDampdigital scale/ indicator in vb PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If you put a breakpoint on the line
Code:
Private Shared Sub DataReceviedHandler(ByVal sender As Object, ByVal e As  SerialDataReceivedEventArgs)
does the break point ever get hit?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #13  
Old 04-07-2011, 05:30 AM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

im sorry, my bad din put updated full codes and caused confuses.
here are the full codes..

Imports System
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Public Event DataReceived As SerialDataReceivedEventHandler
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.SerialPort1.Close()

Me.SerialPort1.PortName = "COM4"
Me.SerialPort1.BaudRate = 9600
Me.SerialPort1.Parity = IO.Ports.Parity.Odd
Me.SerialPort1.DataBits = 7
Me.SerialPort1.StopBits = IO.Ports.StopBits.One
AddHandler Me.SerialPort1.DataReceived, AddressOf DataReceviedHandler
Me.SerialPort1.Open()

lbltrial.Text = Console.Read()
End Sub

Private Shared Sub DataReceviedHandler(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
Dim sp As SerialPort = CType(sender, SerialPort)
Dim indata As String = sp.ReadExisting()
Console.WriteLine("Data Received:")
Console.Write(indata)
End Sub

End Class

and yet it doesn`t anything except the "-1". that`s why i thought it might be any other configuration or setting i missed out (out of codes, such as adding references or services into the "project" )
Reply With Quote
  #14  
Old 04-07-2011, 05:44 AM
PlausiblyDamp's Avatar
PlausiblyDampdigital scale/ indicator in vb PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

I don't think you need the line
Code:
Public Event DataReceived As SerialDataReceivedEventHandler
at the top as your form isn't raising any events itself, merely responding to events raised by other components so it can probably be removed.

If you put a breakpoint on the line
Code:
Private Shared Sub DataReceviedHandler(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
does the breakpoint trigger when you run the application? If so what is the value of e.EventType within the event handler?

If you check the BytesToRead property of the serial port within this event handler does it show any bytes to be read?

Are you sure the data is being sent as a string? If not you can't rely on
Code:
Dim indata As String = sp.ReadExisting()
to actually make any sense as the data isn't going to be in a string format - you might need to look at using either the ReadByte or Read methods to get at the data and then interpret the results yourself.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #15  
Old 04-07-2011, 08:51 AM
AtmaWeapon's Avatar
AtmaWeapondigital scale/ indicator in vb AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Maybe I'm missing something, but the manuals for that scale don't have any details about the communications protocol the scale uses. The only information you get is, "If you're using UPS WorldShip software, configure it this way..." and that the scale transmits data in "a popular data format". That's not very helpful.

Even if the scale is transmitting data right now, having no protocol information means you have to gather a lot of data and try to reverse-engineer what the readings mean. It may be something simple like a Double. It may be something with a convention like "132 means 13.2 pounds". It may be some relative scale, like "16 bit integer where 0 means 0 pounds and 65,535 means 150 lbs, all values in between represent intermediate values."

That aside, the scale may not always transmit the serial data. Maybe instead of constantly publishing its reading, it waits for you to send some data and responds with a reading. Or maybe it requires a little bit of handshaking before it starts sending. Without documentation, you don't know.

You should call the vendor and ask for more information. It's possible PlausiblyDamp has some information I don't see, but if that's not the case I think we're fumbling around in the dark and it's just as likely you'll stumble upon the answer as it is you'll never find it. In fact, calling the vendor should usually be the *first* step you take; there's hundreds of scales out there and the odds you'll find someone using your exact model are slim. The people with the most knowledge are the people selling the scale. It's possible this scale has no protocol documentation because it's only intended to be used with UPS software; only the vendor can answer that question.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #16  
Old 04-07-2011, 10:27 AM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default reply

>>PlausiblyDamp
had ady tried out :
Read() - Overload resolution failed because no accessible 'Read' accepts this number of arguments
ReadByte() - nothing at all (empty label)
Readexisting() - (-1)

the BytesToRead properties is it the (MaxValue and MinValue)?

>>AtmaWeapon
oh my godness.. it does make sense when u point this out. and it is true that the manual does not provide any detail except the "baudrate, databit...."
i should really ask the vendor, however this device i bought online from foreign country. i wondering how effective they will deal with the emails.
thank very much.
Attached Images
File Type: png bytestoread.png (8.7 KB, 8 views)

Last edited by vdex; 04-07-2011 at 10:34 AM. Reason: add picture
Reply With Quote
  #17  
Old 04-07-2011, 12:52 PM
PlausiblyDamp's Avatar
PlausiblyDampdigital scale/ indicator in vb PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The BytesToRead property is just an integer - it tells you how many bytes there are waiting to be read.

If the event handler is never being reached then it looks as though it isn't a simple one way communication and as Atma suggested you will probably need a more detailed bit of documentation on the underlying protocol.

I was trying to see if the event ever actually fired as this would at least indicate some data was being received - putting a breakpoint on the line would have at least allowed you to see it was being reached and also given you the chance to inspect the serialport's state / the arguments passed in to the event handler.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #18  
Old 04-12-2011, 05:39 AM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

hi, im back again after 2 tests over..
alright back to the codes again..

i had tried contact the A&D but no reply until now..
i guess they are just never reachable whenever the topic is not in business.

Imports System
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.SerialPort1.Close()
Me.SerialPort1.PortName = "COM4"
Me.SerialPort1.BaudRate = 9600
Me.SerialPort1.Parity = IO.Ports.Parity.Odd
Me.SerialPort1.DataBits = 7
Me.SerialPort1.StopBits = IO.Ports.StopBits.One
AddHandler Me.SerialPort1.DataReceived, AddressOf DataReceviedHandler
Me.SerialPort1.Open()

lbltrial.Text = Me.SerialPort1.BytesToRead



End Sub

Private Shared Sub DataReceviedHandler(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
Dim sp As SerialPort = CType(sender, SerialPort)
Dim indata As ULong = sp.ReadExisting()
Console.WriteLine("Data Received:")
Console.Write(indata)
End Sub

End Class

the result for bytestoread is 0
is it means there are nothing i can ever retrieve?
Reply With Quote
  #19  
Old 04-12-2011, 05:42 AM
vdex vdex is offline
Newcomer
 
Join Date: Apr 2011
Posts: 19
Default

anything else i could try?
SDK perhaps?
Reply With Quote
  #20  
Old 04-12-2011, 05:45 AM
PlausiblyDamp's Avatar
PlausiblyDampdigital scale/ indicator in vb PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The line
Code:
lbltrial.Text = Me.SerialPort1.BytesToRead
is happening straight after the port has been opened and isn't going to be of much use. If any data is received it would be in the event handler, this is why I have been asking you to put a breakpoint on the event handler to see if the event is ever being raised.

It is highly likely that the device will only transmit information in response to a request, unless you know what it is expecting from your software then this is likely to be a major problem in getting the device to work.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
digital scale/ indicator in vb
digital scale/ indicator in vb
digital scale/ indicator in vb digital scale/ indicator in vb
digital scale/ indicator in vb
digital scale/ indicator in vb
digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb digital scale/ indicator in vb
digital scale/ indicator in vb
digital scale/ indicator in vb
 
digital scale/ indicator in vb
digital scale/ indicator in vb
 
-->