Excel 2010 Vba Serial Port Communication

-->

This topic describes how to use My.Computer.Ports to receive strings from the computer's serial ports in Visual Basic.

To receive strings from the serial port

  1. Initialize the return string.

  2. Determine which serial port should provide the strings. This example assumes it is COM1.

  3. Use the My.Computer.Ports.OpenSerialPort method to obtain a reference to the port. For more information, see OpenSerialPort.

    Shrek: Super Party lets you select characters from the movie-including Shrek, Princess Fiona, Lord Farquaad, Donkey, Monsieur Hood, and Thelonius-to battle three of your friends in 30. Shrek Super Party (PlayStation 2) The children had played the game before and really enjoyed it, so I thought it would be a good choice for our family's game night. I like this game because it allows more than 2 people to play at a time. Shrek: Super Party gameplay for the Playstation 2. Played on the original console and recorded with Elgato Game Capture HD. PS2 playlists: PS2 - Top 10 videos etc. Shrek super party ps2. Shrek Super Party is an interactive board game with 30 action-packed mini-games Six Playable Characters: Shrek, Princess Fiona, Lord Farquaad, Donkey, Monsieur Hood and Thelonious Play fair and square or team-up on your opponents Multiplayer modes - 1 to 4 human players against the balance of A.I.

    The Try..Catch..Finally block allows the application to close the serial port even if it generates an exception. All code that manipulates the serial port should appear within this block.

    To program the remote control: Remove the plastic cover on the head unit. Find the 'smart' or 'learn' button on the head unit. The button should have a LED light next to it. Set the coding switches on the EVERSAFE Universal Garage Door Opener Transmitter to any position you like. Press and hold the button on your EVERSAFE Universal Garage Door. Eversafe Garage Door Remote Manual. Without manufacturer instructions on hand, a standard process may be. I have a 1 year old Sears Garage Door Opener that the remotes work for a few weeks and then gradually quit working at any distance, except for a few feet away from the motor. I have replaced batteries, 're-learned' remotes several times. Eversafe garage door remote manual. Download Eversafe Garage Door Remote Manual. 5/4/2017 0 Comments Everything under control with the official One For All homepage. UGD1 About Your EVERSAFE Universal Garage Door Opener. Your Eversafe remote control works with the following manufacturers' products if they are less than ten (1. MENU. Garage Door Opener 2 Button Programming UGD2 About Your EVERSAFE 2 Button Universal Garage Door OpenerThank You for purchasing the Eversafe® Two Button Universal Garage Door Opener Transmitter. Your remote control transmitter is designed to operate most garage door openers as well as most gate openers manufactured after 1981.

  4. Create a Do loop for reading lines of text until no more lines are available.

  5. Use the ReadLine() method to read the next available line of text from the serial port.

  6. Use an If statement to determine if the ReadLine() method returns Nothing (which means no more text is available). If it does return Nothing, exit the Do loop.

  7. Add an Else block to the If statement to handle the case if the string is actually read. The block appends the string from the serial port to the return string.

  8. Return the string.

Example

This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Connectivity and Networking. For more information, see Code Snippets.

1 and it was kind Excel VBA選擇COM Port讀取Arduino資料; Excel VBA 尋找可用. May 04, 2010 Serial Port Communication in Excel (VBA) Introduction to.

Vba

Compiling the Code

This example assumes the computer is using COM1.

Robust Programming

This example assumes the computer is using COM1. For more flexibility, the code should allow the user to select the desired serial port from a list of available ports. For more information, see How to: Show Available Serial Ports.

This example uses a Try..Catch..Finally block to make sure that the application closes the port and to catch any timeout exceptions. For more information, see Try..Catch..Finally Statement.

See also

