Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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
  #1 (permalink)  
Old October 19th, 2006, 08:05 AM
Friend of Wrox
 
Join Date: Aug 2003
Location: , , .
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default Stop listening to Comm Port

Dear All,

is there anyway to stop listening to a comm port after 2 seconds? coz sometimes after i send command from my computer to my device, the device dint reply and my programe keep listening to the comm port. Is there any way to stop that?
Here is my code for your reference, pls give me some tips on this ...

 Dim port As New IO.Ports.SerialPort
        With port
            .BaudRate = 115200
            .DataBits = 8
            .Parity = 0
            .StopBits = "1"
            .PortName = "COM3"
        End With

    port.Open()
    port.WriteLine(tbCmd.Text)
    strtest = port.ReadLine() 'how can i stop listening if no reply?
    port.Close()
    response.write(strtest)

Best Regards
life_s Ng

  #2 (permalink)  
Old October 20th, 2006, 03:03 AM
Friend of Wrox
 
Join Date: Aug 2003
Location: , , .
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

No way to do this...?

Cheers
life's Ng

  #3 (permalink)  
Old October 21st, 2006, 12:52 AM
Authorized User
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Fresno, California, USA.
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm, I looked on MSDN and found your answer. There is a property you can set for timeout. After you create an instance of the serial class like what you did below, set the object's ReadTimeout property to your value in milliseconds. I only really know how to write in C# but the syntax is similar so the line you would add before opening should be

port.ReadTimeout = 2000

Man, hard to get used ot not putting a ";" at the end hehe.

  #4 (permalink)  
Old October 21st, 2006, 05:04 AM
Friend of Wrox
 
Join Date: Aug 2003
Location: , , .
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

Thank you Quick209!!!

i tried to do something after the time out, but seems like i cant get the status right, any idea for this?


                port.ReadTimeout = 5000
                strtest = port.ReadLine()
                If port.ReadTimeout = true Then
                    Response.Write("time out, i wan to close port")
                Else
                    Response.Write("continue reading")
                End If

ps:it's ok if you put a ";" behind :p
Best Regards
life's Ng



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop button won't stop loop JDShaffer Visual Basic 2008 Essentials 3 May 23rd, 2008 03:22 PM
Problem while reading data from COMM Port salman .NET Framework 2.0 0 November 21st, 2007 07:33 AM
opening port 1433 for listening mat41 SQL Server 2000 2 March 14th, 2005 02:08 AM
C++ Serial I/O Comm Library CNewbie C++ Programming 1 November 25th, 2004 02:59 PM
E-Comm Product Catalog Search reidcor All Other Wrox Books 0 September 3rd, 2004 03:59 PM





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