Using a usb digital scale in vb.net - vb.net

I am developing a FedEx shipping application and I am trying to get the scale to read either dynamically or when the user ships. I need help trying to connect and get data from a usb scale in vb.net. I know how to do it for a serialport but i have no idea for a usb. How would i go about this?
this is my serialport code that i tried getting the port name to read the usb, but it kept saying "port name does not contain COM/com in it".
Private Sub testScale()
Dim Data As String
SerialPort1.Close()
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 9600
SerialPort1.Parity = IO.Ports.Parity.Odd
SerialPort1.DataBits = 7
SerialPort1.StopBits = IO.Ports.StopBits.Two
SerialPort1.Open()
SerialPort1.Write("W" & vbCr)
Data = SerialPort1.ReadExisting
txtOutput.Text = Data
SerialPort1.Close()
End Sub

I was able to achieve what i wanted using this site: http://www.bumderland.com/dev/USBHIDScale.html. Using the HidLibrary.dll and converting the C# code to vb.net.

Related

Get List of all PC's in a local area network

The following code works intermittently. Why is that so? Sometimes result is blank,without any error.
Imports System.DirectoryServices
Public Class Form1
Private Sub Button_Click(sender As System.Object, e As System.EventArgs) Handles Button.Click
Dim result As String = ""
Dim domainEntry As DirectoryEntry = New DirectoryEntry("WinNT://CA")'CA is the workgroup
domainEntry.Children.SchemaFilter.Add("Computer")
For Each computer As DirectoryEntry In domainEntry.Children
result = result & computer.Name & Environment.NewLine
Next
MsgBox(result)
End Sub
End class
Windows workgroups are a peer-to-peer arrangement, with no central server that controls who is on the workgroup. As such, the only way to list all the computers in the workgroup is to contact every computer in your network and check if they are part of the workgroup. That means each computer has to be powered on and connected to the same LAN.
My guess is that some computers are offline when you run that, some other reason that they cannot be contacted at the time you run it.
Old answer:
I'm not terribly familiar with using the WinNT provider, but see if you get different results with LDAP. This would find all computers on the domain (I assume "CA" is the name of your domain):
Dim ds As New DirectorySearcher(New DirectoryEntry("LDAP://CA"), "(objectClass=computer)", New String() {"cn"})
Using src As SearchResultCollection = ds.FindAll()
For Each sr As SearchResult In src
result = result & sr.Properties("cn")(0) & Environment.NewLine
Next
End Using

Already running application now gets socket error 10013

