logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 MSCOMM control troubleshooting guide & tutorial.

Posted on
6/28/2002
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
NT, 9x, 2000
Product:
5, 6





My background is in writing extensive serial communication programs. Most of them were written using MSCOMM communications control that has shipped with VB since version 2.0.

Thus, I see (and get asked) the same questions over and over again. In the same vein, same mistakes are committed countless times. This tutorial is a compilation of many emails I've exchanged with programmers around the world, as well as an attempt to address these issues, so that they do not trip others.

The question usually goes like this: I've tried everything, but the data is not getting through or MSCOMM is not working. Let me assure you, MSCOMM is the most bug-free component that Microsoft has ever released. The problem is your code, your hardware, and your connections. In other words, the problem is YOU.

So, now that you've acknowledged where the problem lies, let's solve it. Follow these suggestions below, not necessarily in this order.

  1. Know the hardware devices you are connecting. It is fine to go modem-to-modem, but what if you are connecting a PC to a device that requires this speed and that parity, etc

  2. Question: I am connecting between two PCs and nothing is coming out on the other end.

    A regular serial cable will not work. You need a Serial NULL Modem cable or a standard serial cable with a NULL modem adapter. You can get it at any Radio Shack. Or let me know - I'll send you one for US$100 + shipping & handling.

    Or the cable is busted. See below on tips to check whether the cable is broken.

  3. Question: I am connecting between two PCs and junk (unreadable characters) is coming out on the other end.

    Make sure the COMM port settings (i.e. baud rate, parity, etc...) on both PCs are the same. How do you accomplish that? Make sure that the Settings property for the MSCOMM control is identical on both ends.

  4. Question: The comm port settings are identical on both ends, but I still have garbage coming out on the other end.

    Most likely you are overwhelming the output buffer. Check the OutBufferSize property. Do not send more characters than the size of the buffer (unless you have HandShaking set to something other than 0). Wait for the buffer to clear after sending data (by checking the size of the output buffer), then send more.

    Comm ports are basically chips that are called UART.
    If you have an older machine, UART chip may not be able to handle a large amount of data at once. In addition, some of the older chips topped out at 57,600 bps. So starting a conversation at 115 kbps will yield junk.

    As a last ditch measure (I do not recommend this for anything but the most desperate of circumstances), go to Device Manager (in Win9x), click on the properties for the com port in question, go to Advanced and start playing with the Receive/Transmit buffers. I don't even think this method is available in NT, 2k, XP machines. Again, this is after you've explored every single other possibility known to man.

  5. Question: I am connecting to a custom/proprietary device that does some function (like a digital volt meter, taxi cab reader, etc anything really). I am sending it commands as specified in the manual, but it does not respond.

    Connecting to mysterious devices requires a bit of serial knowledge. I recommend finding a reference that indicates what each pin on the serial interface does, because this is HUGE when debugging custom devices.

    That said, let's see what could go wrong. The key here is knowing what the device requires.

    Does it need Handshaking to be enabled? If so, what type: software (Xon/Xoff), hardware (RTS) or both (very rare to nonexistent)? Set the HandShaking property accordingly.

    Does the DTR (Data Terminal Ready) line need to be on? If so, set the property.

    Does the RTS (Ready To Send) line need to be on? Set it then.

    What exactly does it mean to be ON? Basically, when you set it to ON or TRUE, the chip on the comm port sends electricity to that pin.

  6. Question: How do I know if the cable is broken?

    This maybe too high-tech for some here. The solution for this problem was invented by a former co-worker of my, who goes by the name of Mark Willson. Plug in the serial cable into the comm port. Now take a staple, and finagle it into the other end of the serial port, so that it touches both pins 2 and 3 (they are marked). Now open HyperTerminal to a COM port and start typing. If whatever you type echoes back, the cable is fine.

  7. Question: How do I send files from one PC to another?

    The details are beyond the scope of this article, but here are two suggestions. You can buy a commercial COMM control, which implements the popular file transfer protocols of yesteryear, like ZMODEM, YMODEM, XMODEM, etc

    Or you can roll your own. Here is an idea. Come up with a START_FILE and END_FILE data markers, so that the program on the other end can extract just the file. Generate CRC32 of the file and append it to the data stream. Then, on the other end, if the file matches the CRC32, then your transmission was successful. The receiving computer can send a FILE_OK data marker. If the sending computer did not receive the FILE_OK, then error has occurred in the transmission. This may sound simple, but I assure you that there are many things to worry about, particularly if you are sending data via an error-prone medium like wireless.

  8. Question: Will it be faster if I use Windows API for serial communications?

    No.

  9. Question: Is there any reason to use Windows API for serial communications?

    Not normally. However, if you feel that your life is too full of excitement, you can do in place of a depressant.

  10. Question: Can I use MSCOMM with .NET?

    Yes, you could. Even though MSCOMM is a COM component, Visual Studio .NET lets you use those types of component through a technique known as Interop. You don't actually deal with Interop, as Visual Studio hides it pretty well. So to the programmer it looks like another .NET control. It is not, however, enough to simply copy mscomm32.ocx to your .NET development machine. You actually have to have VB6 installed there as well. If you don't have VB6 installed, you will get a license error when attempting to instantiate MSCOMM.

  11. Question: Should I use MSCOMM with .NET? If not, what are the alternatives?

    Just because you could doesn't necessarily mean that you should. Because .NET talks to MSCOMM via the Interop layer, there will be a small performance penalty. Now if performance is not that big of an issue, you have no issues. There are two alternatives to the MSCOMM control. The first one would be the commercial native .NET communications controls from Sax and others. The second alternative is a class written by one of Microsoft employees that more or less mimics MSCOMM as far as the properties and the methods go. The advantages of this class? It is free and you already know MSCOMM. It was posted on MSDN a while ago. Grab it here.


    Update (December 8, 2003).
    Microsoft is distributing a Visual Basic .NET resource kit, which has a lot of great stuff for free. Included in the bundle is a free native .NET Serial Communications control from Sax Software Corp. This makes it a no-brainer. Get it while it lasts.




Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By mbuku. Posted on 2/19/2006 11:30:16 PM
Does all this apply to VS 2005 or just VS 2003?

#2. By Rizzo. Posted on 2/24/2006 8:48:22 PM
Most of this applies to Visual Basic 5/6. Questions 10 and 11 apply to VS 2003. As far as VS 2005, it ships with a Mscomm replacement called Serial. It's API is not the same but simple enough.

#3. By Rizzo. Posted on 2/24/2006 9:33:50 PM
Another tidbit to add to the article is that VS2005 supports registry-less deployment of COM components(on WinXp and higher), so if you choose to use MSCOMM with VS2005, you wouldn't have to register it on the target machine.

#4. By mozak. Posted on 2/24/2006 9:34:24 PM
Thanks.
Very cool article.

#5. By bhram. Posted on 2/27/2006 5:23:41 AM
hi, mine query is how am i receive data from serial port in vb using ms comm control

#6. By rizzo. Posted on 2/27/2006 6:24:47 AM
Answer to #5. Simply, execute the following:

dim s as string
s = mscomm1.input

The data will be in the variable s.

#7. By prabuddha. Posted on 3/7/2006 11:49:48 AM
i send some data from one end and i dont get them as a whole from the other end of my dialup program.Sent data been received as several portions though the buffer sizes are the same at the both the ends,What can i do?

#8. By rizzo. Posted on 3/8/2006 7:57:10 AM
#7. You can't just receive the data and be done with it. Setup some type of string variable to hold all the data. They either poll the comport via timer or respond to the event. As you get data, add it to the string variable. Then, you'll see your data.

#9. By archie. Posted on 3/13/2006 1:52:42 PM
I am using this set-up for the mscomm in my vb:
Private Sub Form_Load()
With MSComm1
.CommPort = 1
.Handshaking = comNone
.Settings = "57600,N,8,1"
.InputLen = 0
.InBufferSize = 1024
.InputMode = comInputModeText
.OutBufferSize = 512
.InBufferCount = 0
.RThreshold = 1
.SThreshold = 1
.PortOpen = True
End With
End Sub

on the other side was my microcontroller communicating with the computer program via uart, and i use an interrupt wherein when a data is available on the uart receive register of the microcontroller, it will execute the interrupt service routine like this:
#pragma interrupt
void isr_uart(void)
{
IRQ0 &= 0xef;
printf("v");
}

my problem is that im not receiving the character "v" on my computer after i send a character from my pc!

#10. By Anonymous. Posted on 3/14/2006 5:28:29 AM
Answer to #9. It doesn't look like you are sending anything from you PC - you are just setting up. Also another way to test is to do this from Hyper Terminal.

#11. By aimee. Posted on 3/16/2006 9:34:59 AM
if i am using the binary mode, how can i send a binary data? and what will be displayed when i received a data if i for example add that data to a listbox?

#12. By aimee. Posted on 3/16/2006 10:18:56 AM
if i am using the binary mode, how can i send a binary data? and what will be displayed when i received a data if i for example add that data to a listbox?

#13. By PRIYAN. Posted on 3/17/2006 1:46:56 PM
HOW CAN I CONNECT TO A TELEPHONE LINE AND RECEICE A TELEPHONE CALL AND SENSE THE TELEPHONE KEY PRESSES

#14. By Ebinezar. Posted on 4/7/2006 7:47:38 AM
hi experts..
this is ebi.. i'm working with microcontroller projects. i'm in need to communicate with microcontroller thro rs232. would u help me by givin ur valuable tips to write codings in VB


regards
ebi

#15. By Marian. Posted on 4/27/2006 7:16:23 AM
I actually wanted to clear the message display in Customer Display (VFD). May I know how? I managed to set text into that machine but cannot clear.. what is the command for that... I know that the command to set text is ocxname.output... may i know the command to clear the text display? Thanks

#16. By question. Posted on 4/27/2006 10:24:21 AM
I want to open a file on the front end(VC++) and transfer this file to other pc through serial port using MSCOMM.

#17. By Jayaruvan. Posted on 7/4/2006 2:08:10 PM
I have a device connected to serial port.It sends data continuously.Is there a way to determine when suddnly some one switched off that device or a line faliure such thing?

(I dont need any solution that involve timer okey.....)

#18. By Fluppe. Posted on 7/5/2006 10:58:19 AM
I have a couple of USB-Serial converters (each has 16 serial ports), but I noticed that you can only select up to COM16 with MSCOMM.
Is there a way around this limitation?

#19. By Author. Posted on 7/6/2006 1:33:12 AM
Answer to #17. This depends on the device. Sometimes when the device is turned on, it turns on RTS or the DTR pin on the serial port. I would create a test project and see what events occur in MSCOMM control when you turn on and off your device.

Answer to #18. Sorry, this is a limitation of the control. I'd get a 3rd party control from http://www.sax.net/

#20. By Alfred. Posted on 7/6/2006 1:43:42 PM
Help!
How can I send a signal to a specific pin of the serial port?
Thanks on advance

#21. By Peter. Posted on 7/6/2006 8:27:33 PM
Strange one this.. I use the com ports on a PC to communicate to a PIC processor with VB6. All works well until the PC crashes.. then if I do a hard or soft reboot I cannot communicate with the comm port. I found by trial and error that the only way my program would start again would be to disconnect the serial port, reconnect and then reboot..this solution works everytime.. I cant understand what unplugging/pluggin a connector does ?

