Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 11th, 2006, 09:04 AM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Receving strings from Serial Port

Dear readers,

I am sending an ASCII request via the serial port to a device, which answers back with a serial string. I am using VB2005.

After writing the request, I am using the the following code to read the string from the serial port, as per sample in Visual Basic Help.

Using com1 as IO.Ports.Ports.SerialPort =My.Computer.Ports.OpenSerialPort("COM1")

Do
   Dim Incoming as String = com1.ReadLine()
   If Incoming Is Nothing then
       Exit Do
   Else
       ReturnStr & = Incoming & vbCrLf
   End If
Loop

end using

I can read the string from the serial port, as long as
it ends with a Line Feed character.

The problem is, if the device does not answer back, or does not
end with Line Feed, the ReadLine method, is hanging somewhere waiting for the Line Feed command and not returning Incoming equals to Nothing.
I set the Read Timeout to 3 seconds, but it
does not return to my application.

It seems that the method does not timeout after a while, returning
with Incoming equals to Nothing, as per the sample code.

I also tried to use ReadChar to read the characters. With a loop
I can read each character in the buffer, but after reading the last
character control is not given back to my application.
It gives the impression the code is hanging.

I would appreciate any help on this
Thanks









Similar Threads
Thread Thread Starter Forum Replies Last Post
serial port humayun Linux 0 February 20th, 2006 01:53 AM
Serial Port johnjohn Access VBA 2 November 19th, 2004 02:53 PM
Serial Port johnjohn Classic ASP Databases 1 November 16th, 2004 03:08 AM
Serial Port In C NET4JAGMOHAN C++ Programming 1 January 30th, 2004 07:56 AM
Programming for serial port watercress C# 1 December 23rd, 2003 05:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.