I have a slight problem. When attempting to receive data via my serial port
I sometimes do not get the complete data. For example, I have a scanner
that reads barcodes. When reading barcode after barcode, there might be 2
or 3 barcodes in a row where I do not get the complete barcode. It will be
split up over 2 lines.
Here is my code and an example of the data received is toward the bottom.
Dim WithEvents com1 As New SerialPort
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
Handles Me.Load
Try
With com1
.PortName = "Com4"
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
End With
com1.Open()
Catch ex As Exception
MsgBox(ex.ToStr ing)
End Try
End Sub
Private Sub com1_DataReceiv ed(ByVal sender As Object, ByVal e As
System.IO.Ports .SerialDataRece ivedEventArgs) Handles com1.DataReceiv ed
Dim returnStr As String
returnStr = com1.ReadExisti ng 'ReadLine does not work. Any
reason why??
ReceiveSerialDa ta(returnStr)
com1.DiscardInB uffer()
End Sub
Sub ReceiveSerialDa ta(ByVal msg As String)
' Receive strings from a serial port.
CheckForIllegal CrossThreadCall s = False
TextBox1.Text &= msg & vbCrLf
End Sub
I cannot find anything about an EOM (End Of Message) character setting for
the Serial Port. My scanner is set up to send <CR><LFat the end of each
scan.
Here is an example of the data that I receive. I scanned 2 barcodes over
and over. You can see the barcodes are split up but I'm not sure what is
causing this. Any suggestions would be greatly appreciated.
036600826313
04740
0097742
036600826313
047400097742
036600826313
0474
00097742
036
600826313
047
400097742
036600826313
04740009
7742
Thank you all,
Tony 5 6653
Sorry! Nevermind. I jumped the gun here. My scanner was set up with a
Preamble to send a <CRand my Postamble was DISABLED. Now that I've fixed
those, I also removed the vbCrLf in my ReceiveSerialDa ta. Everything works
great.
"Tony K" <ki********@NOS PAMcomcast.netw rote in message
news:1F******** *************** ***********@mic rosoft.com...
>I have a slight problem. When attempting to receive data via my serial port I sometimes do not get the complete data. For example, I have a scanner that reads barcodes. When reading barcode after barcode, there might be 2 or 3 barcodes in a row where I do not get the complete barcode. It will be split up over 2 lines.
Here is my code and an example of the data received is toward the bottom.
Dim WithEvents com1 As New SerialPort
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Try
With com1
.PortName = "Com4"
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
End With
com1.Open()
Catch ex As Exception
MsgBox(ex.ToStr ing)
End Try
End Sub
Private Sub com1_DataReceiv ed(ByVal sender As Object, ByVal e As
System.IO.Ports .SerialDataRece ivedEventArgs) Handles com1.DataReceiv ed
Dim returnStr As String
returnStr = com1.ReadExisti ng 'ReadLine does not work. Any
reason why??
ReceiveSerialDa ta(returnStr)
com1.DiscardInB uffer()
End Sub
Sub ReceiveSerialDa ta(ByVal msg As String)
' Receive strings from a serial port.
CheckForIllegal CrossThreadCall s = False
TextBox1.Text &= msg & vbCrLf
End Sub
I cannot find anything about an EOM (End Of Message) character setting for
the Serial Port. My scanner is set up to send <CR><LFat the end of each
scan.
Here is an example of the data that I receive. I scanned 2 barcodes over
and over. You can see the barcodes are split up but I'm not sure what is
causing this. Any suggestions would be greatly appreciated.
036600826313
04740
0097742
036600826313
047400097742
036600826313
0474
00097742
036
600826313
047
400097742
036600826313
04740009
7742
Thank you all,
Tony
OK.
I had written a reply that included (with some example code -- since your
code is working, Ill include the other thoughts):
ReadLine returns data (blocking) only AFTER a newline (default is carriage
return plus line feed). I never use ReadLine. I always use ReadExisting
(or Read), and look for whatever specific terminating character I need.
Don't discard anything -- else something received while you are processing a
part of a read will go somewhere less than useful. As soon as you read
data, you have cleared that data, subsequent data may be buffered WHILE this
process is executing.
Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Dick,
If you don't mind I'd like to see some of your example code. Maybe I can
modify my code to complete this in a better way. The examples I've found on
MSDN just haven't been as clear as I'd like.
Thanks,
Tony
"Dick Grier" <dick_grierNOSP AM@.msn.comwrot e in message
news:eB******** ******@TK2MSFTN GP05.phx.gbl...
OK.
I had written a reply that included (with some example code -- since your
code is working, Ill include the other thoughts):
ReadLine returns data (blocking) only AFTER a newline (default is carriage
return plus line feed). I never use ReadLine. I always use ReadExisting
(or Read), and look for whatever specific terminating character I need.
Don't discard anything -- else something received while you are processing
a part of a read will go somewhere less than useful. As soon as you read
data, you have cleared that data, subsequent data may be buffered WHILE
this process is executing.
Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Other events can happen while serial data is being received. Your best bet is to append new data to a string until the desired terminator is received. Handle the message and remove it from the the string. In some instances more data can arrive while (or before)handling the previous terminated message. You must preserve this data or the subsequent message will be incomplete.
Other events can happen while serial data is being received. Your best bet is to append new data to a string until the desired terminator is received. Handle the message and remove it from the the string. In some instances more data can arrive while (or before)handling the previous terminated message. You must preserve this data or the subsequent message will be incomplete. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Pawe³ Chrobak |
last post by:
Hi
How to take access to serial port (rs232) ??
Is't possible?? Just tell me guy's where I can take o look
Now I work under Windows XP but finally I need to make script to communicate
witch
GSM modem under Linux. There will be a typical AT commands
Thanks
|
by: fdunne2 |
last post by:
Hi,
I need to interface a signal generator with my computer's serial port ( to
set the frequency, level etc using the appropriate byte codes). How can I
send and receive (acknowledge the message sent - successful/unsuccessful)
data throught the serial port (RS232) in MFC? Some sample code would be
most appreciated!
Regards,
F.
|
by: Ramakant Kasar |
last post by:
Hi,
If an application is reading data from a serial port, How can I open the
same serial port with another application?
Any idea? Please help.
Thanks,
Ramakant K.
|
by: leovg |
last post by:
Can I access the serial port (RS232) out of an ASP.NET 2.0 client form?
We are planning a barcode application where a barcode scanner delivers
input to an ASP.NET form via RS232.
|
by: joe bloggs |
last post by:
I am writing a mobile application to interface with a legacy system and I am
planning to use web services to communicate with this system. The legacy
system receives data through a serial port. What I would like to do is make
the serial port accessible via a web service.
The web service and the legacy application would be running on the same
machine. The mobile application would access the web service via a network
connection. It...
| |
by: David |
last post by:
I have written an application in VB.NET 2003 that uses the SAX serial
component for RS232 communications with hardware.
The program sets up 2 serial ports so that it can talk to 2 different
hardware devices simultaneaously.
When I run the program on a desktop running Windows 2000 it works fine. When
I run it on a Laptop using XP I start having problems.
It seems that when the ports are initiated, either one will work but not the
|
by: Dave Harry |
last post by:
I found the RS232 class from MS's 101 VB samples.
Writing to the port works fine. (I've got hyperterminal on the other comm
port and a crossover cable between COM1 and COM2)
The port is opened with:
Public switchcom As New Rs232
switchcom.Open(2, 57600, 8, Rs232.DataParity.Parity_None,
Rs232.DataStopBit.StopBit_1, 512)
|
by: Mikegtr |
last post by:
I need to collect and send data from a rs232 device- it is a simple
temperature controller.
I need to be able to collect actual temperature ,store the result in
database (mysql) and show it in browser in realtime (or with max 10 sec
delay).
Is there any function/script or smth that could help do that without
external software - I don't want to write a small program in e.g. C
and then collect it from database. Although it is also an...
|
by: colin |
last post by:
Hi,
Im having a tiresome amount of trouble with using a bluetooth serial link.
The receiving end is a bluetooth-rs232 module conected to my embeded system.
The PC has a little usb bluetooth dongle, ive tried a another dongle with
widicom software
as I was having problems with the IVT bluesoleil software.
that seems to have got rid of some other problems,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |