472,363 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,363 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 6981

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
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.