473,652 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read all data across a serial COM

Im trying to raed data over a com port. The data comes over the serial
port as such reading CRLF reading CRLF and so on.

The code below only sees the first reading CRLF and then only added
that into the DSIDXPort arraylist and never adds readings 2 through
16.....

How can I get it to read those?

[code]

serialPort.Read Timeout = 50
serialPort.Disc ardInBuffer()

Dim strData As String = String.Empty

If Not serialPort.IsOp en Then
strData = String.Empty
Else
strData = serialPort.Read Line
End If


If strData.Length 0 Then

Dim tempArray() As String
strData = strData.Replace (vbCrLf,
vbTab).Replace( Chr(26), "").Replace(Chr (12), "").Replace(Chr (13), "")

'parses out the information gathered from the COM port
to a temp location
tempArray = Split(strData, vbTab)
If serialPort.Read Timeout = 50 Then
Dim intLoop As Integer
For intLoop = 0 To UBound(tempArra y)
If IsNumeric(tempA rray(intLoop)) Then
DSIMRPort.Add(t empArray(intLoo p))
End If

Next
End If
end if
[\CODE]
Nov 6 '08 #1
3 4375
"cmdolcet69 " <co************ @hotmail.comsch rieb
Im trying to raed data over a com port. The data comes over the
serial port as such reading CRLF reading CRLF and so on.
I don't fully understand the meaning of this sentence.
The code below only sees the first reading CRLF and then only added
that into the DSIDXPort arraylist and never adds readings 2 through
16.....

How can I get it to read those?

I only see one "serialPort.Rea dLine". When or where do you expect it to read
more?
Armin

Nov 6 '08 #2
I presume you mean that the format of the data stream is variable length
strings separated by CR and LF.

As VB is an event based language, you need to make use of the event that
indicates that some data has been received from the port. There is no event
available that tells you that a CRLF has been received, but the DataReceived
event will tell you when each character is received. You can use processing
in that event to see if the received character was a CR or LF - if it is,
then there is a data sentence in the buffer that can be retrieved. You can
then use Readline to retrieve the data from the buffer.

You should not use readline unless you know there is a line to be read.

"cmdolcet69 " <co************ @hotmail.comwro te in message
news:82******** *************** ***********@k36 g2000pri.google groups.com...
Im trying to raed data over a com port. The data comes over the serial
port as such reading CRLF reading CRLF and so on.

The code below only sees the first reading CRLF and then only added
that into the DSIDXPort arraylist and never adds readings 2 through
16.....

How can I get it to read those?

[code]

serialPort.Read Timeout = 50
serialPort.Disc ardInBuffer()

Dim strData As String = String.Empty

If Not serialPort.IsOp en Then
strData = String.Empty
Else
strData = serialPort.Read Line
End If


If strData.Length 0 Then

Dim tempArray() As String
strData = strData.Replace (vbCrLf,
vbTab).Replace( Chr(26), "").Replace(Chr (12), "").Replace(Chr (13), "")

'parses out the information gathered from the COM port
to a temp location
tempArray = Split(strData, vbTab)
If serialPort.Read Timeout = 50 Then
Dim intLoop As Integer
For intLoop = 0 To UBound(tempArra y)
If IsNumeric(tempA rray(intLoop)) Then
DSIMRPort.Add(t empArray(intLoo p))
End If

Next
End If
end if
[\CODE]
Nov 7 '08 #3
I'd have to see the actual code. You call ReadLine each time you want to
read a line (seems clear). Do you have a loop for reading data? Are you
calling this in the DataReceived event (if so, the you certainly cannot call
DiscardInBuffer ).
--
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.
Nov 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
43022
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number (or would HDD be better, or both?) and put that info into VB prog so the program won't work on another computer. My program uses an MSAccess table. Much appreciated if you can help! Thanks
3
7148
by: alastair | last post by:
Hi, I'm using pyserial to transfer data from PC to another device - the data is either from an ASCII file or binary data file. Everything works fine up until I start using files of a particular size on Linux, around 1.3MB. When I send the data on windows everything is ok - on Linux I get the following traceback:
1
8572
by: Tolgay Gül | last post by:
I need some codes that able to send and read data by serialport in VB.Net 2005 beta 2. I wrote some codes and It can send data via serialport but It cannot read what I send. I have looked up on internet and msdn and found some codes and samples but they are also can't read serial port. . It was so easy in VB 6.0 with mscomm object and oncommread events but now I don't understand how it reads data from serialport. You can see the codes...
6
3581
by: Casey Bralla | last post by:
I'd like to read ASCII data from a serial port, but (once again) I'm having trouble getting started. (Can't seem to find the basic level of docs to get going <sigh>) I'd like to use only standard "built-in" modules if possible. Could somebody offer a simple code-snippet to get me started reading from a serial port? Thanks!
17
7913
by: luca72 | last post by:
Hello at all sorry for my english but i'm Italian. I use pyserial to communicate via rs232 with an extarnal device called smartmouse. I write the exact line that i want , but when i read i read only the echo ond not the other bytes. When i meke the same project with delphi i solve this problem with the call of the sleep. But in python it don't work. Have you got some ideas for solve my problem?
7
4856
by: alexandre_irrthum | last post by:
Hi there, I am trying to use pyserial to read data from a temperature logger device (T-logger). T-logger is based on the DS1615 temperature recorder chip (Dallas Semiconductor). According to the DS1615 docs, writing to the chip is performed one byte at a time. To read from the chip, one must issue the "read page" command (33h), followed by the two-byte address of the requested page (pages are 32 bytes long). After receiving this, the...
5
1860
by: Kosmos | last post by:
Hey :) hopefully someone can help me with this...I decided to take on the task of programming an access database for my legal co-op/internship...I'm studying law and music production on the side...most of the background I have in programming has to do with music production... The program I'm creating pulls data from an excel sheet (with defined fields) and brings them into an access database. The data being pulled is the following: ...
4
4616
by: chenatcr | last post by:
Hello, I added a serial-USB converter to my laptop, it appear as USB serial port COM4, and I wrote an application to read 78k data from this port. In my VC++ express code, I defined ReadBufferSize = 78k, and ReceivedBytesThreashold = 78k so that I can get the whole data with one ReadExisting() method when DataReceived event fires.
2
10394
by: mmrasheed | last post by:
Hi, I am newbie in python. I am working on Telit GM862 GPS/GPRS module which has python interpreter built in. But it seems this problem is pretty much related to general python structure. I need a promt/terminal when the device is connected to PC. If user enters a command by serial port and press "Enter" then the data is read by the device and work on the command. This is similar to readline() function. Unfortunately there is no...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
isladogs
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...
0
5619
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();...
0
4145
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...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
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
2
1591
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.