Thanks

#22. By Author. Posted on 7/7/2006 2:49:14 AM
To #20. Look at the properties such as RTSEnable and DTREnable. You can't toggle all pins, just selected ones provided for by MSCOMM control.

#23. By charles. Posted on 8/7/2006 5:06:11 AM
how do i check whether the cable is plugged in or not in the computer i am using a board form that board i am reading data all are working fine but i don't know how to check whether the plug is connected or not

#24. By Author. Posted on 8/7/2006 5:58:17 PM
To #23. Find out what pins your device turns on when it is connected. Thus when it disconnects, those pins will go off (e.g. rts, dts, etc...) Create a simple test project and see what events fire in the OnComm event.

#25. By charles. Posted on 8/8/2006 8:19:29 AM
How to Find out what pins your device turns on when it is connected

#26. By Author. Posted on 8/8/2006 7:22:54 PM
Charles,

Read my previous comment. In the OnComm event, you can tell by the parameter that is passed into the event, exactly what pins are turned on.

#27. By JamesM. Posted on 8/12/2006 8:59:39 AM
I have exactly the same problem as Peter #21. VB6 talking to PIC. Chats happily for weeks on end. Reboot the computer and then nothing comes of the PC comm port. But only sometimes! MSCOMM code still runs fine with no errors - it just doesn't do anything. The error is intermittent which makes debugging hard. Many help sites say 'run terminal with a loopback'. This works but it works I think because terminal sets/clears a buffer that mscomm doesn't clear. I need to do some more experiments on this...

#28. By Author. Posted on 8/12/2006 8:51:35 PM
JamesM, have you perhaps explored the possibility that the hardware is faulty. Faulty, not as in broken, but as in badly designed?
Try a plugin COM port (like USB com-ports) and see if that works.

#29. By JamesM. Posted on 8/13/2006 9:23:26 AM
Thx Author for the info. I fixed the problem - a virus had renamed critical components in VB. A scan with AVG and a reinstall of VB and all working now. BTW if anyone wants some VB serial port code and/or pic code please email me on moxhamj at internode.on.net

#30. By hhj. Posted on 8/13/2006 6:21:12 PM
How can i send a file from one Pc to another pc with vb6?
please help me and send vb code
tank you

#31. By hhj. Posted on 8/13/2006 6:21:47 PM
How can i send a file from one Pc to another pc with vb6 and modem?
please help me and send vb code
tank you

#32. By Author. Posted on 8/14/2006 5:50:08 PM
hhj, see question 7 in the article.

#33. By vamsi. Posted on 9/4/2006 6:01:03 AM
hi i am vamsi i am doing a project on serial communication and want information about how to use a MSCOMM in .NET. i am unable to find out MSCOMM control in .NET can any one give me code how to declare mscomm in .net and how to do the project actually the project is sending a sms fromj a mobile to another mobile connected to pc and this is send and also receive message at bothe ends i want code and some guidence how to use mscomm or any other equivalent component in .net
thanks please help me
vamsi

#34. By Author. Posted on 9/4/2006 6:38:40 AM
Vamzi,

Have you looked at your Visual Studio Toolbox? You'll see a Serial control. Use that.

#35. By Kumaravelu. Posted on 10/5/2006 8:09:10 AM
Two pc systems connected in a null modem connection (with handshaking signals), in which, one of the system is always receiver mode and the other is transmitter mode. The program which I developed in VB script is working fine, but randomly at one stage data transmission is not taking place. The data is available in the ms-access database. I have 500 records stored in the data base. For example , during the data transmission after 380 records transmitted the next 381 records onwards, transmission could not taking place. Some times 270th records onwards, 7th records onwards etc.. Kindly help anybody in this regard.

#36. By Author. Posted on 10/9/2006 7:08:44 AM
Answer to #35: Most likely your output buffer gets overloaded. Keep your buffer clean and check its length before sending the next record.

#37. By Raja S. Chaudhary. Posted on 10/18/2006 9:28:42 AM
Hello,
I have to write a program. In which I have to give output via serial port in 6 line and 41 char length in matrix form. Here i have to use a text editor and then this file i have to send in given matrix form.
I know how to send a data on port. but how in maxtrix form ?.
Please help me out.
Regards.

Raja S.

#38. By Lucko. Posted on 10/23/2006 9:35:50 PM
I'm using excel macro and have real problems. Hire is the code:

Sub Button1_Click()

Dim comm As Object
Set comm = CreateObject("MSCommLib.MSComm")

run = 1
ts = 0
tk = 0
sporocila = 1
stevilka = 1
stevilkak = 1

Do
ts = ts + 1
tk = tk + 1
If ts = Cells(2, 3) Then
sporocila = sporocila + 1
stevilka = stevilka + 1
If Cells(stevilka, 1) = "" Then
stevilka = 2
End If
If Cells(sporocila, 7) = "" Then
sporocila = 2
End If
'posiljamo SMS
SMS = Cells(sporocila, 7)
naslov = "AT+CMGS=""" & Cells(stevilka, 1) & ""
comm.CommPort = 1
comm.Settings = "56000,N,8,1"
comm.PortOpen = True
comm.Output = "AT"
comm.Output = "AT+CMGF=1"
comm.Output = "AT+CSCA=""+38640441000"""
comm.Output = naslov
comm.Output = SMS

End If

Application.Wait (Now + TimeValue("00:00:01"))

DoEvents

Loop While 1 = run

End Sub

This dosen't work. I got error "run-time error '429': ActiveX component can't create object. I'm using this program for sending SMSes with AT comands...

I'm making variations(faund with Google) to:
Dim comm As Object
Set comm = CreateObject("MSCommLib.MSComm")
but can't find one that works...

#39. By Kumaravelu. Posted on 10/25/2006 10:08:26 AM
Dear sir/madam,
Thanks for your reply to my earlier correspondence. There after i faced a new problem in my vb program. I created one database with one datatable for updating the data and the same tabel is accessed in other application. Kindly advise me when to open and close the table while updating and while accessing the tabel in other application. Is it may the reason for me not reading any data at one instance onwards from the master table to other application?. Please kindly advise....

#40. By Bechara. Posted on 10/26/2006 11:43:51 AM
I have a problem to connect mobile to a pc thru cable using MSCOMM.
Not all mobiles are supported even with the "ATZ" command is the problem from the mobiles ? Should I find another component ? or should I switch to use API ?

#41. By Biswajit Hira. Posted on 10/30/2006 7:35:18 AM
i am sending a big file via radio modem using mscomm in VB 6.0, after sending a portion of that file CTSholding property changed as FALSE. But I can't refresh the ctsholding as TRUE and can't send the rest part of that file. what should i do?

#42. By Susan. Posted on 11/8/2006 11:41:47 AM
How do I monitor transmit and receive buffer of serial port using VC++ ?

#43. By Susan. Posted on 11/8/2006 11:41:54 AM
How do I monitor transmit and receive buffer of serial port using VC++ ?

#44. By jane. Posted on 11/15/2006 3:53:12 AM
I need to send a signal which has no value but will be set 0 volt, is it possible?
thank you.

#45. By Author. Posted on 11/15/2006 4:15:18 AM
#44. This depends on how the device on the other end receives such notification. Usually, I would set the RTSEnable property to False.

#46. By Ravindra. Posted on 11/21/2006 7:54:37 PM
hai......i wish to made small project on VB-6.0,that was "made a chat between two computers via serial cable or any" .... my question is How can made it? waht are the VB (MSCOMM control)codes for this?....

#47. By sandhya. Posted on 11/29/2006 11:33:52 AM
Question:I want communicate between pc to pc using visual basic 6.
so give me somr reference meterials and later i want to communicate between pc and device compatible with the standard IEC62056.Please give me simple link or reference material.

#48. By ken. Posted on 11/29/2006 11:00:35 PM
I have been using this control for years now with much success but have been having one problem. Perhaps someone else has had to deal with it. I seem to get overrun errors if I am also running a USB device with a lot of activity. It's as if Windows is not servicing the com port fast enough. Is there a way to up the priority or service rate. My current solution is to unplug the USB device.

#49. By Author. Posted on 11/30/2006 7:57:45 AM
To #48. Ken, your analysis is probably correct, but you should test it first. Increase the buffers (both input and output) to the max and see whether it takes longer for the software to fail. If that is the case you might be right.

There is another possibility. The onboard USB chip maybe emitting more "noise" than normal and UART ports are succeptible to this type of noise and it causes them to randomly fail.

Try using a different USB port or a different COM port, so that they are not too physically close to each other.

#50. By karthi. Posted on 12/13/2006 1:23:28 AM
HI,
we got one application which connect to gameboy devive thru mscomm control by vb..this software is running in soem computers(windows xp)but the same time is not running some computers(windows xp). both system has same operating system..is there anything basically needed by xp to run software(mscomm control + vb) ? i install vb in that system i run the project, there i found the chr() in not working .bcoz before send the byte value to mscomm.output. i make it to char by chr() function.but this function return nothing in this computer..but i run the same project other computer(this one the software working properly)., the chr() function return value , then i can send to mscomm.output then working properly.why some computers not supporting chr() function(install vb6.0) ?

thanks in advance..

with regards,
karthji..

#51. By Saikiran. Posted on 12/18/2006 6:21:10 AM
Dear Sir/Madam,

I have gone through your Suggetions its really very helpful. I am doing a VB project
which i need to send files through Serial communications .Can you please be specific regarding this topic?As i require to implement it as soon as possible.Here you are given regarding this topic but not much specific.Please suggest me how to use data markers or if you have any other approach, please provide me.

Thanks & Regards
P.Saikiran
SYLN Technologies,
Hyderabad.

#52. By sandhya. Posted on 12/18/2006 9:13:48 AM
How to use the interrupt and polling mode in serial communication in vb6 taking 2 Pc's as communication equipments.
Please give the src code in vb6 for interrupt and polling mode

Thank You in Advance

#53. By sandhya. Posted on 12/18/2006 9:14:08 AM
How to use the interrupt and polling mode in serial communication in vb6 taking 2 Pc's as communication equipments.
Please give ME the src code in vb6 for interrupt and polling mode

Thank You in Advance

#54. By namritha. Posted on 12/21/2006 10:08:49 PM
how can i use MScomm control to connect a pc to phone?

#55. By Haja Nasurudeen. Posted on 12/22/2006 1:16:12 PM
Dear sir,
How to connect a multi phone line by using single modem through VB coding. How can I identified that this line is activated now and others are idle. I'm maiting for your kindly reply.
Thanking you
By yours sincerly
M.Haja Nasurudeen.

#56. By starry. Posted on 12/26/2006 2:52:51 PM
hi there, hope someone can help me here..
im doing a project,involving two ports of the computer. first, i have a device that
connected to the pc through serial port(input),second the parallel port(output) will
transfer the voltage from the device to the zilog microcntroller.
My question here is how can i use visual basic codes to read
input from the device from the serial port and transfer the voltages in parallel
port(output).
Send me a code how to do this.
I would be very grateful if i could get this code.. its very very urgent..thanks!!


pls. send the code to my email add, maryethel_magtibay@yahoo.com or ethel_star00@yahoo.com
thanks...

