Excel 2010 Vba Serial Port Communication
Can anyone help with communicating to a COM port through Excel (on a machine that does not also have Visual Basic installed)? I've tried downloading MSCOMM -- Excel recognizes the reference to MSComm32.ocx, but I get an error when trying to use it ('Run-time error '429': ActiveX component can't create object' ). These are the lines of code that create the error (omitting the remainder of the subroutine). The line 'Set CPort.' Is what causes the error to pop up: Sub ComPortTesting() Dim CPort As MSComm Set CPort = New MSComm. This is really a two part question: (1) Can this be done using MSComm? (Or is there some basic problem like a licensing/registry issue) AND (2) Is there another way to communicate with the Com port using Excel that doesn't require MSComm?

Nov 29, 2010. Below is the code I used and I also attached the Excel file and the source code I used to communicate with a PIC32 using a FTDI interface chip. The VBA code came from here: Reply #1 on: November 29, 2010, 08:24:08 AM ».
--Jason RE: Excel Com port communication (Programmer) 28 May 03 10:57. Playing with MSCOMM is definitely not for the fainthearted.
I use a simple solution called Cheapcom which is as far as I am aware Freeware. It has an installer that installs the DLL and a simple set of commands for performing the various COM operations. I have written a standard Excel book that contains a sheet with all the settings, Baud, Parity, etc., and I just tailor this to suit the application that I am writing. It is possible to use any Serial Com Port with both ASCII and Hexadecimal. I quote from the Cheapcom help file. *********************************************************** CheapComm was written to permit Visual Basic, Excel, and VBA (Visual Basic for Applications) users to use the Photon Technology International (PTI) serial port devices without requiring purchase of the professional version of Visual Basic (that comes with MSCOMM32, a decent serial port OCX), or an expensive serial port DLL that provides many more features than the SIDs require.
This control has also been used with to control other serial port devices. This control can be used with any language that works with OLE controls (OCX controls). CheapComm is a means of using the serial port for instrument control.
It is NOT meant for very sophisticated serial port operations. To this end, CheapComm only exposes the most basic operations of the serial port. It will send or receive ASCII or binary information, configures the port for basic communications, and clears the port buffers, and that’s it! The command set can be summarized in only a few lines: OpenCommPort(Serial_Port as String, Serial_Frame as String) as Boolean CloseCommPort() GetNumBytes() as Integer GetStringData(Buffer as String, Numchars as Integer) as Integer GetBinaryData(Buffer as Byte array, Numbytes as Integer) as Integer SendStringData(Buffer as String) as Integer SendBinaryData(Buffer as Byte array) as Integer SendSubArray(Buffer as Byte array, NumBytes as Integer) as Integer ClearCommPort() That’s all the functionality this control provides, but these few procedures can do a lot. For example, a timer can be used to poll the serial port using GetNumBytes().
When the number of bytes reaches a certain value, the data can be removed from the serial port. ***************************************************** For more info give me an E-mail address and I will send a sample application. Richard Richard RE: Excel Com port communication (TechnicalUser). A pleasure Malforge, I once started down the MSCOMM route and found it quite beyond me!
I think if you are a professional programmer then it certainly offers everything that you ever could require. My trouble was that I never got going! I only wanted to send an ASCII string of four characters to Com 1 and see what came back, but was immediately lost in the technicalities. If it is any use to you, I have written applications that use both ASCII and HEX, and have made my own routines for converting between DECIMAL, HEX, and ASCII as well as a converter for floating decimal. Regards, Richard RE: Excel Com port communication (TechnicalUser) 4 May 04 12:57. In the meantime I have progressed somewhat with my programming and can now use a variety of dlls and ocxs including MSCOMM.
Cheapcom is brilliant if you just want to do what they offer in the text I posted above. You have to remember that these objects only run from a form. In this example I have created a form called Form1 and using TOOLS/Additional TOOLS have added the Cheapcom Object to the form. You don't need to go further with the form as you will never see it displayed.
This code was used to communicate with a microprocessor called FPO which required the HEX string to give a response. Sub Read_FPO_Registers() 'This routine is used to send a single fixed command, which returns 'the binary state of all registers. Thank you very much! That is a lot of great information. In my time today, I managed to figure out enough to put the CheapComm on a form, and call it as you show.
My problem now seems to be something with the controller connected to the port, or CheapCommm isn't written correctly. I have a small controller that takes ASCII commands to read some analog voltages. I can get the port open, I can verify that the command was sent, I can see data on the input buffer, but I can't get it out. The Help file is written wrong-- showing GetString() instead of GetStringData(). (That took about 4 hours to figure out (ah. Object Browser.
I get it.) So I'm not sure I'm using GetStringData or GetBinaryData the way they supposed to be. The key thing is that I don't get any errors-- I just don't get any data either. Your code does give me a few more ideas to try.
Have you found any other way to do this without CheapComm? Somebody else mentioned that you can just print to the port, but I couldn't get that to work either. Anyway, thanks again for your reply. I'll post again with my results-- good, bad, or indifferent. RE: Excel Com port communication (TechnicalUser) 5 May 04 02:28. I have the same problem as javanic.
The OpenCommPort command is always true, even if the routine has an error opening the port. Nevertheless I was able to use CheapComm to read a 400 character report from a laboratory titrator and insert desired information into a spreadsheet. The code posted by tbl was useful although I'm reading strings not bytes. My problem was that I don't know exactly when (or how much) data will arrive so my macro polls the serial port and gathers data until I detect the character string marking the report end. RE: Excel Com port communication (TechnicalUser) 6 Jan 05 01:38. I have now been using both CheapComm and MSComm for VBA serial applications for many years and have a substantial number of industrial programs running.
I have come to realise that MSComm is more reliable than CheapCom and gives more consistent results. To install MSComm it is necessary to register the DLL and indicate to Excel VBA that it is being used in your code. If anyone needs to know how to do this I will post exact instructions.
I have got an enormous amount of working code that covers both binary and ASCII serial comms and will be very happy to publish chunks for specific applications. Richard RE: Excel Com port communication (Programmer) 6 Jan 05 10:28. 1.) Copy the files you would like to register to [C: WINDOWS system32](in this case MSComm32.ocx) 2.) Go to the command prompt Start -->Run -->cmd 3a.) To install/register the file type in: regsvr32 file.dll or regsvr32 file.ocx 3b.) To uninstall the files type: regsvr32 -u file.dll or regsvr32 -u file.ocx 4.) Some type of message should be displayed that says you successfully registered or unregistered the file Hope this is useful Richard RE: Excel Com port communication (TechnicalUser) 14 Jan 05 18:41. I tried this. It allows the mscomm control to be added to the control toolbox but when I try to put it into a form for use I get the error 'Control could not be created because it is not properly licensed'. Looks like if you don't have VB installed, then you can't use this control and have to stick with CheapComm. Don't know if this is just on the computer you're creating the program or on any computer.
I've used MSCOMM from VB to write an application and then installed the application on other computers so I guess as long as you're not coding, you don't have to have VB installed. Seems compiled software can use the OCX even if it isn't 'properly licensed' since it shows up on most computers even if VB was never installed.
RE: Excel Com port communication (TechnicalUser) 17 Jan 05 01:33. Maybe its the version of Windows or Office that has some effect. I found an Excel Worksheet on the internet that had the MSComm ctrl already present. I deleted everything (code, ctrls, tabs) but the MSComm control and was able to use it successfully writing fresh code. However can't add another MSComm to the worksheet or copy/paste. I guess as long as I only need to use 1 port I'm OK with using this as a template.
Got to figure out how to trick it into adding another MSComm ctrl. Matt RE: Excel Com port communication (Programmer) 27 Jan 05 19:53.
Hope this is of some use. This is another example of communication with a very sophisticated multi-channel measuring instrument. An 8 byte string is sent to the instrument which then sends back the status of each channel in Hex containing the floating point decimal representation. As I could not find any way of converting the 4 bytes per channel into decimal, I made a rather crude but effective model in Excel to convert the incoming bytes 4 by 4 into floating point decimal.This has been working fine for 4 years without restarting the Windows NT PC! The Excel file is programmed to monitor the incoming parameters and send an E-mail automatically if any of them go out of bounds.
Can anyone help with using Excel to speak to a PIC chips using COM1 serial comms port? This is perhaps repeating the first question posted on this thread, but I have spent hours trying to understand the pursuing discussions and efforts and looking up recommended links. I don't want to do anything fancy, only write and read strings or binary data at low speed to and from a PIC chip. I did download a free version of Liberty Basic.
Using its open and print commands it was possible to communicate with the serial port. Is there in summary a simple way to make Excel use serial comms without having to buy very expensive add-ins and if so, how would this be done? If there is not, what is the least expensive way of resolving this issue? I am at the moment confused. Ever so thankful for some help!
RE: Excel Com port communication (TechnicalUser) 16 Feb 05 02:31. It doesn't matter what you are trying to communicate with.The steps are always like this..
Use Port Monitor (freeware) to study the (successful) communication between a PC and the device. Identify a few commands and log them so that you can later simulate them in Excel.You need at lest 1 command with its resulting response from the device. Decide if your comms are ASCII or HEX based, and what your port settings need to be. This you can see from Port Monitor. Make a primitive VBA script which sends the command and receives the response.
To do this you merely install CheapComm or MSCOMM32.ocx + register, and test using Port Monitor to see what your program is doing. Write your program in VBA Richard RE: Excel Com port communication (TechnicalUser) 16 Feb 05 02:35. Thanks so much for an amazingly fast response! The forms bit puzzled me too. Is there an answer to why this is the case (do you have to attach the commands to an object)?
How do you actually do this? I don't know how to make the forms palette show the Cheapcomms functions/subroutines, although they show in the reference library in the Excel Visual Basic editing window.
Without being too much of a burden, if you wanted to send at 9600 baud (stopbits 8 parity none stopbits 1 and flowcontrol none) a simple string 'Hello world' from cell A1 in Sheet1 and then receive 'Hello world' and write it into cell A2 in Sheet1, what would this programme look like in VBA Excel using Cheapcomms? Looking forward to hear from you soon. RE: Excel Com port communication (TechnicalUser) 16 Feb 05 09:55.
OK farmcafe, I make no apologies for the very low technical level of this explanation! Open Excel with blank sheet and press Alt + F11 to open VBA. Right click on This workbook and insert both a form and a module. Install CheapComm 4. In VBA under TOOLS/REFERENCES/BROWSE find CheapComm.ocx in System32 and register it in References - must be present in the list and ticked. 5.Click on the UserForm that you have created and select Additional Controls by using right click on Toolbox 6.
Drag the funny CheapComm icon onto your form and select Properties (right mouse) 7. You will see that the properties window has opened and CheapComm1 has arrived! You now have a valid Form containing CheapCom ActiveX which can be addressed by the code in a module. Insert your code into the blank module ************************************************** Sub SendHelloWorldASCII () bIsPortOk = UserForm1.CheapComm1.OpenCommPort('COM1', '9600,n,8,1') Use the code from the help file of CheapComm end sub **************************************************** I don't have time to program your code today but I will publish it when I have time. Hope this gets you started. Richard RE: Excel Com port communication (TechnicalUser) 16 Feb 05 11:09. As promised, your program.
Just stuff this code into an empty module of an Excel book,prepared as I described in my previous post. ************************************************************ Sub HelloWorld() 'fully tested! BIsPortOpenSuccessful = UserForm1.CheapComm1.OpenCommPort('COM1', '9600,n,8,1') 'you can of course link your string to an Excel cell nNumBytesSent = UserForm1.CheapComm1.SendStringData('HELLO WORLD') fStartTime = Timer 'get the current time (seconds since midnight) Do 'Give the program time to read the input buffer nNumBytesWaiting = UserForm1.CheapComm1.GetNumBytes fCurrentTime = Timer 'get current time 'if no reply within 10 sec, exit If fCurrentTime - fStartTime >10 Then MsgBox 'Doesn't look like WORLD is going to reply!' , vbCritical, 'Reply Error' UserForm1.CheapComm1.CloseCommPort 'close Comport End 'get out of loop End If Loop Until nNumBytesWaiting = 11 'Change this value to suit number of words 'Select the number of bytes to be removed from buffer for processing nNumBytesReceived = UserForm1.CheapComm1.GetStringData(strData, 11) ReceivedString = strData 'this is what has come back to the port UserForm1.CheapComm1.CloseCommPort End Sub ************************************************************ It is always a very good idea to have Port Monitor running while you step through the code with F8. Not really worth the effort! You have to work at a much lower level and specify and register eveything. I include a bit of code which I use to get a list of available ports on a Windows PC.
The result gives you a complete list of all available ports on the PC. Thanks for the compliment. Actually, responding to other users' comments on this forum is so easy as you automatically get a mail each time something happens. If only some of the other forums were as organised.
The art of RS232 communication with Excel is particularly satisfying, as the data that one gets from an instrument almost always ends up in Excel in the end. It is therefore much more elegant to import your data directly into Excel.I have got loads of programs which not only monitor industrial instruments, but notify users by e-mail (including Lotus Notes.) automatically if the data exceeds a particular limit. Some of these have been running for more than 3 years without re-booting! Richard RE: Excel Com port communication. There seem to be a lot of people out there struggling with licensing errors for the MSComm on machines that do not have VB6 installed. This worked for me: (for end-users under Windows NT 4.0) - copy the mscomm32.ocx to the location d: winnt system32 - run from the dosprompt: regsvr32 d: winnt system32 mscomm32.ocx - save both the texts between the dotted lines in notepad files which you save as.reg The blank lines also are important so leave them where they are! ------------------------------ REGEDIT4 [HKEY_LOCAL_MACHINE SOFTWARE Classes Licenses 4250E830-6AC2-11cf-8ADB-00AA00C00905] @='kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun' ---------------------------------- AND --------------------------------- REGEDIT4 [HKEY_CLASSES_ROOT Licenses 4250E830-6AC2-11cf-8ADB-00AA00C00905] @='kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun' -------------------------------------- run both files on the end-user machine just by doubleclicking them ==>this solved the errors and made MSComm available.
==>with thanks and respect to the guys on. It is totally unclear whether or not MS really wants (wanted?) to protect the MSComm itself. I would suppose they included the right to distribute the apps you create with a licensed VB6. Updating the registry just avoids having to install and uninstall the whole package on every pc you want to run your code. If MS offered the possibility to buy a license for it stand-alone (as exists for countless other ActiveX components) all of this timeconsuming fiddling wouldn't be necessary.
RE: Excel Com port communication (TechnicalUser) 2 Mar 05 19:35. I would like to thank all of you for your comments here. I have been looking for a way to download data from a timer for years. With CheapComm it's been a piece a' cake. PS The cheapcomm issue that arises from the openport statement always returning 'true' needed a work-around, and my fix isn't elegant, but it works.
In essence, I put the statement at the end of a short procedure. If the operator is notified by CheapComm that the port couldn't be opened, he/she has to be smart enough to know that the port couldn't be opened. RE: Excel Com port communication (TechnicalUser) 4 Mar 05 01:53.
Actually, after using CheapCom for many years I have learned that MSComm is not only no more difficult to use than CheapCom, but considerably more reliable. The advantage of CheapCom is that is only consists of a few simple lines of code that can handle most serial comms. The downside is that CheapCom doesn't always work!! I have had instances where a program that has run for 2 to 3 years has begun to run erratically and I have had to switch the code over to MSComm. I personally do not believe that MSComm is subject to any restrictions at all. It was not written by Microsoft and has been included in countless (free) packages. I think that Sax Software wrote it for Microsoft as they did the version for VB.NET.
My experience is that if you use the right version it always just works. If you want to know if a port is available without getting an error message then you can use my 'Get Available Ports ' routine exactly as posted. Otherwise you just get a message from CheapCom that the requested port could not be opened. Here is a simple (complete) routine that sends a bit of HEX to an engraving machine to turn it on. Hi, I’m trying to get communication between a microcontroller (BasicX24) and VBA in PowerPoint. The microcontroller will be sending one byte to VBA and receiving three bytes from VBA. In VBA I’m sending data to the serialport using CheapComm by writing the following: nNumBytesSent = Userform1.CheapComm1.SendBinaryData(111) Have also tried to write (1,1,1), (“1”, “1”,”1”), (“1,1,1”) and (“111”).
When I try to print the value of nNumBytesSent (Debug.Print nNumBytesSent) the immediate window writes a 0 (zero) or nothing at all, instead of 111 or 1,1,1. How can I get CheapComm to send 111? The reason for using the function SendBinaryData instead of SendStringData is that it is important that the numbers sent are bytes since that is what the microcontroller expects to receive and sends. VBA is quite new to me and I have tried to follow the tread “Excel Com port communication” (Thread 707-560230) but have a hard time to find a solution that’s right for me. Is there anyone out there that could help me?
Polly RE: Excel Com port communication (Programmer) 7 Mar 05 13:25. Thanks for the fast reply and your code. I have now got the sending part to work but not the receiving one. Can't proceed cause my trial version of Eltima port monitor ran out.
I tried the Advanced Serial Port Monitor from Agg Software but it didn't work for me, cause it couldn't read the communication. Kept writing something about trial version limitation. Is there anyone that can recommened a free port monitor? Can't go on without one. Thanks, Polly RE: Excel Com port communication (TechnicalUser) 10 Mar 05 06:54.
No one has posted here in a while, but I thought I would chip in just the same. I was using CheapComm but I ran into the same type of problem as Richard and Dcupper2 noted.
CheapComm gets glitchy. My problem was that after working fine for a while, my OnTime events started running OK the first time through but on subsequent runs the CheapComm commands wouldn't work. I subsequently moved over to MSCOMM and was able to change my OnTime events to OnComm events. The data shows up on the worksheets much faster and I have not had any problems since I switched. I downloaded SerialCom.zip from It appears that you must have a license to program to MSCOMM but your end users only need it installed in order for the project to run. This forum has been a great help in getting me started with serial port communication in Excel/VBA.
I have picked up a few tidbits about MSCOMM along the way and I am quite willing to share if anyone has an interest. Ask and you shall receive. I visit this site once or twice a week. Greg RE: Excel Com port communication (Programmer) 28 May 05 04:33. Contained within the SerialCom.zip file I mentioned earlier is the MSCOMM file and instructions for registering the license.
The instructions are essentially the same as described in another response, but include manually inserting the license in your registry. I have not been able to relocate CheapComm.zip either.
My advice though is to try MSCOMM again. It has more functionality and appears to be more stable. Information regarding the methods, properties etal of MSCOMM is scattered. There is some good information in the Tek-Tips VB forum. If you can find a forum on Visual FoxPro you may find some help there also. Greg RE: Excel Com port communication (TechnicalUser) 30 May 05 01:32.
Despite the various posts about the problems of registering MSCOMM and licencing it, I have never had any problem with this on any of the PCs that I have used it on. I'm not even sure that it is any different to any other ocx. Maybe the users who are having problems using it can give us some feedback as to exactly what does not work. It is certainly true that Cheapcom works very well on 95,98,and NT, but begins to give strange results on Win2000 and higher.
If anyone needs Cheapcom I'm sure I can find a way to get it to them. RE: Excel Com port communication (Programmer) 31 May 05 20:56. Ok I've finally got MSComm working and can dial up a modem. I am currently just waiting for a fixed period then assuming connection then sending a string. The thing is the response I recieve would be a string of indeterminate length (but not that long), so can you advise how I would determine when the modem connects for sure and when the remote modem has finished sending? I'm currently looking at the comevent property but being new to this I am just blundering around. Thanks in advance R4 RE: Excel Com port communication (Programmer) 1 Jun 05 11:42.
The default event for MSCOMM is 'OnComm'. Code for OnComm will be within the userform that holds MSCOMM..RThreshold (receive) and.SThreshold (send) are triggers for the OnComm event to run. The default value for these is 0 which means OnComm will not fire.
You can set the value of either to an integer representing the number of characters that must be in the port buffer before OnComm fires. The usual number to set them to is 1.
There is no relationship between.InputLen and RThreshold or.Output and SThreshold. Download Lagu Karaoke Indonesia Mp4. The threshold values can be set at runtime anywhere in your code. The.CommEvent value changes according to events at the Com Port. In the Object browser window, search for 'OnComm'. One of the responses will be OnComm constants.
These OnComm constants are the possible values for.CommEvent and at the bottom of the window you will see the numerical values for each.CommEvent constant. ComEvReceive is equal to 2 and that is probably the one you want. Sub OpenAPort() On Error Resume Next ComOpenResponse = False ComOpen.Show 'a dialog box that allows the user to select the port number. The variable 'ComPortName' is set to the value of a textbox on the form. If ComOpenResponse = False Then Exit Sub ComForm1.MSComm1.PortOpen = False 'make sure the port is closed.
I've not had time to really digest the answer you gave but thought I would just get on and thank you for the effort you put into it. The one question I do hav is I notice that you predetermine that InputLen is 22 characters long. How do you handle it if you don't know for sure how many digits will be returned?
The reason is I want to write a script that will interrogate a system to find out how it has been programmed but the options that I will be querying can have variable lengths of information stored in them. RE: Excel Com port communication (Programmer) 2 Jun 05 15:05. To Ozzie, There are two ways (at least) to handle incoming data of indeterminate length. If you set '.InputLen = 0' then '.Input' will pull all the data out of the port buffer. You can also use a Do-Loop and pull one character at a time until all the data has been pulled.
This takes longer but if you happen to know what the end-of-string character is (CR or LF or whatever) you can stop looping when you reach it. This allows you to pull down 1 'Sentence' even though you aren't sure how long it will be. By the way, one of the OnComm constants is 'comEvRing'. Sounds like it should be useful when writing code for a modem. RE: Excel Com port communication (Programmer) 3 Jun 05 23:35.
Ozzie G If you know a device is going to respond then maybe you should poll the port (use an OnTime event instead of OnComm). You can poll the port once per second. The alternative is a loop with a built in pause.
The danger with a loop is if there is no response from the device the code hangs in an infinite loop. Either of these slows the process down to allow the device to respond with less likelyhood that the downloaded data will get truncated. This code will poll the port.
When something arrives in the port the loop is broken. If nothing arrives in the port you're stuck. I suppose you could put a counter in so it only ran a set number of times and then exited.
Do While userform1.MSComm1.inbuffercount = 0 TheWait = 1 TheTime = Timer Do While Timer. The biggest problem I am having at the moment is that the modems are doing the initial handshaking then immediately closing down the link. I used portmon to see what was happening and the results less the time and process columns are below. As I am new to this it doesn't mean a lot to me (By the way the word Programmer next to my name is from A pabx forum where I usually supply the answers). I am wondering whether the problem is the serial port or the modem protocols? Do I have to use a command to hold a pin high or something? IOCTL_SERIAL_GET_COMMSTATUS Winachsf0 SUCCESS IOCTL_SERIAL_SET_WAIT_MASK Winachsf0 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING IOCTL_SERIAL_WAIT_ON_MASK Winachsf0 SUCCESS IOCTL_SERIAL_SET_WAIT_MASK Winachsf0 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING IOCTL_SERIAL_WAIT_ON_MASK Winachsf0 SUCCESS IOCTL_SERIAL_SET_WAIT_MASK Winachsf0 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING IOCTL_SERIAL_WAIT_ON_MASK Winachsf0 SUCCESS IOCTL_SERIAL_GET_COMMSTATUS Winachsf0 SUCCESS IOCTL_SERIAL_GET_COMMSTATUS Winachsf0 SUCCESS IRP_MJ_READ Winachsf0 SUCCESS Length 14:.NO CARRIER.
IOCTL_SERIAL_GET_COMMSTATUS Winachsf0 SUCCESS IOCTL_SERIAL_SET_WAIT_MASK Winachsf0 SUCCESS Mask: IOCTL_SERIAL_CLR_DTR Winachsf0 SUCCESS IOCTL_SERIAL_PURGE Winachsf0 SUCCESS Purge: TXABORT RXABORT TXCLEAR RXCLEAR IRP_MJ_CLEANUP Winachsf0 SUCCESS IRP_MJ_CLOSE Winachsf0 SUCCESS Any help gratefully recieved. Regards R4 RE: Excel Com port communication (TechnicalUser) 7 Jun 05 11:08. The sites where I found Cheapcom.zip is no longer active. Turbo C Book By Robert Lafore Pdf Free Download there. I would recommend MSCOMM instead. The information in this thread should allow you to get it working even if you don't have Visual Basic.
Alternatively, search on Excel+ Com Port or something like that. I found a website that had an example of an Excel sheet with MSCOMM already present as a control. I then deleted everything but the control and started fresh. If the control is already on the spreadsheet, you can use it as long as you have MSCOMM.ocx on your PC.
YOu can get that from MS. RE: Excel Com port communication (TechnicalUser) 8 Jun 05 15:17. Thanks guys, This thread has been very helpful in getting me started in the right direction. I am trying to communicate with a serial device with VBA, however I need to see how the device communicates first. I downloaded portmon and tried it but it seems to lack the most basic feature.
I want to see what ascii characters are being sent back and forth. In the 'other' column it sort of shows this, but the first 8 characters or so are missing (the word 'Length:25' for example) is covering them up. Is there any way to see what is being sent? Maybe a different port monitoring program? RE: Excel Com port communication (TechnicalUser) 22 Jun 05 18:48.
If you know the baud rate, parity, stop bits, data length and the type of cable required, a very simple way to monitor what your serial device is sending is using HyperTerminal which comes with Windows. You'll see all the ASCII characters that are sent although sometimes Hyperterminal has trouble with non-printing ASCII characters (like carriage return, linefeed). Often I will use Hyperterminal to record the data that a device sends and then write the parsing routine offline instead of having to sit in the lab in front of the instrument.
RE: Excel Com port communication (TechnicalUser) 31 Oct 05 23:09. I've found this thread quite helpful. I'm trying to communicate with a lab instrument by an RS-232 serial comm port from Excel VBA. I've downloaded MSComm using GVF's post of 27 May '05, and registered the file by the method of tbl (Jan 05).
I got the control into my toolbox as suggested to farmcafe by tbl on 16 Feb. 05, but 'the control could not be created because it is not properly licensed'. I got some text to be inserted to the registry from the devhood site recommended by GVF (29 May '05), and tried saving it as a notepad file with a.reg extension as MisterCfromIT suggested on 18 Feb '05. It was identical to the first text he supplied as his example. I got the error message, 'specified file is not a registry script. You can only input binary registry files'. I'm working in Windows XP, not NT.
I do not know if that is why his method does not work. Can someone help me insert the appropriate license information to my registry?
I'm in unfamiliar territory in the registry so a little detail may be needed on my part. RE: Excel Com port communication (Programmer) 1 Nov 05 13:41.
To everone, thanks for all the information in this thread, I have been able to successfully create an application using mscomm as instructed so I simultaneously run 2 Excel files each pointing to a different port and exchange data on command through a null modem. What I really want to do is initiate the transfer by a trigger read in as a bit by one of the two applications through the parallel port LPT1. I am looking for the simplest way to read the parallel port in bidirectional mode by polling. I am running under XP. If anyone can point me in the right direction to do this I would appreciate it. Thanks again for this great thread! Rob RE: Excel Com port communication (Programmer) 8 Feb 06 19:11.
Thanks for response, I realized I may be able to pull this off by installing a generic text only printer using lpt1: and then using VBA to make it the active printer. I may then be able to check printer status and thus get a read of the input bits. Not sure if it will work or the overhead, but I'll try it over the next few days and let you know for posterity. I really appreciate your earlier work with the MSCOMM, it helped me quite a bit. In my implementation, I used the multimedia timer to me let me know 25ms after the receive buffer stopped receiving characters. Then I just read in the buffer and so far it looks pretty solid. RE: Excel Com port communication (TechnicalUser) 9 Feb 06 01:14.
Alan, Yes.provided the device you are sending to accepts ASCII strings (otherwise you will have to translate the information (hex or binary or whatever) before you send it. I usually put the string together before I send it, but I don't think that it's truly necessary. My personal preference is SendStr = nus & vbCR Userform1.MSComm1.Output = SendStr but the following should also work Userform1.MSComm1.Output = nus & vbCR The only reason I do it as shown in the first example is that I generally pass the string along to a sub which sends the string and gathers the response. This can be device specific and so collection of the response might also be device specific. In the snippet below.nus, SendStr and Response are assumed to be public variables. Sub BlahBlah() nus = Activecell.Value SendStr = nus & vbCR call SendAString(SendStr) MsgBox Response End Sub Sub SendAString(SendmyStr) with Userform1.MSComm1.InBufferCount = 0 'clear the buffer.Output = SendmyStr TheWait =.2 + Timer Do until Timer >= TheWait 'a pause that allows the device time to respond Loop Response = '.InputLen = 1 Do Response = Response &.Input Loop Until.InBufferCount = 0 End With End Sub Greg RE: Excel Com port communication (TechnicalUser) 11 Mar 06 02:01.
I am trying to expand on the script GVF sent on 10th Mar. I am using with Userform1.MSComm1.InBufferCount = 0 'clear the buffer.Output = SendmyStr TheWait =.2 + Timer Do until Timer >= TheWait 'a pause that allows the device time to respond Loop Response = '.InputLen = 1 Do Response = Response &.Input Loop Until.InBufferCount = 0 End With to send 'SendmyStr' and wait for a response comimg back. This works ok and I can check it against a known variable. However sometimes I get no response and it just hangs.
Is it possible to have a loop which checks for a response for a time limit and jumps out if it expires? RE: Excel Com port communication (MIS) 4 Apr 06 11:30.