I have an application done in VB.NET that listen on a specific UDP port and answer through the same port to the IP that send the packet.
It was working ok from a couple of years to the last month; now when try to answer crash due to socket error 10013.
I even try an older version that I know it was working too and get the same crash.
I try disabling Microsoft Security Essentials real time protection and Windows firewall and didn't work.
In the code I have the line
MyUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, True)
I have no clue about what to do, I'm lost.
Any idea how to solve this?
Edit:
Here's the code
#Region "UDP Send variables"
Dim GLOIP As IPAddress
Dim GLOINTPORT As Integer
Dim bytCommand As Byte() = New Byte() {}
#End Region
Dim MyUdpClient As New UdpClient()
Private Sub StartUdpBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartUdpBtn.Click
If StartUdpBtn.Tag = 0 Then
' If Not UdpOpen Then
StartUdpReceiveThread(CInt(ListeningPortLbl.Text))
'End If
Else
If ThreadReceive.IsAlive Then
ThreadReceive.Abort()
MyUdpClient.Close()
PrintLog("UDP port closed")
StartUdpBtn.Tag = 0
UdpOpen = False
StartUdpBtn.Text = "Start UDP"
End If
End If
If UdpOpen Then
StartUdpBtn.Tag = 1
StartUdpBtn.Text = "Stop UDP"
Else
StartUdpBtn.Tag = 0
StartUdpBtn.Text = "Start UDP"
TimerUDP.Enabled = False
TiempoUDP.Stop()
TiempoUdpLbl.Text = "--:--:--"
End If
End Sub
Private Sub StartUdpReceiveThread(ByVal Port As Integer)
Dim UdpAlreadyOpen As Boolean = False
Try
If Not UdpOpen Then
MyUdpClient = New UdpClient(Port)
MyUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, True)
UdpAlreadyOpen = True
Else
Me.Invoke(Sub()
TiempoUDP.Restart()
If TimerUDP.Enabled = False Then
TimerUDP.Enabled = True
End If
End Sub)
End If
ThreadReceive = New System.Threading.Thread(AddressOf UdpReceive)
ThreadReceive.IsBackground = True
ThreadReceive.Start()
UdpOpen = True
If UdpAlreadyOpen Then
PrintLog(String.Format("UDP port {0} opened, waiting data...", Port.ToString))
End If
Catch ex As Exception
PrintErrorLog(ex.Message)
PrintErrorLog(ex.StackTrace)
End Try
End Sub
Private Sub UdpReceive()
Dim receiveBytes As [Byte]() = MyUdpClient.Receive(RemoteIpEndPoint)
DstPort = RemoteIpEndPoint.Port
IpRemota(RemoteIpEndPoint.Address.ToString)
Dim BitDet As BitArray
BitDet = New BitArray(receiveBytes)
Dim strReturnData As String = System.Text.Encoding.ASCII.GetString(receiveBytes)
If UdpOpen Then
StartUdpReceiveThread(CInt(ListeningPortLbl.Text))
End If
PrintLog("From: " & RemoteIpLbl.Text & ":" & ListeningPortLbl.Text & " - " & strReturnData)
AnswersProcessor(strReturnData)
End Sub
Private Sub UdpSend(ByVal txtMessage As String)
Dim pRet As Integer
GLOIP = IPAddress.Parse(RemoteIpLbl.Text)
'From UDP_Server3_StackOv
Using UdpSender As New System.Net.Sockets.UdpClient()
Dim RemoteEndPoint = New System.Net.IPEndPoint(0, My.Settings.UDP_Port)
UdpSender.ExclusiveAddressUse = False
UdpSender.Client.SetSocketOption(Net.Sockets.SocketOptionLevel.Socket, Net.Sockets.SocketOptionName.ReuseAddress, True)
UdpSender.Client.Bind(RemoteEndPoint)
UdpSender.Connect(GLOIP, DstPort)
bytCommand = Encoding.ASCII.GetBytes(txtMessage)
pRet = UdpSender.Send(bytCommand, bytCommand.Length)
End Using
PrintLog("No of bytes send " & pRet)
End Sub
10013 is WSAEACCES, which is documented as follows:
Permission denied.
An attempt was made to access a socket in a way forbidden by its access permissions. An example is using a broadcast address for sendto without broadcast permission being set using setsockopt(SO_BROADCAST).
Another possible reason for the WSAEACCES error is that when the bind function is called (on Windows NT 4.0 with SP4 and later), another application, service, or kernel mode driver is bound to the same address with exclusive access. Such exclusive access is a new feature of Windows NT 4.0 with SP4 and later, and is implemented by using the SO_EXCLUSIVEADDRUSE option.
In the comments you mentioned:
I tried the program on a XP x32 and works ok but on Windows 7 x32/x64 don't, even if I disable the firewall and Microsoft Security Essentials Live Protection.
Maybe it sounds almost obvious but you could try to start your program in all of the available Windows XP compatibility modes. You didn't say that you already tried this but maybe you're lucky and the problem will be "solved" by this workaround.
If the problem still exists afterwards and considering the error code of 10013, I would try or check the following things:
I know you disabled "Microsoft Security Essentials" and the Windows Firewall, but double check whether there are other security related programs/services like anti virus protection, anti malware tools etc. running. It really sounds like something is blocking your socket creation/bind.
In case your program created log output/data which allows you to see exactly when it started to fail:
Any new software installed at that time?
Were Windows Updates (maybe automatically) installed at that time? Especially security updates regarding network security?
Any other noticeable changes in your environment? What about log entries in your Windows system log?
Just as a little test to verify if the error occurs only with your UDP socket: Try to use a TCP socket instead of UDP.
Start the machine in Windows Safe Mode with network support and execute your program from there.
Run your program on another Windows 7 machine and see if the same problem occurs there. It could be a valuable starting point (in terms of localization) to know if the problem occurs only on specific versions of Windows.
Single step through your code with a debugger and carefully watch what happens. Perhaps this can reveal some additional info on what's going wrong.
Maybe some of the ideas above can help you to track down the problem a little bit more. Good luck!

SEND SMS from samsung galaxy win celphone using vb.net

