473,385 Members | 1,693 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,385 software developers and data experts.

help for the code

32
Can somebody help? Really need help.
I got this sample from internet but there some parts I could not understand well why we have to use the thing for ..

Hope can seek some advice through this forum...thanks..

Expand|Select|Wrap|Line Numbers
  1. Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMPort.DataReceived
  2.   ' Note this subroutine is executed on the serial port thread - not the UI thread.
  3.   Dim RXByte, Nibble As Byte
  4.   Dim RXArray(2047) As Char
  5.   Dim I As Integer = 0
  6.   Do
  7.     RXByte = COMPort.ReadByte
  8.     Nibble = (RXByte >> 4) + 48          ' Convert received byte to Hex
  9.  
  10.     If Nibble > 57 Then
  11.       Nibble = Nibble + 7
  12.     End If
  13.     RXArray(I) = Chr(Nibble)
  14.     I = I + 1
  15.     Nibble = (RXByte And 15) + 48
  16.     If Nibble > 57 Then
  17.       Nibble = Nibble + 7
  18.     End If
  19.     RXArray(I) = Chr(Nibble)
  20.     I = I + 1
  21.     RXArray(I) = " "
  22.     I = I + 1
  23.     SpaceCount = (SpaceCount + 1) And 31 ' Insert spaces and CRLF for better readability
  24.     If SpaceCount = 0 Then               ' Insert CRLF after 32 numbers
  25.       RXArray(I) = Chr(13) ' CR
  26.       I = I + 1
  27.       RXArray(I) = Chr(10) ' LF
  28.       I = I + 1
  29.     Else
  30.       If (SpaceCount And 3) = 0 Then   ' Insert two extra spaces for each 4 numbers
  31.         RXArray(I) = " "
  32.         I = I + 1
  33.         RXArray(I) = " "
  34.         I = I + 1
  35.       End If
  36.     End If
  37.   Loop Until (COMPort.BytesToRead = 0)
  38.   Dim RxString As New String(RXArray, 0, I) ' Convert the first part of the Char Array to a String
  39.   ' Put a message with a delegate, which points to the display routine and holds the RxString,
  40.   '   on the message queue and return immediately.
  41.   Me.BeginInvoke(New StringSubPointer(AddressOf Display), RxString)
  42. End Sub
  43.  
  44. ' Text display routine, which appends the received string to any text in the Received TextBox.
  45.  
  46. Private Sub Display(ByVal Buffer As String)
  47.   Received.AppendText (Buffer)
  48. End Sub
  49.  
  50. ' Transmitter subroutine.
  51.  
  52. Private Sub Transmitter(ByVal sender As Object, ByVal e As EventArgs) Handles SendButton.Click
  53.   Received.AppendText ("TX" & vbCrLf)       ' Switch to a new line after every transmission
  54.   SpaceCount = 0
  55.   Dim TextString As String
  56.   Dim TXArray(2047) As Byte
  57.   Dim I As Integer
  58.   Dim J As Integer = 0
  59.   Dim Ascii As Boolean = False
  60.   Dim Quote As Boolean = False
  61.   Dim Temp As Boolean
  62.   Dim Second As Boolean = False
  63.   Dim TXByte As Byte = 0
  64.   Dim CharByte As Byte
  65.  
  66.   If COMPort.IsOpen Then
  67.     TextString = Transmitted.Text
  68.     For I = 0 To TextString.Length - 1
  69.       CharByte = Asc(TextString.Chars(I))
  70.       If CharByte = 34 Then ' If " Then
  71.         Temp = Ascii
  72.         Ascii = Ascii Or Quote
  73.         Quote = Not (Temp And Quote)
  74.       Else
  75.         Ascii = Ascii Xor Quote
  76.         Quote = False
  77.       End If
  78.       If Not Quote Then
  79.         If Ascii Then
  80.           TXArray(J) = CharByte
  81.           J = J + 1
  82.         Else
  83.           If (CharByte <> 32) And (CharByte <> 10) And (CharByte <> 13) Then ' Skip spaces, LF and CR
  84.             CharByte = (CharByte - 48) And 31 ' And 31 makes it case insensitive
  85.             If CharByte > 16 Then
  86.               CharByte = CharByte - 7
  87.             End If
  88.             If Second Then
  89.               TXArray(J) = TXByte + CharByte
  90.               Second = False
  91.               J = J + 1
  92.             Else
  93.               TXByte = CharByte << 4
  94.               Second = True
  95.             End If
  96.           End If
  97.         End If
  98.       End If
  99.     Next
  100.     Try
  101.       COMPort.Write(TXArray, 0, J)
  102.     Catch ex As Exception
  103.       MsgBox (ex.Message & "  Check CTS signal or set Flow Control to None.")
  104.     End Try
  105.   Else
  106.     thanks again..
  107.     MsgBox ("COM port is closed. Please select a COM port")
  108.   End If
  109. End Sub
  110.  
Sep 6 '07 #1
1 1569
dyc
32
RXByte = COMPort.ReadByte

How we can noe how byte it is for the COMPort, in this case the COMPort is a variable name for the serial Port..
thanks..I totally lsot...
Sep 6 '07 #2

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

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
4
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
1
by: glenn123 | last post by:
Hi, i am just about out of time to produce a working jukebox which has to perform these functions: to play music files when a track is chosen from a list which when the user presses the change genre...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.