473,289 Members | 1,961 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,289 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 8113

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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.