Click here to Skip to main content
15,881,623 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i just want to connect weight scale into my vb.net application! i don't know how to do ! i am beginner to this problem! thanks in advance!

What I have tried:

VB
import system.io

public class form1

dim comports as array

private sub form1_load
comports=io.ports.serialport.getportnames
serialport.portname="com3"
serialport.bauderate=9600
serialport.parity=io.ports.parity.none
// <<= from where com serialport1 ?
serialport1.stopbits=io.ports.stopbits.one
serialport1.databits=8
// <<= from where comes serial1 ?
if serialport1.isopen=false
serial1.portname="com3"
end if 
// <<= missing end Sub here 

private sub serialport1_datareceived(byvalsender as object, byval e as system.io.ports.serialdatareceivedEventArgs)
if serialport1.isopen=true then
Read()
end if 
end sub

private sub Read()
if serialport1.isopen then
Dim Data as string=serialport1.readexisting()
frist_w.text=data
end if 
end sub

// <<= missing End Class here
<pre>
Posted
Updated 8-Jan-21 23:04pm
v2
Comments
Richard Deeming 8-Jan-21 10:51am    
Read the documentation that came with your device.
Ralf Meier 9-Jan-21 5:00am    
My question to this code : does anything happen when you start it ? I suppose that nothing really happens - some parts of the code are really senseless for me. And by the way : have youn ever heard something about formatting ...?
See also my comments inside your provided code ...
Henry Z. 9-Jan-21 14:14pm    
Ralf, you really need to try to understand the code instead of just copying it from the internet. The code you posted is very poor, for example serialport, serialport1 and serial1 are all mentioned in your code which is implying three different serial ports. Your code as it stands here will do nothing since the code never mentions .open for serialport1 which is in your serialport1_datareceived event and the serialport1_datareceived will never be ran because you never assign the datareceived event to the sub routine... My suggestion to you is to open up hyperterminal and see if your scale is configured correctly for outputting the weight to the serial port.
Ralf Meier 9-Jan-21 14:52pm    
Sorry Henry - it's not my question and not my issue an I'm not the enquirer. I'm a "Replier" like you ... and my reply corresponds to the so called "very poor code-snippet" ...

1 solution

Even with a scale, you have to "send" a command before you'll get something back.

Commands like: "tare weight", status, center scale, etc. ... all off which return a result.

And the protocol and "timing" (scales are async devices), is "in the manual".
 
Share this answer
 
Comments
Henry Z. 8-Jan-21 16:31pm    
Welcome and thanks for asking a question. What is the make and model of the scale controller you are trying to connect to? Most scale controllers have two modes which are "Demand" and or "Continuous". Demand will send the weight after a command is sent to the scale controller through a serial port whereas "Continuous" will output the weight continuously without any user interaction. You can usually configure your scale controller for either mode but for that you will most definitely need either a manual or you have to contact the manufacturer of the scale controller.

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