473,420 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,420 software developers and data experts.

Reading from a Serial Port output start byte

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO.Ports
  2.  
  3. Public Class serial_chat
  4.  
  5.     Delegate Sub OutputTextBack(ByVal [text] As String)
  6.  
  7.     Private Sub serial_chat_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  8.         For Each port In IO.Ports.SerialPort.GetPortNames
  9.             ComboBox1.Items.Add(port)
  10.  
  11.         Next
  12.     End Sub
  13.  
  14.     Private Sub Connect_Click(sender As Object, e As EventArgs) Handles Connect.Click
  15.         Try
  16.             If Connect.Text = "Connect" Then
  17.                 SerialPort2.PortName = ComboBox1.SelectedItem.ToString()
  18.                 SerialPort2.Open()
  19.                 GroupBox2.Enabled = True
  20.                 ComboBox1.Enabled = False
  21.             Else
  22.                 SerialPort2.Close()
  23.                 GroupBox2.Enabled = False
  24.                 Connect.Text = "Connect"
  25.  
  26.             End If
  27.         Catch ex As Exception
  28.             MessageBox.Show(ex.Message)
  29.  
  30.         End Try
  31.     End Sub
  32.  
  33.     Private Sub Send_Click(sender As Object, e As EventArgs) Handles Send.Click
  34.         Try
  35.             SerialPort2.Write(TextBox1.Text & vbCr)
  36.             RichTextBox1.Text += "Me : " & TextBox1.Text & vbCr
  37.             TextBox1.Clear()
  38.  
  39.         Catch ex As Exception
  40.             MessageBox.Show(ex.Message)
  41.  
  42.         End Try
  43.     End Sub
  44.  
  45.     Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort2.DataReceived
  46.  
  47.         Receivedtext(SerialPort2.ReadExisting())
  48.  
  49.     End Sub
  50.     Sub UpdateReceviedText()
  51.  
  52.         Dim bytes As String = SerialPort2.BytesToRead
  53.         Dim buffer As String = SerialPort2.BytesToRead
  54.             buffer = SerialPort2.ReadExisting()
  55.             bytes = SerialPort2.ReadExisting()
  56.  
  57.         If Mid(bytes, 1, buffer) = " me :  # - !" Then
  58.             SerialPort2.Write("Ok")
  59.         End If
  60.  
  61.     End Sub
  62.  
  63.     Private Sub Receivedtext(ByVal [Text] As String)
  64.  
  65.         If Me.RichTextBox1.InvokeRequired Then
  66.             Dim x As New OutputTextBack(AddressOf UpdateReceviedText)
  67.             Me.Invoke(x, New Object() {(Text)})
  68.         Else
  69.             Me.RichTextBox1.Text &= [Text] & vbCrLf
  70.         End If
  71.     End Sub
  72. End Class
i want my serial port start bit read should be "#" and end with "!" when it get both character in text form ,then it should received ok message in terminal or virtual com serial port.
Please help its my task and i am newbee vb programmer.Kindly revert ASAP.
Nov 29 '21 #1
0 8209

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Simon | last post by:
Using qbasic, the following accepts input from com1, and prints its output : OPEN "com1:9600,n,8,1,CD0,CS0,DS0,RS" FOR INPUT AS #1 WHILE INKEY$ <> " " INPUT #1, a$ PRINT a$ WEND What...
9
by: Mircea | last post by:
Hi everybody, I have a big problem. I am trying to use serial communication in C# 2. The problem is that the event DataReceived is never fired. I have tried on two computers and it does not...
0
by: pandi | last post by:
Hi, I am using a check scanner.It has functions which gives output like image ,checknumber. i am using serial port to get this output in my coding. My problem is i am not able to read the display...
0
by: usagimys | last post by:
Hi all, i'm very new in serial port communication.. here i got some problem in writing to the serial port.. i have done the connection successfully.. let me explain my situation.. i'm doing a system...
2
by: evle | last post by:
haw to read data from an Infrared Infrared Remote Control
0
by: pranavkrish | last post by:
I am using serialPort control to read data from a barcode scanner , Can you please suggest me the most reliable methof to do this. Now I generate an even based on the data received in the serial port...
6
by: John Wright | last post by:
I am trying to read the data from a device on a serial port. I connect just fine and can receive data fine in text mode but not in binary mode. In text mode the data from the device comes in...
2
by: crampio | last post by:
Hello everyone, I generally look at Google and other websites before I post a question, but trust me I still cannot find and answer to this problem. I'm using VB.net. My problem being is that I...
9
by: Hal Vaughan | last post by:
I've done a fair amount of Googling for information on reading the serial port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to be an unanswered question, 1 is someone saying,...
1
by: Dave Verdi | last post by:
Every time I transmit a byte buffer out the serial port with the byte set to &H0, the transmission stops. Is there a way to transmit &H0 without nullifying the transmission?
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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,...
1
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...
0
agi2029
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,...
0
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...

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.