473,830 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help for the code

32 New Member
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 1586
dyc
32 New Member
RXByte = COMPort.ReadByt e

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
2761
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 storing products in
6
3032
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 an html authoring tool to help you accomplish? 2. What do you expect from online help for a html authoring tool? 3. What audience do you think a freeware html authoring tool is directed towards?
6
391
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 hides all of them including hiding the database window, disabling menu changes. What I am after is the same effect as disabling all the check boxes in startup which still leaves 'File', 'Edit', 'Insert','Records','Window' &'Help'. I want to do this...
4
2644
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 type in a command line that runs the help in the correct Context from a button on each form. It all worked fine - HERE. The problem is that when I sent it out to a site, the help file was not able to be accessed because it was my path in the...
7
3313
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 buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
23
3300
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 to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
16
2017
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 learning and really need some help bad. Public Shared Function GetAll() As ArrayList Dim dsCustomer As New DataSet() Dim sqlQuery As String = "SELECT Name, Address, PhoneNo " & _ "FROM CustomerTable" Try
3
3742
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 lot different from what the pros around here use. I really need help with debugging some program errors more than anything, even though my coding style might not be perfect. Anyway here is my code. About the only things that work right are...
1
2295
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 button the list is populated with a list of that genre. I have got the interface done to satisfaction, my problem is that when i press the change genre button nothing happens and when i select a track to play from the list which is setvisible and...
10
3377
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 the worst I ever seen. I almost cannot find anything I need, including things I
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10526
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9315
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7746
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.