How to send sms from your cellphone to any number using vb.net? I have searched over the internet including youtube but it seems that i could not find or cant figure out where to start. My CP cant event detected in the "phone and modem" in windows...
I have a perfect way to send SMS in visual basic, using AT-commands.
AT-commands:are instructed through which you can send and receive SMS messages, make calls from cell phone, and this is an example to Send a message:
Firstly:
Write this code in the top:
Imports System.IO.Ports
Imports System.IO
Secondly:
Write this code in the public class of form:
Dim SerialPort As New System.IO.Ports.SerialPort()
Dim CR As String
Thirdly:
Create a textBox(TextmsgTextBox) to write the text message, and TextBox2(MobileNumberTextBox) to enter the mobile number, and Button(SendBUT) to Send message.
And write this code in the button click event.
If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = COM4
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
Dim message As String
message = MsgRichTextBox.Text
SerialPort.Open()
If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & phoneNumBox.Text & Chr(34) & vbCrLf)
SerialPort.Write(message & Chr(26))
SentPicture.Visible = True
SentLabel.Visible = True
SentTimer.Start()
Else
MsgBox("Port not available")
End If
I Hope My Answer Was Useful To You.
Important Note
Port value change from time to another and from computer to another.
I will show you how to know port value of your device by pictures.
1:Enter to Device Manager from Control Panel.
2:Right click on the device, and choose Properties.
3:Choose Modem tap, and look for port name, and use it in your application.

How to get messages from Serial Port in VB.NET

I already have the working codes using USB broadband kit to send a message in VB to mobile phone. Now I am doing the other way which is getting the messages from the Broadband SIM here's the code:
Imports System
Imports System.IO.Ports
Public Class ReadSMS
Dim SerialPort As New System.IO.Ports.SerialPort()
Private Sub ReadNow_Click(sender As Object, e As EventArgs) Handles ReadNow.Click
If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = "COM4"
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.None
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
SerialPort.ReadTimeout = 10000
SerialPort.Open()
If SerialPort.IsOpen() Then
Try
Debug.Print("START")
Debug.Print(SerialPort.ReadExisting)
Debug.Print("END")
Catch ex As Exception
MsgBox("read " & ex.Message)
End Try
Else
MsgBox("Port not available")
End If
End Sub
End Class
The code above is not working. This line always return an empty value Debug.Print(SerialPort.ReadExisting) even if the SIM card has unread messages. Will that be okay if you will suggest me the best thing to do? Thanks Thanks!
The way you can read GSM is to initialize or send command to ask GSM to stream you some messages, the messages cannot stream by itself. I think you are missing the command to initate the stream of message.
You might wana read this http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS -- these are in C, but the principal remains the same.
Hope this help

Customer Display OR Pole Display

I do also want to know how can I Display Text on Pole Display.
I write the code with VB.net 2008.
Sample Code that I write is :
If SerialPort1.IsOpen = False Then SerialPort1.Open()
SerialPort1.Write("\r\n" & RichTextBox1.Text & vbCr, 0, RichTextBox1.TextLength)
System.Threading.Thread.Sleep(1000)
If SerialPort1.IsOpen = True Then SerialPort1.Close()
I got no errors but can't display on Pole Display.
Please help me.
Sorry,
Forgot to Say. I do setup the Serial port Like This:
SerialPort1.BaudRate = 1200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = 1
SerialPort1.DataBits = 7
But It doesn't work. :(
sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
sp.Open();
// to clear the display
sp.Write(Convert.ToString((char)12));
// first line goes here
sp.WriteLine("Total : " + textBox1.Text + " RM" );
// 2nd line goes here
sp.WriteLine((char)13 + "Tendered:" + textBox2.Text + " RM");
sp.Close();
sp.Dispose();
sp = null;
Dim sp As SerialPort = New SerialPort("COM15", 9600, Parity.None, 8, StopBits.One)
sp.Open()
sp.Write(Convert.ToString(ChrW(12)))
sp.WriteLine("WELCOME HERE")
sp.WriteLine(ChrW(13) & "Total Amount:1200")
sp.Close()
sp.Dispose()
sp = Nothing
You need to setup the serial port - i.e. the baud rate, number of bits and number of stop bits. Read the display poles manual to get these settings.
edit
Before you write any code use a terminal program like windows hyper-terminal to confirm:
That your hardware is working.
if you are using the correct com port
if you are using the correct baud rate
If you need flow control (XON/XOF) or is it via hardware (RTS/CTS)
What commands you can send to the display- i.e. to clear the display & to move the top line
if the display pole dip switches are set-up correctly