#57. By ian. Posted on 1/5/2007 3:41:12 PM
hi, can you show me a program in visual basic that sends numbers from 0 to 10 in ascii code. I am planning to send it via rs232 port..tnx

#58. By Boo Yan Jiong. Posted on 1/7/2007 4:00:00 PM
thanx you very much ya...

#59. By elpedro. Posted on 1/10/2007 1:07:18 PM
Hi there, looks like i am not the only one struggeling with mscomm. I have got the following problem: I am communicating with an external microcontroller and while debugging i am printing every telegram that i send to the uC. After i found to many receifed telegramms that i did not asked for i found out that the pc is repeating some telegrams for its own without showing them with debug.print ... So.. I was sniffing the sent data with another program that observed the rs232. Maybe there is something wrong with the output-buffer? Here ist the code that i use for sending:

WLen = TxTel(i, 2) And 255 'len aus tel(bytes ohne kopf)
WLen = WLen / 2 + 3 'len in words total
ReDim OutBuf(WLen * 2 - 1) 'array dimension
For j = 0 To WLen - 1 'build tel in OutBuf
LoB = TxTel(i, j) And 255 'loByte
HiB = (TxTel(i, j) And 65280) / 256
OutBuf(j * 2) = LoB
OutBuf(j * 2 + 1) = HiB
Anz = Anz + Trim(Show_Hex(HiB)) + Show_Hex(LoB)
Next j
VarTx = OutBuf
Rs232.Output = VarTx 'send
SentTels = SentTels + 1
If TxTel(i, 2) <> QTACK Then
Anz = TelTyp(TxTel(i, 2)) + Anz
Debug.Print "Sent Tel from PL : " + CStr(i) + Anz + Timestamp
End If

I would be very happy about some suggestions. Thanks in advance

#60. By JamesM. Posted on 1/11/2007 12:16:46 AM
Re #61 Elpedro, is rs232.output the new vbnet standard? See Q10 and 11 at the top of this page re .net, but I have gone back to vb6 because too many commands in vb6 were not supported in vbnet. In vb6 the code to output a string is:
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False:' in case some other code left it open
MSComm1.Settings = "1200,n,8,1":' 1200 baud, no parity, 8 bits, one stop bit
MSComm1.CommPort = "2":' comm port 2 (mouse uses com port 1 on older PCs)
MSComm1.PortOpen = True":' open the port
MSComm1.Output = "Hello World":' send some text. Or turn an array into a string and send the string.
MSComm1.PortOpen = False:' close the port

Re #59, re sending data as ascii, if you send an A it sends the number 65 to the serial port. If you want to send this as ascii, do you mean send a "6" and then a "5"?

Re #58, yes, you can do all that in vb and I have built such things, but they are huge projects and you need to be pretty good at programming. Can you describe what you want to do in a bit more detail?

#61. By Rick. Posted on 1/12/2007 5:55:27 AM
Hy, I am wondering if you might be able to help me. I am writing a program for a client that needs to dial up to one of a couple of different BBS locations and transmit or download files. I am writing the software in Visual Studio 2005 and have been trying to find a component that provides the file transfer methods already as well as supports Zmodem. So far what I have found out there is really dissapointing, components with half hazard documentation, or components that just simply dont work, or ones that cost hundreds of dollars. I looked at trying to use the Serialport control, but I could not find any methods within it to provide file transfer methods. Is there a control that I should be looking at, that I can not find, or am I missing something here. Please help, I have been getting increasingly frustrated over this and really need to find a resolution. If somone out there has some sample code out there writting in VB.NET 2005 that provides file tranfer capabilities using the serialport control and zmodem protocol, I would be ever so grateful if they could pass it my way. Rbrown@asysbs.com

#62. By Urmila Shind. Posted on 1/13/2007 6:28:25 AM
How Different Type of MsComm Port join One pc in vb

#63. By aboobacker. Posted on 1/19/2007 1:55:47 PM
I am using a customer display how to send commands to erase the display and positioning

#64. By tapan mandi. Posted on 2/20/2007 3:23:42 PM
hi, i want to transfer data comming from serial port to microsoft excel 2003 into two columns alternatively and finally plot a graph by using visual basic 6.0. please help me.

#65. By fabbio. Posted on 3/1/2007 9:13:07 AM
"Let me assure you, MSCOMM is the most bug-free component that Microsoft has ever released"

from microsoft.public.development.device.drivers newsgroup,

"mscomm.ocx cannot handle pended async reads (even when they are sent async).
this is a BUG in the component. in this case you have to complete the read
synchronously if there is data"

doron.holan@microsoft.com

#66. By barrios. Posted on 3/7/2007 6:07:39 AM
Hi..I am experiencing some delay problems for the RTS as described by this article.
http://www.vns.nl/articles/7
It occurs for WindowsXP and MSComm Control. I used an oscilloscope and witnessed this delay in switching RTS.

I would like to know if this is really the way MsComm is? Also, is there a better method to control the serial communications in order to solve this issue?

#67. By swarna. Posted on 3/9/2007 5:39:03 AM
hi, i am doing an embedded sys proj, wher i hav to communicate a pc to the microcontroller to get the info and store it in a database. can i use mscomm? how do i connect the database and the mscomm recieved info?? please help!!!

#68. By Thomas. Posted on 3/9/2007 1:05:08 PM
if you add HKEY_CLASSES_ROOT\Licenses\4250E830-6AC2-11cf-8ADB-00AA00C00905]@ = "kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun" to the regidtry you will solve the license problem in VB NET 2003
for more info look at
http://www.yes-tele.com/mscomm.html you will

#69. By saqib. Posted on 3/9/2007 8:21:43 PM
plz, tell me more about the serial and parallal por

#70. By Stuart. Posted on 3/16/2007 1:11:00 AM
Hi, I'm using vb6 to write a program for a serial device used to measuring particles in oils. I have the mscomm setup, and can receive the data to a textbox; it comes out as 1000000020000000300000004000000050000000600000007000000080000000
i then need to get this data into 8 seperate label captions and/or variables. i've tried using split() on both this data stream and a seperate stream which sends the data back as
10000000|20000000|30000000|40000000|50000000|60000000|70000000|80000000
then using "|" as the delimiter. the array it creates then has an out of range error after i try to retrieve the data from the array.
Code::

If MSComm1.CommEvent = comEvReceive Then
sBuffer = sBuffer & MSComm1.Input
sBuffer = Replace(sBuffer, Chr(13), vbCrLf) 'removes endline char,creates new line
sBuffer = Replace(sBuffer, Chr(33), "") 'removes !
If lblStatus.Caption = 2 Then 'checks for data request command has been sent
Result1 = sBuffer
Result1 = Result1 & MSComm1.Input
Result1 = Replace(sBuffer, Chr(33), "")
mystring = Split(Result1, Chr(13), 8)
lbl4dia1.Caption = mystring(0)
lbl6dia1.Caption = mystring(1)
lbl10dia1.Caption = mystring(2)
lbl14dia1.Caption = mystring(3)
lbl14dia1.Caption = mystring(4)
lbl25dia1.Caption = mystring(5)

i have also tried using Mid(Mystring,1,8)
Mid(MyString,9,8) etc
but it wont isolate the section, it just prints the whole string???
any help would be much appreciated :)

#71. By Gnekker. Posted on 3/22/2007 11:42:35 AM
I want to connect to Mettler balance, using Excel VBA. Here is my code:

Private Sub MSComm1_OnComm()
Dim MyBuffer As Variant, Arrived As Integer
Arrived = MSComm1.InBufferCount
MyBuffer = MSComm1.Input
(some other stuff)
End Sub

(I put the breakpoint after "MyBuffer = MSComm1.Input")
Funny thing is, when balance sends data (24 character string), oncomm event is triggered, I can check InBufferCount and Input in debug mode, just putting mouse over it (input only once), I can also insert Watch to review data, but I can't assign data to variables - Arrived and MyBuffer are still empty!

#72. By gorji. Posted on 3/31/2007 8:28:38 AM
hi dear

if you have vb source code to send sms please tell me.
please send me to my email

#73. By John. Posted on 4/12/2007 11:14:46 AM
I'm using two MSComm controls in one application for two devices with serial interface: COM1 voltmeter (reading) and COM2 - oscillator (writing). Most of time connection PC-voltmeter is good, but sometimes (one in a hour) it is lost for unknown reason. Is there any ways to catch and restore broken connection with minimal data lose?
Thank you

#74. By SWAPNIL M GHOLAP. Posted on 4/15/2007 2:23:31 PM
RESPECTED SIR ,
I AM STUDENT OF THIRD YEAR,STUDYING IN INSTRUMENTATION AND CONTROL ENG.
SIR,I AM DOING PROJECT, IN WHICH I WANT TO READ THE SIGNAL FROM COM PORT1 THROUGH RS232 PARALLEL(DB25)AND THEN WITH RESPECT TO TIME,I WANT TO DISPLAY GRAPH ON VISUAL BASIC 6.0 SOFTWARE.
I WANT CODE IN VB,WHICH WILL DISPLAY THE GRAPH WHEN THE INPUT WILL CHANGE,GRAPH ALSO CHANGE FROM RS232(DB25). I HOPE U WILL DEFINEATLY SOLVE MY PROBLEM.I AM WAITING
FOR UR RESPONSE TILL WEDNESDAY.

#75. By Mallesh. Posted on 4/19/2007 7:10:21 AM
IS there any event that automatically fires as and when serial port receives some data
i.e,. Some thing like OnMsComm event of MSCOMM control in VB6.
Presently iam working on Vb.net

My application Includes a Flash card reader connected to PC
as and when an employee flashes his card an unique number is sent to the serial port
which identify that card in that regard i need such event that automatically fires
when an employee flashes the card

please do Help me


Thanks in Advance
Regards
mallesh

#76. By pranses. Posted on 4/22/2007 7:48:52 AM
hi
i'm happy to see your site and i'm going to learn more about mscomm
please help me
i don't know nothing a bout this topic.

#77. By Adrionne Winfrey. Posted on 5/1/2007 5:56:47 PM
Hi, I am using this segment of code in a program to communicate from a PC to a microcontroller via serial port. Only my VB code will not send data nor does it make it to the second Console.Writeline statement where items will actually be read in. Do you have any suggestions?

I know for a fact that my microcontroller is accessing the serial port. I was able to see my data in hyperterminal. The info stored from my microcontroller program should be held after I close it; I then download my VB code and nothing happens.

Module Module1
Sub Main()
Dim Data As String
Data = "Test"

Console.WriteLine("Writing the following data to COM1: " & Data)
SendSerialData(Data)

Console.WriteLine("Read the following data from COM1: " & ReceiveSerialData())

Console.WriteLine("Press ENTER to quit")
Console.ReadLine()
End Sub

Sub SendSerialData(ByVal data As String)
' Send strings to a serial port.
Using com1 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM1")
com1.WriteLine(data)
'com1.Close()
End Using
End Sub

Function ReceiveSerialData() As String
' Receive strings from a serial port.
Dim returnStr As String = ""

Using com1 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM1")
Do
Dim Incoming As String = com1.ReadLine()
If Incoming Is Nothing Then
Exit Do
Else
returnStr &= Incoming & vbCrLf
End If
Loop
com1.Close()
End Using

Return returnStr
End Function
End Module