Hi all,
This forum has been a great help to me in the last few months and I wanted to give something back. Although I am no Excel or VBA expert..I have learnt one heck of a lot in recent times.
I have had some major issues using MSCOMM and finding information/support on the web. So I thought I would share how I got it working on an excel worksheet to communicate with a serial device.
Thanks
Rob
----------------------------------------------------------------
First off, if you hav'nt already done so - you will need to obtain the MSCOMM32.OCX Active X library.
Start here - http://www.yes-tele.com/mscomm.html
You will need to register it. Go to command prompt and type the following -
regsvr32 C:WindowsSystemMSCOMM32.OCX
You should get a message to indicate that the control has been registered.
Then you may need to update the registry with this key -
[HKEY_CLASSES_ROOTLicenses4250E830-6AC2-11cf-8ADB-00AA00C00905]
@ = 'kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun'
As far as the registry stuff goes, I am no expert. This worked for me..and as far as I know it is legal. But if you have any concerns..or if you are not familiar with working within the registry..I would suggest doing some more research first!
Now..you should be ready to program with MSCOMM!!!
Open up a new Excel workbook. Make sure you can see the 'Control Toolbox (View>>>Toolbars>>>Control Toolbox).
Rename your worksheet 'SerialPort'.
Once you can see the toolbox- there should be a little toolbox icon. Click the icon and select 'Microsoft Communication Control' from the list.
The cursor will change, allowing you to draw a box on the worksheet. This is the control. It does not matter where you place it - as when you open the workbook this will not be visible to the user.
Once you have created the control, right-click and select 'View Code'.
You should see something like -
Private Sub MSComm1_OnComm()
End Sub
This is the 'OnComm' event and tells excel what to do when data is received from the serial port. We will come back to this later. Lets write some code to open a port up..
Insert the following into a new sub under the OnComm sub -
Sub OpenPort()
'Open the COM Port with the relevant settings
Worksheets('SerialPort').MSComm1.CommPort = 1
Worksheets('SerialPort').MSComm1.Settings = '9600,n,8,1'
Worksheets('SerialPort').MSComm1.RThreshold = 1
Worksheets('SerialPort').MSComm1.InBufferSize = 4096
Worksheets('SerialPort').MSComm1.PortOpen = True
End Sub
The sub above will configure the port when you try and open it. 'CommPort' is the port number your device is connected to. 'Settings' are the device setting (baud rate, parity, etc) and are usually in the device documentation (you can also use the device with Hyperterminal to get these settings).
PortOpen = True tells Excel to open the port with the above settings.
RThreshold is what we are interested in here. By setting it to '1' we are telling Excel to fire the 'OnComm' code whenever data is received from the serial port.
The way I call the port open sub, is to have a worksheet onchange event. I only want the port to open when the user selects a cell in a particular column range, so I am using the following -
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Columns('A:A')) Is Nothing Then
If Target.Value = ' Then
Call OpenPort
End If
End If
Application.EnableEvents = True
End Sub
This piece of code must sit against the 'Worksheet' 'Selection Change' section. Use the dropdown boxes at the top of your VBA editor to select this.
So now, if a cell in column 'A' is selected, the port will be opened with my settings. As RThreshold is set to '1' - the OnComm code will be called whenever I try to read from the cheque reader and am in the 'A' column.
Now to tell it do something when data is received..
Go back to your OnComm make it look like -
Private Sub MSComm1_OnComm()
If Worksheets('SerialPort').MSComm1.CommEvent = comEvReceive Then
Call GetData
End If
End Sub
The CommEvent - comEvReceive tells Excel that if data is coming in from the serial device..do something. In this case, Call sub 'GetData'.
Now, to create sub 'GetData' that will grab the information from the device and place it in your worksheet.
The sub below is very straightforward - but will help get you started!
Private Sub GetData()
Dim MyData As String
Wokrsheets('SerialPort').MSComm1.InputLen = 0
MyData = Worksheets('SerialPort').MSComm1.Input
ActiveCell.Value = MyData
MyData = '
Worksheets('SerialPort').MSComm1.PortOpen = False
End Sub
The 'InputLen' setting tells Excel how much data to read from the serial device. Setting it to zero tells it to keep reading until the end of the file (ie it gets all of the data). If you know your string is always going to be 10 digits..you could set this to 10. Or you may need a function to pull the characters one at a time until you get to a specific value. It all depends on the device and what you are trying to achieve..
And you are done! You should now have a very basic working script to read data from a serial device and place it into your worksheet.
I hope this helps someone..my apologies for any poor terminology/lack of clarity and any mistakes I have made. I am not using the same code myself..and there is a great deal more that you will need to learn to use MSComm effectively. It is also the first time I have put something together like this (but that's obvious :P)
Hopefully this is a start for anyone else who is struggling to get going with this.
Have fun!
Rob