manasa355
asked on
Serialport Communication moRS232 just reading and placing that value in textbox - It is opening Port and failing in Read method
Hi,
I need to read the value from barcode scanner and put that in my form textbox textSerialNumber.
I have downloaded moRS232 from net and added that class in my project. I am able to open a port, but is faling when it try to read.
here is the code I used In form load I opend the port and Button is clicked I read the value and putting in SerialNumber Text box.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim moRS232 = New Rs232
Try
With moRS232
.Port = 5 '// Uses COM1
.BaudRate = 2400 '// 2400 baud rate
.DataBit = 8 '// 8 data bits
.StopBit = Rs232.DataStopBit.StopBit_ 1
.Parity = Rs232.DataParity.Parity_No ne
.Timeout = 1500 '// 500 ms of timeout admitted to get all required bytes
End With
'// Initializes and Open
moRS232.Open()
'// Set state of RTS / DTS
moRS232.Dtr = True
moRS232.Rts = True
Catch Ex As Exception
MessageBox.Show(Ex.Message , "Connection Error", MessageBoxButtons.OK)
'Finally
End Try
MsgBox("Port Opened")
End Sub
Private Sub bwrite_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bwrite.Click
Try
'moRS232.Read(10)
moRS232.Read(512)
TxtSerialNumber.Text = moRS232.InputStreamString. ToString()
TxtSerialNumber.ForeColor = Color.Black
TxtSerialNumber.BackColor = Color.White
Catch Ex As Exception
TxtSerialNumber.BackColor = Color.Red
TxtSerialNumber.ForeColor = Color.White
End Try
End Sub
Please help where I am doing wrong.
Thanks
Manasa
I need to read the value from barcode scanner and put that in my form textbox textSerialNumber.
I have downloaded moRS232 from net and added that class in my project. I am able to open a port, but is faling when it try to read.
here is the code I used In form load I opend the port and Button is clicked I read the value and putting in SerialNumber Text box.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim moRS232 = New Rs232
Try
With moRS232
.Port = 5 '// Uses COM1
.BaudRate = 2400 '// 2400 baud rate
.DataBit = 8 '// 8 data bits
.StopBit = Rs232.DataStopBit.StopBit_
.Parity = Rs232.DataParity.Parity_No
.Timeout = 1500 '// 500 ms of timeout admitted to get all required bytes
End With
'// Initializes and Open
moRS232.Open()
'// Set state of RTS / DTS
moRS232.Dtr = True
moRS232.Rts = True
Catch Ex As Exception
MessageBox.Show(Ex.Message
'Finally
End Try
MsgBox("Port Opened")
End Sub
Private Sub bwrite_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bwrite.Click
Try
'moRS232.Read(10)
moRS232.Read(512)
TxtSerialNumber.Text = moRS232.InputStreamString.
TxtSerialNumber.ForeColor = Color.Black
TxtSerialNumber.BackColor = Color.White
Catch Ex As Exception
TxtSerialNumber.BackColor = Color.Red
TxtSerialNumber.ForeColor = Color.White
End Try
End Sub
Please help where I am doing wrong.
Thanks
Manasa
ASKER
1)Microsoft Development Environment 2003 Version 7.1.3088
Microsft DotNet Environment Framework 1.1 Version 1.1.4322SP1
Microsft DotNet Environment Framework 1.1 Version 1.1.4322SP1
ASKER
1) Can you use HyperTerminal, and connect to the bar code scanner?
2) What is the scanner model, version, manufacturer, etc.?
Bob
2) What is the scanner model, version, manufacturer, etc.?
Bob
ASKER
Yes Bob,
I used Hyperterminal and I can see the Barcode. connecting Comport 5 - Barcode looks like AA441500-157
2)DENSO GT10Q-SB
MANUFACTURED:APr.,2005ET
2D Code Handy Scanner
Can you please take a look let me know as soon as possible, if you know anything
Thanks for all your help
I used Hyperterminal and I can see the Barcode. connecting Comport 5 - Barcode looks like AA441500-157
2)DENSO GT10Q-SB
MANUFACTURED:APr.,2005ET
2D Code Handy Scanner
Can you please take a look let me know as soon as possible, if you know anything
Thanks for all your help
ASKER
Bob,
Is there any other program, I can do this requirement. All I need is read the data feom serail port(Bar code scanner) and place it in the txtbox serial Number.
Please help....
Thanks
Manasa
Is there any other program, I can do this requirement. All I need is read the data feom serail port(Bar code scanner) and place it in the txtbox serial Number.
Please help....
Thanks
Manasa
Free, or do you want to pay?
Good choice if you want to pay:
http://www.sax.net/
I use VB.NET 2005, which has the System.IO.SerialPort class, so I don't know of any good free resources for serial port stuff that I could recommend.
Bob
Good choice if you want to pay:
http://www.sax.net/
I use VB.NET 2005, which has the System.IO.SerialPort class, so I don't know of any good free resources for serial port stuff that I could recommend.
Bob
ASKER
Bob,
I have VB.net 2005 installed on my computer. Can you please guide me through how I can do this.
Please urgent....
Thanks
Manasa
I have VB.net 2005 installed on my computer. Can you please guide me through how I can do this.
Please urgent....
Thanks
Manasa
ASKER
Bob,
I tried like this VB.NET 2005 ......noting happens. sRead valueis nothing when I debug.
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SerialPortConn As System.IO.Ports.SerialPort = New System.IO.Ports.SerialPort ("COM5", 38400, IO.Ports.Parity.None, 8, 1)
SerialPortConn.Open()
'SerialPortConn.ReadChar()
Dim sRead As String = SerialPortConn.ReadChar()
Catch ex As Exception
End Try
I appreciate if you can help me what Read parameter I should work of. I took as ReadChar() because My barcode sample looks like this AA443200-803*
Thanks
Manasa
End Sub
I tried like this VB.NET 2005 ......noting happens. sRead valueis nothing when I debug.
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SerialPortConn As System.IO.Ports.SerialPort
SerialPortConn.Open()
'SerialPortConn.ReadChar()
Dim sRead As String = SerialPortConn.ReadChar()
Catch ex As Exception
End Try
I appreciate if you can help me what Read parameter I should work of. I took as ReadChar() because My barcode sample looks like this AA443200-803*
Thanks
Manasa
End Sub
Imports System.IO.Ports
...
Private Withevents SerialPortConn As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPortConn = New System.IO.Ports.SerialPort ("COM5", 38400, IO.Ports.Parity.None, 8, 1)
SerialPortConn.Handshake = Handshake.None
SerialPortConn.DtrEnable = True
SerialPortConn.RtsEnabled = True
SerialPortConn.Open()
End Sub
Private Sub OnDataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialData ReceivedEv entArgs) Handles SerialPortConn.DataReceive d
Dim data As String = SerialPortConn.ReadExistin g()
End Sub
Bob
...
Private Withevents SerialPortConn As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPortConn = New System.IO.Ports.SerialPort
SerialPortConn.Handshake = Handshake.None
SerialPortConn.DtrEnable = True
SerialPortConn.RtsEnabled = True
SerialPortConn.Open()
End Sub
Private Sub OnDataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialData
Dim data As String = SerialPortConn.ReadExistin
End Sub
Bob
ASKER
Bob,
I tried with your code. I do not get any data from bar code scanner. When i debug the value for data is nothing.
and I tried with palcing acommand button even then it is not working.I got from hyperterminal
Please let meknow
weather it worked from your end
Thanks
Manasa
I tried with your code. I do not get any data from bar code scanner. When i debug the value for data is nothing.
and I tried with palcing acommand button even then it is not working.I got from hyperterminal
Please let meknow
weather it worked from your end
Thanks
Manasa
1) Just because code works for me doesn't guarantee that it will work for you. There are too many variables, like flow control, COM settings, DTR signalling, etc. that are different.
2) I am not using a bar scanner, but reading from a scale, which is a different proposition
3) It is very important that you get the communications settings correct in order to get this to work.
4) I noticed from your initial code above that you had a baud rate of 2400 and COM1, but the 2005 code has 38400 and COM5, so which is it?
Bob
2) I am not using a bar scanner, but reading from a scale, which is a different proposition
3) It is very important that you get the communications settings correct in order to get this to work.
4) I noticed from your initial code above that you had a baud rate of 2400 and COM1, but the 2005 code has 38400 and COM5, so which is it?
Bob
ASKER
Bob,
I used Rs232 and it worked fine. I think I solved the problem of connecting to port. Now What's happenning is when I display Serial Number in Textbox I am displaying like this
#1301~~AA44320008030~~~~~
Can we replace those Ascii char with empty. I want to display like this #1301 AA44320008030
Can you please help me with this
Thanks
aMnasa
I used Rs232 and it worked fine. I think I solved the problem of connecting to port. Now What's happenning is when I display Serial Number in Textbox I am displaying like this
#1301~~AA44320008030~~~~~
Can we replace those Ascii char with empty. I want to display like this #1301 AA44320008030
Can you please help me with this
Thanks
aMnasa
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bob,
Serial Number is displaying as like this 43AA4432004530,87010-02700 ,0003,2006 05301525 looks like it displaying how many characters in the string at the front. instead it should display like this AA4432004530,87010-02700,0 003,200605 301525. And serialnumber is dsiplaying when I debug it is looping for ever and When I hit F11 then only the serial Number is displaying in the Text box. Otherwise nothing is in the TextBox.
Can you please take a look at the code for looping Please… I really appreciate IF you can see the below code.
And I am thinking that since I am not closing the port, it is looping for ever and displaying that 43 characters in the starting serialNumber. Please help me loop correctly and close the port. So I have correct SerialNumber in the Textbox.
Private Sub GetDataFromScanner(ByVal Ctl$)
Dim InString As String ' Buffer to hold input string
Dim buffer$
Dim StartTime As Date
Dim strSerialNumber As String
strSerialNumber = TxtSerialNumber.Text
On Error GoTo ErrorSub
ScannerInUse = False ': DoEvents() : DoEvents() : DoEvents()
TxtScannerInfo.Text = ""
If TxtSerialNumber.Text <> "" Then TxtScannerInfo.Text = TxtSerialNumber.Text & "data Already Exists." : Exit Sub
StartTime = Now
Dim moRS232 = New Rs232
'If moRS232.Open = True Then moRS232.Open = False
With moRS232
.Port = 2 '// Uses COM1
.BaudRate = 9600 '// 2400 baud rate
.DataBit = 8 '// 8 data bits
.StopBit = Rs232.DataStopBit.StopBit_ 1
.Parity = Rs232.DataParity.Parity_No ne
.Timeout = 500 End With
'// Initializes and Open
moRS232.Open()
'// Set state of RTS / DTS
moRS232.Dtr = True
moRS232.Rts = True
ScannerInUse = True
Do 'Wait for data to come back to the serial port.
'DoEvents()
If Not ScannerInUse Then GoTo ExitSub
TxtScannerInfo.Text = "...Waiting for Scanner"
buffer$ = buffer$ & moRS232.Read(Int32.Parse(5 0))
buffer$ = buffer$ & moRS232.InputStreamString( )
Loop Until InStr(buffer$, vbCrLf) Or Truncate(buffer$, 1) = Chr(13)
TxtSerialNumber.Text = Truncate(buffer$, (Len(buffer$) - 1))
ExitSub:
TxtScannerInfo.Text = ""
ErrorSub:
'If moRS232.Open = True Then moRS232.Open = False
End Sub
Private Sub TxtSerialNumber_GotFocus(B yVal sender As Object, ByVal e As System.EventArgs) Handles TxtSerialNumber.GotFocus
GetDataFromScanner(TxtSeri alNumber.T ext)
End Sub
Thanks a lot for all your help.
Manasa
Serial Number is displaying as like this 43AA4432004530,87010-02700
Can you please take a look at the code for looping Please… I really appreciate IF you can see the below code.
And I am thinking that since I am not closing the port, it is looping for ever and displaying that 43 characters in the starting serialNumber. Please help me loop correctly and close the port. So I have correct SerialNumber in the Textbox.
Private Sub GetDataFromScanner(ByVal Ctl$)
Dim InString As String ' Buffer to hold input string
Dim buffer$
Dim StartTime As Date
Dim strSerialNumber As String
strSerialNumber = TxtSerialNumber.Text
On Error GoTo ErrorSub
ScannerInUse = False ': DoEvents() : DoEvents() : DoEvents()
TxtScannerInfo.Text = ""
If TxtSerialNumber.Text <> "" Then TxtScannerInfo.Text = TxtSerialNumber.Text & "data Already Exists." : Exit Sub
StartTime = Now
Dim moRS232 = New Rs232
'If moRS232.Open = True Then moRS232.Open = False
With moRS232
.Port = 2 '// Uses COM1
.BaudRate = 9600 '// 2400 baud rate
.DataBit = 8 '// 8 data bits
.StopBit = Rs232.DataStopBit.StopBit_
.Parity = Rs232.DataParity.Parity_No
.Timeout = 500 End With
'// Initializes and Open
moRS232.Open()
'// Set state of RTS / DTS
moRS232.Dtr = True
moRS232.Rts = True
ScannerInUse = True
Do 'Wait for data to come back to the serial port.
'DoEvents()
If Not ScannerInUse Then GoTo ExitSub
TxtScannerInfo.Text = "...Waiting for Scanner"
buffer$ = buffer$ & moRS232.Read(Int32.Parse(5
buffer$ = buffer$ & moRS232.InputStreamString(
Loop Until InStr(buffer$, vbCrLf) Or Truncate(buffer$, 1) = Chr(13)
TxtSerialNumber.Text = Truncate(buffer$, (Len(buffer$) - 1))
ExitSub:
TxtScannerInfo.Text = ""
ErrorSub:
'If moRS232.Open = True Then moRS232.Open = False
End Sub
Private Sub TxtSerialNumber_GotFocus(B
GetDataFromScanner(TxtSeri
End Sub
Thanks a lot for all your help.
Manasa
ASKER
Bob,
Can you please take a look. Please urgent...
Thanks
Manasa
Can you please take a look. Please urgent...
Thanks
Manasa
2) Download location?
Bob