#78. By sherry. Posted on 5/4/2007 6:54:15 PM
I created a program in vb6 that is using mscomm. It works when I open the program and run it. It does not work when I use the .exe program. Can you help me?

#79. By Andy Carmichael. Posted on 5/17/2007 1:22:01 PM
Is it possible to run MSCOMM32 legacy on a laptop running Vista ? The laptop has no RS232 ports -only USB?

#80. By Leow. Posted on 5/21/2007 6:27:14 AM
Dear Sir,
I am using mscomm command on my VB6, it work great ( transmit and receive ) on my desk top computer.( even on usb to serial converter, it work great )

But, when i run my application on my note-book ( true COM1 port ), it not working ONLY on transmit data. ( it work great on receive )

I also try on others note-book, it not work on transmit data.
My OS is Window 98 and Xp

Please advice.
Thank you.

#81. By Leow. Posted on 5/21/2007 6:27:32 AM
Dear Sir,
I am using mscomm command on my VB6, it work great ( transmit and receive ) on my desk top computer.( even on usb to serial converter, it work great )

But, when i run my application on my note-book ( true COM1 port ), it not working ONLY on transmit data. ( it work great on receive )

I also try on others note-book, it not work on transmit data.
My OS is Window 98 and Xp

Please advice.
Thank you.

#82. By Abdul Kadir. Posted on 5/29/2007 11:03:44 AM
I understand that the ontrol only supports ports 1 to 16. what if my poret (virtual) is allocated a COMM port number of > 16 ?

Is there any way round this?

#83. By Anonymous. Posted on 5/29/2007 4:57:37 PM
To #83. The only solution is 3rd party control, like those mentioned in the article.

#84. By Saikiran. Posted on 6/18/2007 7:26:52 AM
Hello EveryBody,

I am doing a project which deals communication in VB 6.0.Requirement is like this:
1) i have to send file having size <= 1MB in even second
2) I have to receive Some Commands from other System in ODD Second.
My Problem is : I could able to send file through MSCOMM successfully in 14 seconds of file size 82Kb but our client wants even for 1MB to be sent in maximum of 2 seconds.

For that they have given pCOMM.dll which is MOXA based RS-422 communication. But i dint acheive the requirement. Can any one tell me the procedure to send Maximum of 1MB file in less than or equal to 2 secondsusing RS-422 communication in VB 6.0.

Thanks and Regards in Advance.

#85. By Michael. Posted on 6/18/2007 12:56:01 PM
I have a problem using mscomm with my cdma modem. it can send data but when recieving data it reports "error reading comm device". this is my code :

Private Sub Command1_Click()
Dim buff As String
Dim buff1 As String
On Error Resume Next
MSComm1.CommPort = 6
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
' Tell the control to read entire buffer when Input
' is used.
MSComm1.InputLen = 1
' Open the port.
If MSComm1.PortOpen Then _
MSComm1.PortOpen = False
MSComm1.PortOpen = True

buff = ""
buff1 = ""
MSComm1.Output = "ate"
t = Timer
Do
buff = MSComm1.Input
buff1 = buff1 & buff
Loop Until InStr(1, buff1, "OK", vbTextCompare) Or Timer - t > 20
Text3 = buff1


End Sub

if i use other program to analize the comm port there is no stop bits and parity information like when we use comm serial port?? do i have to use handshake??

#86. By David. Posted on 6/21/2007 7:25:19 AM
HI

I am new to VB6 and I am having trouble in using the COM1 port. I have an IOTech serial to GPIB converter to talk and listen to instruments of varoius sorts. I have written many Quick Basic applications useing the OPEN etc. statemnet and I have had no problems with COM1 communications. My open statement goes like this :-

OPEN "COM1:9600,N,8,2" FOR RANDOM AS 1

The IOTEch RS232 requirements are listed as :- 9600 baud, 8 Data bits, 2 stop bits, No Parity, Serial terminator CR/LF, Echo Disabled, RTS/CTS Handshake.

I have added the comms to the tool box, dragged it to the form, setup the properties and tried several simple programm lines in the form1.

MSComm1.PortOpen = True
MComm1.Output = "OUTPUT 30;F0R2X"

I had hoped to get the simple output string "OUTPUT 30;F0R2X" sent, but nothing ever happens the IOTech leds do nothing. I have tried all combinations in the properties box and get nowhere.

Any help would be very much appreciated.

Regards.

#87. By kaushik. Posted on 6/21/2007 11:15:35 AM
Sir/Madam
my problem is:
I am using orgms="AT+CMGS" & chr(27) etc
mscomm.output = orgms etc
when I step passed this line and place the mouse curser on the mscomm.output
instead of showing "Property is write
only".
Is this the reason I appear to be unable to send data out my com port.
Thanks kaushik

#88. By kaushik. Posted on 6/21/2007 11:15:45 AM
Sir/Madam
my problem is:
I am using orgms="AT+CMGS" & chr(27) etc
mscomm.output = orgms etc
when I step passed this line and place the mouse curser on the mscomm.output
instead of showing "Property is write
only".
Is this the reason I appear to be unable to send data out my com port.
Thanks kaushik

#89. By romany. Posted on 7/1/2007 9:47:35 PM
my problem is serial comm bet computer and microcontroller by vb6
i can send to microcontroller but i cannot recieve any thing
can yu send me code to recieve from microcontroller
thanks for your help

#90. By romany. Posted on 7/1/2007 9:47:44 PM
my problem is serial comm bet computer and microcontroller by vb6
i can send to microcontroller but i cannot recieve any thing
can yu send me code to recieve from microcontroller
thanks for your help

#91. By Kuntal Mukherjee. Posted on 7/11/2007 7:58:06 AM
I want to connect my PC with telehone. There will be database in MS access and there say 100 telephone number is stored. Now how can the calls will automatically through one by one

#92. By Remya. Posted on 7/24/2007 7:07:53 AM
I'M WORKING WITH VB6.0.I HAVE A TABLE CUSTOMER.MDB.IN THAT THERE IS A FIELD LOAN.I WANT THIS.
WHEN THE LOAN AMOUNT EXCEEDS A PARTICULAR AMOUNT,AUTOMATICALLY CALL SHOULD BE CONNECTED
TO THE CUSTOMER TAKING PHONE NO FROM THE CUSTOMER TABLE.
HOW CAN I CONNECT TO A TELEPHONE LINE AND RECEICE A TELEPHONE CALL AND SENSE THE TELEPHONE KEY PRESSES.
I WANT TO KNOW WHEN THE CUSTOMER TAKES THE PHONE,HOLDS,DISCONNECTS ETC...CAN U PLZ HELP ME...

#93. By Jill. Posted on 7/27/2007 1:00:53 AM
I am trying to automate the process of looking in the device manager to find the com port that my device is assigned to. For example: MSComm1.CommPort = X. I am using VB 6.0 and I don't want to hard code the com port. Does anyone have any ideas?

Thanks,
Jill

#94. By Jill. Posted on 7/27/2007 1:03:30 AM
I am trying to automate the process of looking in the device manager to find the com port that my device is assigned to. For example: MSComm1.CommPort = X. I am using VB 6.0 and I don't want to hard code the com port. Does anyone have any ideas?

Thanks,
Jill

#95. By Dr_Acula. Posted on 7/27/2007 3:04:56 AM
Re Romany #89 try http://www.geocities.com/drvernacula/serial_port_communications_with_.htm which is the code I used to test the serial port. First send a byte. Then do a loopback test. Then try the microcontroller. I use picaxes as they are easy to interface with a PC.
Re #94 the usual comm port is 2, as the mouse takes comm port 1. But that wouldn't be true if using a USB mouse. There is no simple test as the computer doesn't 'know' what is connected to its comm port (unlike USB where each device has an ID). One solution is to write code where the user can easily select which port and the program saves this in a data file. Another solution is to connect your peripheral device and have the PC poll the serial ports in turn waiting for a reply. If there is a timeout and error trapping in the VB code it will timeout on ports that don't exist or haven't got anything connected.

#96. By lisa. Posted on 8/3/2007 7:15:27 AM
hi
i want to connect telephone line whith our technology like visual basic 6.0 ? how to detect phone and which control we can use for that

#97. By Bruce. Posted on 8/17/2007 4:07:52 AM
Hi, I am using the MSComm control in VS2005 VB.NET and I am having a hell of a myserious problem. :) I am collecting data at an extreme rate of 200/sec using the event driven OnComm event and sending out data on a average of 1/10sec. The problem is that the port dies after aprox 20 min or more of operation. I have monitored the system resources with perfmon and no leaks. And the port consistantly dies WITH ABSOLUTELY NO ERRORS at the same point every time, when the data is sent out (after 20 min of operation at some random point). No errors at all! other parts of the program continue to run. Have you heard of this before?


Delegate Sub SetCommCallback()
Dim CommCall As New SetCommCallback(AddressOf SerialComm)
-------------------------------------------------------------------------------------
Private Sub ForceComm_OnComm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ForceComm.OnComm
Try
If Me.AllowCommunication = True Then
Select Case ForceComm.CommEvent

Case 1 ' There are fewer than SThreshold number of characters in the transmit buffer.
MsgBox("There are fewer than SThreshold number of characters in the transmit buffer.")
Case 2 'Received RThreshold (1 Char) number of characters. This event is generated continuously until you use the Input property to remove the data from the receive buffer.

'Running
Me.Invoke(CommCall)

End Select
End If

Catch ex As Exception
ErrLog.WriteToErrorLog(ex.Message, ex.StackTrace, "Error")
End Try
End Sub
---------------------------------------------------------------------------------------------
Private Sub SerialComm()
mybyte = ForceComm.Input()
'rest of data processing code........
End Sub

#98. By Chris. Posted on 9/3/2007 7:36:29 AM
I am very new to VB programming. I am about to develop a seríal communication application that has to be used on many colleagues at work. If I use mscomm component, should this component be installed on all machines that use my application? If so, how can I develop an application which doesn't need any additional installation?

#99. By sudhir. Posted on 9/3/2007 7:54:40 AM
I have written a code to transfer a textbox data to another textbox but It not
working.I don't when MSComm1_onComm event takes place. Please guide in this regard

#100. By Yeoj. Posted on 9/18/2007 5:32:25 AM
Hey, I really need some answers regarding my project for now. I have here a SmartCard Reader having a connection to Comm Port. I try to use MScomm component but I dont receive any response on the OnComm event of the Mscomm...

#101. By fufu from RO. Posted on 9/21/2007 6:02:21 AM
i doing GPS now i able to show my information on hyperterminal, but now i wish to use visual basic 6.0 to display my information rather than hyperterminal. got any suggestion or some code can show to me? how to transfer/get my information to my vb6.0 textbox

regard
kenneth

#102. By Rich. Posted on 9/25/2007 1:45:27 AM
Anyone have any ideas on how to recover from a framing error? The program seem to stop receiving any data after that point

Thanks Rich

#103. By Author of the Article. Posted on 9/25/2007 7:45:09 PM
To #102 Rich. As far as I know, the only way is to close the port and reopen it.

#104. By joe wazen. Posted on 10/22/2007 10:54:22 AM
Dear Mr. Robert

it was very helpful reading your tutorial but there is one problem i couldn't solve and its that MSComm does not work with usb (http://support.microsoft.com/kb/832678) what should i use as an alternative?it would be great if you could help

