Manejo De Puerto Serial En Visual Basic 2010

Posted on by admin

Hi to all,I have one application in which there is one machine (a tub which gives amount of liter) on display board. It is having Serial Port RS232 in machine. So what i would thinking to do is that through RS232 port i directly want to display it in my application in one text box. So how can i access data from RS232 port in VB.NET (I am using Visual Studio 2008). I know there is Class called System.IO available.

If anybody know this please help me!!!! Also want to know that how to test the code that it is working or not, without attaching it to machine through a serial port RS232?Thank you. When answering a question please:. Read the question carefully. Understand that English isn't everyone's first language so be lenient of badspelling and grammar. If a question is poorly phrased then either ask for clarification, ignore it, oredit the question and fix the problem. Insults are not welcome.

Don't tell someone to read the manual. Chances are they have and don't get it.Provide an answer or move on to the next question.Let's work to help developers, not make them feel stupid.

Manejo Del Puerto Serial En Visual Basic 2010

Visual

How to: Receive Strings From Serial Ports in Visual Basic. 2 minutes to read.In this articleThis topic describes how to use My.Computer.Ports to receive strings from the computer's serial ports in Visual Basic. To receive strings from the serial port.Initialize the return string. Dim returnStr As String = '.Determine which serial port should provide the strings. This example assumes it is COM1.Use the My.Computer.Ports.OpenSerialPort method to obtain a reference to the port.

Manejo

For more information, see.The Try.Catch.Finally block allows the application to close the serial port even if it generates an exception. All code that manipulates the serial port should appear within this block.

Dim com1 As IO.Ports.SerialPort = NothingTrycom1 = My.Computer.Ports.OpenSerialPort('COM1')com1.ReadTimeout = 10000Catch ex As TimeoutExceptionreturnStr = 'Error: Serial Port read timed out.' FinallyIf com1 IsNot Nothing Then com1.CloseEnd Try.Create a Do loop for reading lines of text until no more lines are available. DoLoop.Use the method to read the next available line of text from the serial port.

Dim Incoming As String = com1.ReadLine.Use an If statement to determine if the method returns Nothing (which means no more text is available). If it does return Nothing, exit the Do loop. If Incoming Is Nothing ThenExit DoEnd If.Add an Else block to the If statement to handle the case if the string is actually read.

The block appends the string from the serial port to the return string. ElsereturnStr &= Incoming & vbCrLf.Return the string. Return returnStrExample Function ReceiveSerialData As String' Receive strings from a serial port.Dim returnStr As String = 'Dim com1 As IO.Ports.SerialPort = NothingTrycom1 = My.Computer.Ports.OpenSerialPort('COM1')com1.ReadTimeout = 10000DoDim Incoming As String = com1.ReadLineIf Incoming Is Nothing ThenExit DoElsereturnStr &= Incoming & vbCrLfEnd IfLoopCatch ex As TimeoutExceptionreturnStr = 'Error: Serial Port read timed out.' FinallyIf com1 IsNot Nothing Then com1.CloseEnd TryReturn returnStrEnd FunctionThis code example is also available as an IntelliSense code snippet.

In the code snippet picker, it is located in Connectivity and Networking. For more information, see. Compiling the CodeThis example assumes the computer is using COM1. Robust ProgrammingThis example assumes the computer is using COM1. For more flexibility, the code should allow the user to select the desired serial port from a list of available ports.

Basic

For more information, see.This example uses a Try.Catch.Finally block to make sure that the application closes the port and to catch any timeout exceptions. For more information, see.

See also.