Regards,
Joe Wazen

#105. By James Moxham. Posted on 10/23/2007 12:38:39 AM
The world seems to be moving to VB.Net and serial port comms is easier with VB.Net. Example and code is at http://www.instructables.com/id/Control-real-world-devices-with-your-PC/ There are a few traps - eg you can't put the bytes into a string and send the string otherwise ASCII values from 128 to 255 get turned into ASCII value 63. But the workaround is to put all the data into a byte array and send the entire array and the code actually works out simpler. VB.Net is free so grab it while Microsoft is giving it away!

#106. By Author of the Article. Posted on 10/23/2007 6:59:47 AM
To #104 - Joe Wazen.

Unfortunately I have no alternative. Serial Ports are the thing of the past and you must accept it. If you have to develop for a comm port, do it on a desktop pc and buy yourself a PCI comm port card.

The USB comm ports are weird in a way, most of the time they work fine, but sometimes they don't.

Regards,
Robert

#107. By Tapan. Posted on 10/30/2007 5:55:40 AM
hi
i am working with visual basic6.0 at initial stage. i want to read a text file having data 367, 436, 780. Then i want to store third data to excel.
How can I do it?
anyone can help me?
Thank you
Tapan

#108. By Tapan. Posted on 10/30/2007 9:32:33 AM
hi
i am working with visual basic6.0 at initial stage. i want to read a text file having data 367, 436, 780. Then i want to store third data to excel.
How can I do it?
anyone can help me?
Thank you
Tapan

#109. By Anonymous. Posted on 11/29/2007 8:45:57 AM
How can i transmiitted data between Computer and Customer display device using .net (vb.net) code.

#110. By Avee. Posted on 12/5/2007 1:34:23 AM
when I created VB6.0 already ,but I can't setup it into window98(Could u help me?)

#111. By rohit. Posted on 12/28/2007 8:52:32 AM
iam calling from modem to mobile phone i am listening but at mobile phone voice is not detected

#112. By Muhamad. Posted on 1/2/2008 7:38:32 AM
please i want to use the MScomm control of visual basic 6 but i want to let it receive the data only after receiving all bits,
Best regards

#113. By K.G. Posted on 1/30/2008 3:21:12 AM
I am a newbie on mscomm vb6, can you please email me some links or books to read up regarding serial port rs-485 transmitting hexa from a controller to be manipulated and send to a display board to be displayed. thank you.

#114. By Michele. Posted on 2/15/2008 6:33:29 PM
I have a vb6 program communicating with a weight scale. This program runs on several pcs and communicates with the scales without any problems. BUT, there is one pc that will run for several weeks with any problems, then it will not communicate with the scale. The program no longer sees any communication coming from the comm port. Opening hyperterminal verifies the comm port is communicating. The pc has been changed several times. Any suggestions to this problem??

#115. By anoop. Posted on 2/26/2008 2:11:43 PM
hai.......my name is anoop..................
i want to know about how to read the pulse of buttons in the telephone
plz help me................................

#116. By newxplorer. Posted on 3/1/2008 6:09:32 PM
this is how i transmit my data via rs232
Private Sub CmdOpen_Click()
MSComm1.CommPort = Val(Text1.Text)
MSComm1.Settings = "9600,N,8,1" '9600=baud rate N=no parrity 8bits 1 stop bit
MSComm1.InputLen = 0
MSComm1.PortOpen = True
Shape1.FillColor = vbGreen
End Sub

Private Sub cmdSend_Click()
Dim del As Integer

For del = 1 To 800
MSComm1.Output = "B"
Next

End Sub

but how and i going to receive data from rs232? (e.g: data will print at a text box)
what is the code?

#117. By James Moxham. Posted on 3/2/2008 9:39:13 AM
newexplorer - I wrote this all up at:

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/

vb.net is superseding vb.6 and the code is slightly different, but the big plus is that vb.net is free. Displays the serial data in a label on a form, but you can simply change that to a text box and write it to text1. instead of label1. It is pretty easy to then save the data in a text file - there is a link at the beginning of this instructable which links to a more complex one that saves text files.

Just a general comment to people who write one line requests like; "please build me my rocket ship to the moon, how I use serial comms?", a bit more detail in the question is more likely to get a response :)

#118. By gvreddy. Posted on 3/15/2008 4:29:20 PM
i want code for accessing mscomm in c#.net. very urgently.

#119. By apollo. Posted on 3/28/2008 11:50:40 AM
I am using mscomm control to send and receive data from a com port.
The following codes work,

Dim A As String

Private Sub Command1_Click()
T1.Enabled = False
C1.Output = T2.Text
T1.Enabled = True
T2.Text = ""
End Sub

Private Sub Form_Load()
C1.PortOpen = True

End Sub
Private Sub Timer1_Timer()

If (C1.InBufferCount > 0) Then

A = C1.Input
T1.Text = T1.Text + A

End If
End Sub

but i want to know the use of timer and why the codes are written inside it

#120. By James Moxham. Posted on 3/28/2008 1:40:57 PM
Apollo - the timer is checking the RS232 port regulary to see if any data has arrived. If there is a new character, it adds that to the T1.text string. You will need to define the timer properties, especially how often it checks for a new string. Maybe 10 times a second - it depends on how often new data arrives. Is this code you wrote or did you get it from somewhere else?

#121. By Robert. Posted on 4/10/2008 8:58:32 PM
I am polling the receive buffer to log data from a flight instrument using MSComm. I get the "Run-time error '7': Out of memory" after a few seconds. I understand this is a bug with the MSComm.ocx. Please offer any suggestions. Thanks

If MSComm1.InBufferCount <> 0 Then
RichTextBox1.Text = MSComm1.Input 'read input buffer
stringlen = Len(RichTextBox1.Text)
For index = 0 To (stringlen - 1)
RichTextBox1.SelStart = index
RichTextBox1.SelLength = 1
Text2.Text = Text2.Text & Asc(RichTextBox1.SelText)
Next
End If

#122. By Abdu. Posted on 4/13/2008 11:42:13 PM
I am trying to compile my program but i have got a problem with this can you see it what is the wrong here


Private Sub MSComm1_OnComm()
Dim s As String
Select Case MSComm1.CommEvent
Case comEvReceive
s = MSComm1.Input
If Asc(s) = 13 Then s = vbCrLf
End If
Text1.Text = Text1.Text & s
Text1.SelStart = Len(Text1.Text)
End Select
End Sub

#123. By James Moxham. Posted on 4/14/2008 6:31:08 AM
Abdu there is an error in the if/then line. Change it from
If Asc(s) = 13 Then s = vbCrLf
End If

to
If Asc(s) = 13 Then
s = vbCrLf
End If

#124. By Abdu. Posted on 4/15/2008 1:47:59 AM
Hi these all my code I have tried to solve why the numbers in form2 can't appear in any part of main form, and also when I tried to compile my wizard I get problem with MSComm1_comm
can you see what is the matter please




Option Explicit
Dim DataArray(999, 6) As String
Dim ArrayIndex As Integer
Dim SMS As String ' get a different message
Dim Value As String ' for hour
Dim telephone As String 'mobile phone number
Dim message1 As String 'message for zone 1
Dim message2 As String 'message for zone 2
Dim message3 As String 'message for zone 3
Dim message4 As String 'message for zone 4
Dim message5 As String 'message for zone 5
Dim message6 As String 'message for zone 6
Dim message7 As String 'message for zone 7
Dim message8 As String 'message for zone 8
Dim message9 As String 'message for zone 9
Dim message10 As String 'message for zone 10
Dim message11 As String 'message for zone 11
Dim message12 As String 'message for zone 12
Dim message13 As String 'message for zone 13
Dim message14 As String 'message for zone 14
Dim message15 As String 'message for zone 15

Private Sub CmdTesting_Click()
Dim AT As String
AT = "at"
MSComm1.Output = AT & Chr$(13)
cmdAt2_click
End Sub

Private Sub cmdAt2_click()
Dim AT2 As String
AT2 = "at+cmgf=1"
MSComm1.Output = AT2 & Chr$(13)
End Sub

Private Sub cmdzone1_Click()
Dim zone1 As String
Dim Combo1 As Form2
Value = Hour(Now) 'get hour value
zone1 = "Zone 1, Fire Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone1
cmdtelno_click ' to comparing the hour and get the number
cmdmessage1_click 'get zone1 message
cmdAt_Click ' ready for sending out the message
End Sub
Private Sub cmdzone2_Click()
Dim zone2 As String
Value = Hour(Now) 'get hour value
zone2 = "Zone 2, water pipes zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone2
cmdtelno_click ' to comparing the hour and get the number
cmdmessage2_click
cmdAt_Click
End Sub

Private Sub cmdzone3_Click()
Dim zone3 As String
Value = Hour(Now) 'get hour value
zone3 = "Zone 3, Smoke Detector Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone3
cmdtelno_click ' to comparing the hour and get the number
cmdmessage3_click
cmdAt_Click
End Sub
Private Sub cmdzone4_Click()
Dim zone4 As String
Value = Hour(Now) 'get hour value
zone4 = "Zone 4, Gas Pipes Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone4
cmdtelno_click ' to comparing the hour and get the number
cmdmessage4_click
cmdAt_Click
End Sub
Private Sub cmdzone5_Click()
Dim zone5 As String
Value = Hour(Now) 'get hour value
zone5 = "Zone 5, Door Lock Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone5
cmdtelno_click ' to comparing the hour and get the number
cmdmessage5_click
cmdAt_Click
End Sub
Private Sub cmdzone6_Click()
Dim zone6 As String
Value = Hour(Now) 'get hour value
zone6 = "Zone 6, Window Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone6
cmdtelno_click ' to comparing the hour and get the number
cmdmessage6_click
cmdAt_Click
End Sub
Private Sub cmdzone7_Click()
Dim zone7 As String
Value = Hour(Now) 'get hour value
zone7 = "Zone 7, Temperature Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone7
cmdtelno_click ' to comparing the hour and get the number
cmdmessage7_click
cmdAt_Click
End Sub
Private Sub cmdzone8_Click()
Dim zone8 As String
Value = Hour(Now) 'get hour value
zone8 = "Zone 8, Bath room Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone8
cmdtelno_click ' to comparing the hour and get the number
cmdmessage8_click
cmdAt_Click
End Sub

Private Sub cmdzone9_Click()
Dim zone9 As String
Value = Hour(Now) 'get hour value
zone9 = "Zone 9, Kitchen Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone9
cmdtelno_click ' to comparing the hour and get the number
cmdmessage9_click
cmdAt_Click
End Sub

Private Sub cmdzone10_Click()
Dim zone10 As String
Value = Hour(Now) 'get hour value
zone10 = "Zone 10, Storage Tank Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone10
cmdtelno_click ' to comparing the hour and get the number
cmdmessage10_click
cmdAt_Click
End Sub

Private Sub cmdzone11_Click()
Dim zone11 As String
Value = Hour(Now) 'get hour value
zone11 = "Zone 11, Light Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone11
cmdtelno_click ' to comparing the hour and get the number
cmdmessage11_click
cmdAt_Click
End Sub


Private Sub cmdzone12_Click()
Dim zone12 As String
Value = Hour(Now) 'get hour value
zone12 = "Zone 12, Basine Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone12
cmdtelno_click ' to comparing the hour and get the number
cmdmessage12_click
cmdAt_Click
End Sub

Private Sub cmdzone13_Click()
Dim zone13 As String
Value = Hour(Now) 'get hour value
zone13 = "Zone 13, Fan Zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone13
cmdtelno_click ' to comparing the hour and get the number
cmdmessage13_click
cmdAt_Click
End Sub

Private Sub cmdzone14_Click()
Dim zone14 As String
Value = Hour(Now) 'get hour value
zone14 = "Zone 14, Air conditioner zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone14
cmdtelno_click ' to comparing the hour and get the number
cmdmessage14_click
cmdAt_Click
End Sub

Private Sub cmdzone15_Click()
Dim zone15 As String
Value = Hour(Now) 'get hour value
zone15 = "Zone 15, Electric zone" 'display the time and data now
txt2date.Text = Format$(Now, "hh:mm:ss") + Format$(Now, "dddd:mmm:yyyy")
List4.AddItem zone15
cmdtelno_click ' to comparing the hour and get the number
cmdmessage15_click
cmdAt_Click
End Sub

Private Sub cmdmessage1_click()
SMS = "Warning !Your House on Fire! Please Call fire brigade and come Back Immediately"
lbl1.Caption = SMS

End Sub
Private Sub cmdmessage2_click()
SMS = "Warning !Your House water pipes on Leakage! Please Call Plumber and come Back Immediately"
lbl1.Caption = SMS

End Sub

Private Sub cmdmessage3_click()
SMS = "Warning !Your House on smoke! Please come Back Immediately"
lbl1.Caption = SMS

End Sub

Private Sub cmdmessage4_click()
SMS = "Warning !Your House Door Unlock! Please come Back Immediately"
lbl1.Caption = SMS

End Sub

Private Sub cmdmessage5_click()
SMS = "Warning !Your House water pipes on Leakage! Please come Back Immediately"
lbl1.Caption = SMS

End Sub

Private Sub cmdmessage6_click()
SMS = "Warning !Your House Windows Unlock! Please come Back Immediately"
lbl1.Caption = SMS

End Sub

Private Sub cmdmessage7_click()
SMS = "Warning !Your House Temperature Meter is high! Please come Back Immediately"
lbl1.Caption = SMS

End Sub
Private Sub cmdmessage8_click()
SMS = "Warning !Your House Toilet not function properly! Please Call Plumber and come Back Immediately"
lbl1.Caption = SMS

End Sub

Private Sub cmdmessage9_click()
SMS = "Warning !Your House Kitchen freezer not work! Please fix it Immediately"
lbl1.Caption = SMS

End

#125. By abhijit. Posted on 4/15/2008 5:15:31 AM
How to select different handshaking in vb6.0 using MSComm Control?

#126. By James Moxham. Posted on 4/15/2008 2:25:39 PM
Abdu - this line Dim Combo1 As Form2
doesn't compile and I'm not sure what you are trying to do with that line. But I don't think that is the problem.
Have you added a comm control to the form? Go to Project/Components then scroll down the list to Micrsoft Comm Control 6.0 and check the box. Then the little telephone symbol will appear on the left side of the screen and you can drag it into the form. It will default to MSComm1. The rest of the code seems ok, which line is causing the error? Also, have you got this on two forms? If so and you want to send data between forms, you can either have global variables or you can save data to small text files and then read it back.

To abhijit, and with the greatest respect, your question makes no sense whatsoever. Neither grammatically, nor as one programmer to another. A bit more detailed description of the problem and not only might you be more likely to get an answer, but you might also answer your own question yourself.

#127. By abhijit. Posted on 4/20/2008 5:52:01 PM
How to handle interrupt in Serial Communication using vb6.0?

#128. By icebox. Posted on 5/15/2008 7:26:48 AM
hi guys..
im new hir and im making a project which includes serial communication using rs232..
how can i check if the connection between the device and the host computer is broken? and if the device is connected or not.. pls give me some tips and advice.. or if someone could provide me a code.. that's very much accepted.. tnx!:D

#129. By icebox. Posted on 5/15/2008 7:46:12 AM
hi guys..
im new hir and im making a project which includes serial communication using rs232..
how can i check if the connection between the device and the host computer is broken? and if the device is connected or not.. pls give me some tips and advice.. or if someone could provide me a code.. that's very much accepted.. tnx!:D

#130. By Lanie. Posted on 5/26/2008 10:05:09 AM
Im doing a program in visual basic, this program will connect to a microcontroller with built it ADC,which means that the data that the program will received is 0-2 volts. I've researched a topic regarding communications to serial ports and found out that an object called mscomm control must be used. But stil Im not sure yet on what code to be use in order to receive the exact datafrom serial..Will somebody help me to solve this problem..Thank you..

#131. By James Moxham. Posted on 5/26/2008 2:34:47 PM
To add an MSCOMM control in vb6 - open a new file. Top menu is File/Edit/View/Project etc. Click Project. Go down to Components... at the bottom. Scroll down to "Microsoft Comm Control 6.0". Check the box. Click OK. On the left of the screen a little telephone symbol will appear underneath all the standard things like buttons. Grab this and drop it onto your main form1. You can put it anywhere as it doesn't show at runtime. Now you can use all the serial port comms in your code.

#132. By PUnit Roy. Posted on 6/4/2008 10:13:35 AM
Dear Sir,
I m working on VB project , in which i have to interface PC to 8051 microcontrollerto tx and rx data.I am using mscomm command on my VB6.0, to tx data from PC to microcontroller, it is working correctly ( transmit and receive ) on desktop computer.But the interfacing is not taking place on USB port of desktop computer and on notebook computer also no tx and rx is taking place.kindly tell me where the problem is and how to solve it.I m using Window Xp. mail me on punitroy01161@gmail.com

#133. By suresh. Posted on 6/5/2008 10:53:31 AM
I WANT DEPTH INFORMATION ON MSCOMM CONTROLS ON VISUAL BASIC 6.0

#134. By paresh. Posted on 6/23/2008 6:03:01 AM
how send sms using mscomm control to mobile. please give me a quick response.and some example with port number.

#135. By Pardeep Kumar Mittal. Posted on 6/26/2008 11:10:48 AM
Question : I want to send files from one PC to another by serial port using VB6 (Just like using Hyper Terminal we can send the file through serial port to another PC.)

#136. By Pardeep Kumar Mittal. Posted on 6/26/2008 11:16:39 AM
Question : I want to send files from one PC to another by serial port using VB6 (Just like using Hyper Terminal we can send the file through serial port to another PC.)


Thanx

Pardeep

#137. By ronald. Posted on 8/8/2008 9:55:04 AM
I want to know how will I display the reading of a sensor on the PC using VB6? I used the mscomm32.ocx. Well I have a module witch contains 2 sensors for reading raw data. The measured data must be desplayed on the pc. My problem is I cannot display readings of the sensor even if the module and the PC are communicating.
here is a code I made in vb6.


Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMillisecond As
Long)
Dim serialdata As String
Dim mode As Integer
Dim T_P, C_F As Boolean
Const read_T = &H31
Const read_P = &H32
Const read_TP = &H33
Const cal_T = &H34
Const led_off = &H35
Const led_on = &H36
Const mode_1 = 1
Const mode_2 = 2
Const mode_3 = 3
Const mode_4 = 4

Private Sub cmdCalibrateT_Click()
Timer1.Enabled = True
MSComm1.RThreshold = 1
MSComm1.InputLen = 1
mode = mode_4
lblcalibinfo.Caption = " "
End Sub


Private Sub cmdDegC_Click()
C_F = True
End Sub

Private Sub cmdDegF_Click()
C_F = False
End Sub

Private Sub cmdErase_Click()
On Error GoTo nxt
With adoTP.Recordset
.MoveFirst
Do While Not .EOF
If Not (.BOF Or .EOF) Then
.Delete
.MoveFirst
End If
Loop
End With
nxt:
End Sub



Private Sub cmdLEDOff_Click()
MSComm1.Output = Chr(led_off)
End Sub

Private Sub cmdLEDOn_Click()
MSComm1.Output = Chr(led_on)
End Sub

Private Sub cmdReadP_Click()
Timer1.Enabled = True
MSComm1.RThreshold = 1
MSComm1.InputLen = 1
mode = mode_2
End Sub

Private Sub cmdReadT_Click()
Timer1.Enabled = True
MSComm1.RThreshold = 1
MSComm1.InputLen = 1
mode = mode_1
End Sub

Private Sub cmdReadTP_Click()
Timer1.Enabled = True
MSComm1.RThreshold = 2
MSComm1.InputLen = 2
mode = mode_3
End Sub

Private Sub cmdStop_Click()
Timer1.Enabled = False
End Sub


Private Sub Form_Load()
MSComm1.CommPort = "1"
MSComm1.PortOpen = True
End Sub

Private Sub MSComm1_OnComm()
Dim serdata As String
If MSComm1.CommEvent = 2 Then
serialdata = MSComm1.Input

serdata = Hex(Asc(serialdata))

If mode = mode_1 Then
If Hex(Asc(serialdata)) = "FF" Then
lblcalibinfo.Caption = "Detached Temp Sensor"
txtTempValue = "0"
Else
lblcalibinfo.Caption = "Attached Temp Sensor"
If C_F = False Then
txtTempValue = Format(Asc(serialdata) * 100 / 255 +
7.4, "###0.00")
Else
txtTempValue = Format(((Asc(serialdata) * 100 / 255
+ 7.4) * 9 / 5) + 32, "###0.00")
End If
End If
Call LogT
ElseIf mode = mode_2 Then
If Hex(Asc(serialdata)) = "FF" Then
lblcalibinfo.Caption = "Detached Pressure Sensor"
txtPressValue = "0"
Else
lblcalibinfo.Caption = "Attached Pressure Sensor"
txtPressValue = Format(Asc(serialdata) * 100 / 255,
"###0.00")
End If
Call LogP
ElseIf mode = mode_3 Then
txtTempValue = Format(Asc(Mid(serialdata, 1, 1)) * 100 /
255 + 7.4, "###0.00")
txtPressValue = Format(Asc(Mid(serialdata, 2, 1)) * 100 /
255, "###0.00")
Call LogTP
ElseIf mode = mode_4 Then
If serialdata = "F" Then
lblcalibinfo.Caption = "Temp sensor calibrated."
End If
End If
End If
End Sub
Private Sub LogTP()
If chkLog.Value = 1 Then
With adoTP.Recordset
.AddNew
!date_time = Now
!temperature = txtTempValue
!unit_T = "°C"
!pressure = txtPressValue
!unit_P = "kPascal"
.Update
End With
End If
End Sub
Private Sub LogT()
If chkLog.Value = 1 Then
With adoTP.Recordset
.AddNew
!date_time = Now
!temperature = txtTempValue
!unit_T = "°C"
!pressure = " "
!unit_P = " "
.Update
End With
End If
End Sub
Private Sub LogP()
If chkLog.Value = 1 Then
With adoTP.Recordset
.AddNew
!date_time = Now
!temperature = " "
!unit_T = " "
!pressure = txtPressValue
!unit_P = "kPascal"
.Update
End With
End If
End Sub


Private Sub Timer1_Timer()
If CInt(txtSamplingInterval) < 10 Then
txtSamplingInterval = 10
Timer1.Interval = 10
Else
Timer1.Interval = txtSamplingInterval
End If

If mode = mode_1 Then
MSComm1.Output = Chr(read_T)
ElseIf mode = mode_2 Then
MSComm1.Output = Chr(read_P)
ElseIf mode = mode_3 Then
MSComm1.Output = Chr(read_TP)
ElseIf mode = mode_4 Then
MSComm1.Output = Chr(cal_T)
lblcalibinfo.Caption = "Temp sensor calibrated."
End If


End Sub

#138. By sahil gupta. Posted on 8/20/2008 10:19:04 AM
i want to transfer a text file by using hyper terminal to a ram attached to microcontroller 8051 please suggest me the required code for doing this job.

#139. By sahil gupta. Posted on 8/20/2008 10:19:13 AM
i want to transfer a text file by using hyper terminal to a ram attached to microcontroller 8051 please suggest me the required code for doing this job.

#140. By Bijo.P.Jose. Posted on 8/21/2008 4:39:31 PM
I want to connect two computers through RS232 port.I want to progam it Vb using Ms comm control.The data entered in one textbox should be transferred to the otherone.What shoud I do?

#141. By elamathi. Posted on 8/22/2008 6:50:00 AM
how to use serial prot through vb
how to wirte code vb forn serial port programming

#142. By sanandiya vijay. Posted on 9/27/2008 3:43:49 PM
how to display take weighting scale information in visual basic 6.0 textbox using mscomm control?

#143. By frans. Posted on 10/24/2008 11:40:05 AM
Good site..!

Is it possible to setup the MSCOMM control on WinXP for an unusual 96K baudrate
using VB5/6..?

Thanx in advance.

8?>

#144. By jerome. Posted on 11/8/2008 12:00:23 PM
how will i interface the computer to PIC microcontroler?

#145. By karthikeyan. Posted on 11/12/2008 11:16:35 AM
hi i'm new to vb... Now i want transmit some data through mscomm and receive that data in same pc ..

#146. By James Moxham. Posted on 11/12/2008 11:26:56 AM
Jerome - yes you can interface with a pic - check out http://www.instructables.com/id/Control-real-world-devices-with-your-PC/

#147. By karthikeyan. Posted on 11/13/2008 7:09:59 AM
hi ,
I want transmit one data and receive the data in same form.. i use this code but it not workin..

Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub

Private Sub MSComm1_OnComm()
Text1.Text = Text1.Text & MSComm1.Input
End Sub

Private Sub Timer1_Timer()
MSComm1.Output = "date"
For i = 0 To 10000
Next i
End Sub

help me..

#148. By karthi. Posted on 11/15/2008 11:55:22 AM
hi..
I connect the gps port to system... how to i receive the data from GPS plz help me as soon as possible...

advance thanks

#149. By manuelito martinez. Posted on 11/19/2008 4:43:04 AM
ke pedo? kon esas mamadas escriban en espanol po =r ke no entiendo ni madres de sus pendejadas

#150. By Anonymous. Posted on 12/5/2008 2:12:31 PM
Test

#151. By Ruan. Posted on 12/5/2008 2:53:05 PM
ERROR 8020 - ERROR READING COMM DEVICE

I am using Win Vista Ver. 6.00.6001 Service Pack 1 as OS. My application is written in VB6 SP6. I use MSComm32.ocx for the serial communication and a USB to serial converter cable. All the serial comms works 100% on my PC.

I then installed my application on another Vista PC with exactly the same version and service pack installed. I use the same USB to serial converter cable. Whenever I try and read the comms port with MSComm.Input, the control generates an error: ERROR 8020 - ERROR READING COMM DEVICE. I can TX data on that comms port though. It is only a problem when I receive data.

I used “Serial-Port-Monitor” to monitor OUT and IN data on the comms port. I can see that the TX and RX data are received BUT whenever I read my comms port, the control generates Errror 8020.

Another test I did was in Hyperterminal. I connected a loopback-plug to my DB9 and opened the same comms port. The characters I typed on the keyboard, echoed back to Hyperterminal. This tells me that the comms port is working fine.

So why does it not work in VB6?

Please help.

#152. By BobJ. Posted on 12/8/2008 3:16:37 AM
I am trying ot use mscomm32.ocx in VBScript ! I "Registered" it but still get "Class not licensed for use"
Most of my web searching seems to indicate this control will work ONLY if I install VB6 on my machine.
I'm desparately trying to write a script that accpets serial data from a remote weatheer station for our local Emergency Ops Center - Any ideas please?

#153. By Dean. Posted on 12/30/2008 2:27:55 AM
I,m trying to use the MScomm program an AVR. So far, Im using the RTS,DTR (both Out) & CTS (in), but I need another output.
I noticed that a program (Ponyprog) uses the TX output as a reset on his serial programming circuit as the reset.
I wacked a CRO on the TX, and found that he has full High / Low control over it and could leave it in either state.
I've searched the MSComms control dat and even the UART chip data, but I can't see a way of controlling this TX line (under my control, Any ideas.

#154. By jitendra. Posted on 2/2/2009 10:01:53 AM
this is good to learn about different topics.
through this i want to create activex control or dll in vb6.0

thanks

#155. By karthik. Posted on 2/3/2009 6:52:59 AM
hello sir..
pls help me.i want get text in local language Tamil in text box and save that text i notpad as .txt file. after that i want to read that file and send to another system through MSComm device.. normally i use Bamini font for tamil. but this font view the text in tamil. but it save the file in english only. so pls help in this visual basic code...
thank u sir..

#156. By Ruan. Posted on 2/11/2009 5:31:00 AM
ERROR 8020 - ERROR READING COMM DEVICE

I am using Win Vista Ver. 6.00.6001 Service Pack 1 as OS. My application is written in VB6 SP6. I use MSComm32.ocx for the serial communication and a USB to serial converter cable. All the serial comms works 100% on my PC.

I then installed my application on another Vista PC with exactly the same version and service pack installed. I use the same USB to serial converter cable. Whenever I try and read the comms port with MSComm.Input, the control generates an error: ERROR 8020 - ERROR READING COMM DEVICE. I can TX data on that comms port though. It is only a problem when I receive data.

I used “Serial-Port-Monitor” to monitor OUT and IN data on the comms port. I can see that the TX and RX data are received BUT whenever I read my comms port, the control generates Errror 8020.

Another test I did was in Hyperterminal. I connected a loopback-plug to my DB9 and opened the same comms port. The characters I typed on the keyboard, echoed back to Hyperterminal. This tells me that the comms port is working fine.

So why does it not work in VB6?

Please help.
-------------------------------------
I got it to work!!!!!!!!!!!!
I copied my USB driver file Windows\System32\Drivers\ser2pl.sys and replaced it with the target Vista PC and it worked fine.
Remember, when you overwrite the file, unplug the USB cable and connect it again. Windows will load the new USB Serial Drivers.

#157. By Ruan. Posted on 2/11/2009 5:35:40 AM
ERROR 8020 - ERROR READING COMM DEVICE

I am using Win Vista Ver. 6.00.6001 Service Pack 1 as OS. My application is written in VB6 SP6. I use MSComm32.ocx for the serial communication and a USB to serial converter cable. All the serial comms works 100% on my PC.

I then installed my application on another Vista PC with exactly the same version and service pack installed. I use the same USB to serial converter cable. Whenever I try and read the comms port with MSComm.Input, the control generates an error: ERROR 8020 - ERROR READING COMM DEVICE. I can TX data on that comms port though. It is only a problem when I receive data.

I used “Serial-Port-Monitor” to monitor OUT and IN data on the comms port. I can see that the TX and RX data are received BUT whenever I read my comms port, the control generates Errror 8020.

Another test I did was in Hyperterminal. I connected a loopback-plug to my DB9 and opened the same comms port. The characters I typed on the keyboard, echoed back to Hyperterminal. This tells me that the comms port is working fine.

So why does it not work in VB6?

Please help.
-------------------------------------
I got it to work!!!!!!!!!!!!
I copied my USB driver file Windows\System32\Drivers\ser2pl.sys and replaced it with the target Vista PC and it worked fine.
Remember, when you overwrite the file, unplug the USB cable and connect it again. Windows will load the new USB Serial Drivers.

#158. By Juan P. Posted on 2/14/2009 4:59:24 AM
I-m trying to use MSComm component in one MS Access application, but it seems that only works when the component is compiled. I think that because i wrote the same lines in a VB6 project, and after compilation, it worked like a good song... so, the question is..is true that the MSComm doesn-t work without compiling and if so, is there any workarround or solution ?

#159. By nafisa. Posted on 2/27/2009 2:38:06 PM
ok so idk

#160. By Sathish.C. Posted on 3/9/2009 9:00:32 AM
Hi,
Plz Send me the dll or Source Code for Measuring Telephone Pulse Rate in .Net Applications.

#161. By Kalu. Posted on 3/21/2009 1:36:54 PM
please, I was given a project to write on a management system that can send sms and also dial calls using visual basic 6.0. I have written the program just remaining the sms sending and dialing functionality. please can anyone help me. my emial address is dkdimgba@yahoo.com.

thanks in advance

#162. By Alan French. Posted on 5/18/2009 7:13:44 PM
Having read your advice above and the many comments below I am still struggling to get any meaningful data from my serial port.
I am attempting to capture data that is intended for a parallel printer. This is being done using a parallel to serial converter and the MsComm control. For testing purposes I send a simple text file from the parallel port and attempt to capture it on the serial port of the same PC. The VB code places the data from the MsComm.Input into a text box for me to view. The problem that I am having is that I always receive junk/unreadable characters. The only time I receive data correctly is when I choose to use a “Generic/Text Only” printer driver.
I am almost certain that I need to set the MsComm.InputMode to Binary and then interrogate the Bytes that are received but I must be doing something wrong. Any help would be very grateful and may well save what little hair I have left :)

PS. I know that the serial to parallel converter is working because when I plug it into my dot matrix printer (do you remember those?) it prints out exactly as I'd expect. I have also checked the Baudrate & Parity etc many times now.

#163. By Anonymous. Posted on 5/24/2009 7:16:32 AM
@Alan French. The reason you are getting what seems like garbage is because the printer driver is putting out the printed data in a binary language that the printer understands. So, of course, when you pick "Generic/Text Only", the printer driver is going to send out data in clear text.

#164. By Vidhi Jain. Posted on 7/12/2009 1:33:00 PM
The Questions and Answers helped me a lot.I am new to serial communication using RS232.I m making a project in Vb6.I am facing problem in clearing buffer before each command.When I display output from MSComm1.Input in TextBox it displays answers of all previous commands.Can you please help?
Thanks in anticipation.

#165. By Vidhi Jain. Posted on 7/12/2009 1:38:55 PM
I am doing serial communication using RS232 in a project of Vb6.I am not able to display answer of last command given to instrument.The MSComm1.Input returns answer of all previous commands but i need only of last command given.How do i clear buffer each time.
Kindly help.

#166. By Vidhi Jain. Posted on 7/12/2009 1:40:13 PM
I am doing serial communication using RS232 in a project of Vb6.I am not able to display answer of last command given to instrument.The MSComm1.Input returns answer of all previous commands but i need only of last command given.How do i clear buffer each time.
Kindly help.

#167. By John L. Posted on 7/17/2009 7:31:03 PM
I've been trying to communicate with an old CNC mill that I own. Mostly unsuccessfully. I've also considered resurrecting my old MS-Dos PC, and trying communication with that. In any case I have written a few programs in both VB5.0 and VB.Net. But my reference books that I have here are not telling me much on serial ports and so forth. Assuming the problem is not with the CNC mill do you offer an off the shelf program to batch dump an ascii program down to a serial device?

#168. By Bhushan Deshpande. Posted on 7/22/2009 12:53:38 PM
Hello Friends,

I am facing a small problem in Serial communication using MSComm component.
I am reading a device on serial port using VB6.0 program where I have used MSComm component for ser. comm.
But while receiving the data sometimes insted of some specific values it's receiving 00H as hex data.

This is happening for following values received: 0AH, 7AH, 8AH, FAH.
I have observed this on some utility parallely while this software in VB is running.

Here A is common for data.and 0AH means line feed.

So what could be the problem.
Can u tell me the same.

What could be the remedy.
Friends please let me know if you have any idea.

Waiting for your help.

Thank You.
With Regards,

Bhushan Deshpande

#169. By Bhushan Deshpande. Posted on 7/22/2009 12:55:46 PM
Hello Friends,

I am facing a small problem in Serial communication using MSComm component.
I am reading a device on serial port using VB6.0 program where I have used MSComm component for ser. comm.
But while receiving the data sometimes insted of some specific values it's receiving 00H as hex data.

This is happening for following values received: 0AH, 7AH, 8AH, FAH.
I have observed this on some utility parallely while this software in VB is running.

Here A is common for data.and 0AH means line feed.

So what could be the problem.
Can u tell me the same.

What could be the remedy.
Friends please let me know if you have any idea.

Waiting for your help.

Thank You.
With Regards,

Bhushan Deshpande

#170. By vamsi. Posted on 8/21/2009 8:12:38 AM
how to receive data from serial port to database using vb.net2005

#171. By yuvasree. Posted on 10/7/2009 6:52:53 AM
Hi,
I have to send data to hyperterminal of my own computer terminal using VB 6.0,i am using only one computer,Can u please help me by sending code and connections for it?

#172. By yuvasree. Posted on 10/7/2009 6:53:36 AM
Hi,
I have to send data to hyperterminal of my own computer terminal using VB 6.0,i am using only one computer,Can u please help me by sending code and connections for it?

#173. By Steve. Posted on 12/3/2009 1:18:17 PM
I am trying to read and write to the com1 port using vba code in Access 2007 running XP pro. I had this type of function working earlier in windows 98 using some calls to functions based on kernal32. These functions are failing to work on my current machine with xp pro and a single serial port. Does anyone have a suggestion?

Thanks in advance.

#174. By Steve. Posted on 12/3/2009 1:21:17 PM
I am trying to read and write to the com1 port using vba code in Access 2007 running XP pro. I had this type of function working earlier in windows 98 using some calls to functions based on kernal32. These functions are failing to work on my current machine with xp pro and a single serial port. Does anyone have a suggestion?

Thanks in advance.

#175. By Steve. Posted on 12/3/2009 1:22:26 PM
I am trying to read and write to the com1 port using vba code in Access 2007 running XP pro. I had this type of function working earlier in windows 98 using some calls to functions based on kernal32. These functions are failing to work on my current machine with xp pro and a single serial port. Does anyone have a suggestion?

Thanks in advance.

#176. By Jaime. Posted on 1/26/2010 2:39:50 PM
I have a pc with 4 additional serial ports and a VB6 application. When I use the open com1: for output to send a file to a printer (line by line), it works fine. But when I use open com4: for output, I get an "path error". Could someone give me some help please?

#177. By yogesh. Posted on 2/2/2010 7:19:56 AM
i want to send sms from vb6 to any other mobile how can i send, pls give me soucecode

#178. By yogesh. Posted on 2/2/2010 7:21:20 AM
i want to send sms from vb6 to any other mobile how can i send, pls give me soucecode

#179. By hamad. Posted on 3/11/2010 2:50:25 PM
Dear sir,
How can i receive data from a weighing machine through comm port using VB6, i want ot recieve weight in a textbox on form.
regards

#180. By haseeb. Posted on 3/11/2010 3:08:37 PM
Hi,

I have connected an electonic weighing scale to
CommPort 2 on my pc. I want to continuously read the
contents of the weight into the textbox.
This is what I have done but I am not successful. It
displays some junk characters at times. Can someone
please help me.

On a form I have placed a TextBox, Timer and MSComm.



Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1
MSComm1.CommPort = 2
MSComm1.PortOpen = True
End Sub



Private Sub Timer1_Timer()
Text1.Text = MSComm1.Input
End Sub

#181. By Syed Ehtesham. Posted on 4/23/2010 3:12:42 PM
Dear
I want to get data from weighbridge machine and the machine is connected to computer via com port 1 i m using MsAccess database and my project is also in MsAccess I dont know how to get data from this com port and save it to my database someone told me it will be done through mscomm.ocx and i dont know how to use this control whether this control is in active x controls in MsAccess forms etc.
plz some help me in this connection I shall be very thankful.

My email is ehteshamshah@yahoo.com

#182. By Comm32. Posted on 5/14/2010 5:43:20 PM
As the man said, mscomm32 is relatively bug free. However, there are a few 'features' that can cause problems.

Texas Instruments appear to have released a USB chipset with a virtual comport driver that causes problems whenever a com port is opened for OverlappedIO.

Anyway - the problem that occurs when using the TI usb hardware/drivers is ERROR 8020 - ERROR READING COMM DEVICE. You can transmit data but whenever you try to receive using the Input method you get that error.

Using an alternative ocx such as Comm32 from www.comm32.com there are a few additional properties. One of them is "ParallelEnable". Set that to FALSE and the 8020 error goes away and you can send and receive using the same syntax as mscomm32

#183. By Ahsan Butt. Posted on 6/18/2010 12:50:12 PM
A nice article - really liked it!

#184. By Isse ali. Posted on 7/11/2010 11:17:20 PM
thanks bro it help me well

#185. By roni kassouf. Posted on 7/23/2010 8:56:12 AM
i need the tutorial coding

#186. By questioner. Posted on 8/10/2010 8:12:11 PM
Hi,
I used a usb to serial converter to connect between my pc and a printer.
I set rthreshold = 1 and inputlen = 4.
However, I always got only one character when the comeventrecv got fired.
If I connect the printer direct to my pc com port, I have no problem getting 4 characters when the comeventrecv got fired.
How to solve the problem?

#187. By Rahul. Posted on 8/28/2010 1:08:43 PM
Hi All,


This is Rahul.I'm fresher. I got project to work Axmscomm control.

My project :
I should dail a system from my system to another system through GSM modem by number and i should read the data from it. I should do this application in vb.net with Sql Server.

I have searched a lot in google but i dint get any information. I thought this forum may help me. So please kindly give some information regarding this.

1. What information I should aware of before doing this?
2. How to use Axmscomm Control to my application?
3. I have Tried this application with some source but i'm getting Exception of Type 'System.Windows.Forms.AxHost=InvalidActiveXStateException' was thrown errors. How to slove this
Please guide me with source.Please Help meConfused
It is Urgent for me to complete this

Thank You in Advance

#188. By Rahul. Posted on 8/28/2010 1:09:53 PM
Hi All,


This is Rahul.I'm fresher. I got project to work Axmscomm control.

My project :
I should dail a system from my system to another system through GSM modem by number and i should read the data from it. I should do this application in vb.net with Sql Server.

I have searched a lot in google. I thought this forum may help me. So please kindly give some information regarding this.

1. What information I should aware of before doing this?
2. How to use Axmscomm Control to my application?
3. I have Tried this application with some source but i'm getting Exception of Type 'System.Windows.Forms.AxHost=InvalidActiveXStateException' was thrown errors. How to slove this
Please guide me with source.Please Help meConfused
It is Urgent for me to complete this

Thank You in Advance

#189. By Jeffery. Posted on 9/8/2010 4:51:48 AM
Please advise what is the maximum number of serial ports that can be accessed with the Visual Basic MSCOMM command. Thank you.

#190. By Flanagan. Posted on 11/4/2010 6:44:08 AM
Is it possible for me to use this control to intercept data sent to a printer and then write the text to a text file. If possible...how do i do this?

#191. By 0-. Posted on 2/4/2011 8:25:32 AM
p,0op,

#192. By 0-. Posted on 2/4/2011 8:25:45 AM
p,0op,

#193. By Dasharath Gawas. Posted on 4/30/2011 11:44:19 AM
I am new in programing. I want to connect the external device(Temperature Controller). so pls help me to write mscom code.

#194. By Dasharath Gawas. Posted on 4/30/2011 11:44:54 AM
I am new in programing. I want to connect the external device(Temperature Controller). so pls help me to write mscom code.

#195. By kishore. Posted on 5/12/2011 7:30:48 AM
http://www.vbrad.com/article.aspx?id=37

#196. By ADONTEC. Posted on 5/19/2011 2:10:41 PM
Tired of tumbling with MSComm ? Replace within seconds with SuperCom Serial ActiveX. Read more at www.adontec.com/scocx_e.htm.

#197. By ADONTEC. Posted on 5/19/2011 2:43:37 PM
Tired of tumbling with MSComm ? Replace within seconds with SuperCom Serial ActiveX. Read more at www.adontec.com/scocx_e.htm.

#198. By Wdave. Posted on 10/25/2011 3:20:11 PM
I take issue with the author's statement, "the problem is YOU".
I honestly think that that needs a very important qualifier before it can be accepted.
And that qualifier is "YOU think that Microsoft cares whether things work or not."
Or "YOU are using Microsoft products."
That, then, would make his statement accurate.
I have been banging my head against a brick wall with MSComm. Such a wonderful 'module' 'object' whatever?
If it's not this MSComm control causing the problems then it has to be Windows itself causing the problem.
It totally ignores Xon/Xoff after a second or three and reports that the output buffer is empty.
I recoded my stuff to stop polling the .OutBufferCount Property and rely on the OnComm Event and the result is no
different. The data is lost.
MSComm has one single Event that causes you to slow everything down checking which detail actually raised
the event. Everything else is a Property. No methods whatsoever. Even the simple LABEL Control has more than that!
The MSComm control is fine unless you're serious about your app.
I had always dropped to DOS when using serial communications since the early versions of Windows always
caused problems. I'd figure that after 20 years they (MS) should be able to get things right.
Now I'm told that I need to "upgrade" to VB.Net - yeah, right.
More syntax, more changes, more mis-logic, more MS.

#199. By Harold. Posted on 1/3/2012 2:29:09 AM
i'm working now with a project and i'm using visUal basic 6.0, and i'm having a hard time detecting devices connected to usb ports... is there anyone here could give me the possible solution to my problem? if possible, can you give me a sample source code in vb thaT can do such thing co'z i'm kinda newBie to vb6.0.

ThanKs guys in advance!

#200. By shilpa. Posted on 2/13/2012 5:26:20 AM
i need to get the reading of a weighbridge reading device into my vb project text box. port is COMM port. i need to know the settings and code for the same. and also how to apply them in vb. please help.

#201. By masum6278. Posted on 3/13/2012 7:57:49 PM
tkank u bosss........................