Library tutorials & articles
Com Ports and the MSComm Control
Receiving Data
To receive data, you need to check the Input property. However, the problem is, knowing when the data is there. This is because the data only stays in the Input property for a few seconds. I find that the OnComm event is the best way to do this. In order for the OnComm event to fire, you need to set RThreshold and SThreshold to 1. So, to get the result of the command we sent the modem in the last section, we need the following code to be inserted into the OnComm event:
Select Case MSComm1.CommEvent
' Event messages.
Case comEvReceive
txtOutput.Text = txtOutput.Text & StrConv(MSComm1.Input,
vbUnicode)
EndSelect
This checks to see what event has just occured. If it was a receive event, we add the contents of the Input property to the end of the txtOutput textbox. When we send the command above, we should receive something like
ATDT01992245365
BUSY
The first line is our command echoed back at us. The next is the result of the dial, in this case Busy (because we were dialing our own number). On my modem, you can turn the command echo off by sending ATE0. For a list of other commands, click here.
You can also use the OnComm event to monitor other communication events or errors. Because communications (especially over telephone lines) can be unpredictable, trapping these events and errors allows you to respond to them appropriately.
The following table lists the communication events that will trigger the OnComm event. The values will then be written to the CommEvent property.
| Constant | Value | Description |
| comEvSend | 1 | There are fewer than SThreshold number of characters in the transmit buffer. |
| comEvReceive | 2 | Received RThreshold number of characters. This event is generated continuously until you use the Input property to remove the data from the receive buffer. |
| comEvCTS | 3 | Change in Clear To Send line. |
| comEvDSR | 4 | Change in Data Set Ready line. This event is only fired when DSR changes from 1 to 0. |
| comEvCD | 5 | Change in Carrier Detect line. |
| comEvRing | 6 | Ring detected. Some UARTs (universal asynchronous receiver-transmitters) may not support this event. |
| comEvEOF | 7 | End Of File (ASCII character 26) character received. |
The OnComm event is also triggered, and a value is written to the CommEvent property, when the following errors are encountered.
| Setting | Value | Description |
| comEventBreak | 1001 | A Break signal was received. |
| comEventFrame | 1004 | Framing Error. The hardware detected a framing error. |
| comEventOverrun | 1006 | Port Overrun. A character was not read from the hardware before the next character arrived and was lost. |
| comEventRxOver | 1008 | Receive Buffer Overflow. There is no room in the receive buffer. |
| comEventRxParity | 1009 | Parity Error. The hardware detected a parity error. |
| comEventTxFull | 1010 | Transmit Buffer Full. The transmit buffer was full while trying to queue a character. |
| comEventDCB | 1011 | Unexpected error retrieving Device Control Block (DCB) for the port. |
Related articles
Related discussion
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Hi. I need to comunicate with a money colector using VB 6.0 Pro. I had installed the MsComm control.
How can i send this comands to the money collector and how i can read the answers ?
254 - Simple Poll
18 0.00002576 WRITE Length 5: 02 00 01 FE FF
19 0.00851212 READ Length 5: 02 00 01 FE FF
20 0.00621133 READ Length 4: 01 00 02 00
21 0.00000270 READ Length 1: FD
246 - Request Manufacturer ID
23 0.00001986 WRITE Length 5: 02 00 01 F6 07
24 0.00854877 READ Length 5: 02 00 01 F6 07
25 0.00935437 READ Length 4: 01 03 02 00
26 0.00000235 READ Length 4: 4E 52 49 11
244 - Request Product Code
28 0.00002023 WRITE Length 5: 02 00 01 F4 09
29 0.00852501 READ Length 5: 02 00 01 F4 09
30 0.00935432 READ Length 4: 01 03 02 00
31 0.00000234 READ Length 4: 47 31 33 4F
242 - Request Serial No
33 0.00002094 WRITE Length 5: 02 00 01 F2 0B
34 0.00853151 READ Length 5: 02 00 01 F2 0B
35 0.00935416 READ Length 4: 01 03 02 00
36 0.00000241 READ Length 4: BF 42 5F 9A
Thanks... Raxe
First of all, I have to thank you for giving out this lovely tutorial:) This is a great help for folks like who has no idea in using the Ms comm Control, Thank you very much and keep up the good work. :cool:
Dear Friend Virag,
I have done lots of R&D in this matter, and what i found is, it is best option to go with third party controls & components to work with these type of apps. So search web u will have options for such controls
dear friend,
i m looking for new tips for controling hardware using visual basic code.
i also want to build interactive voice response system by which i can control my computer from anywhere. just like listninig songs from my computer.
please help me to get this result.
waiting for positive reposnce
from
virag jani
Is it possible to develop simple IVR Apps with ms comm control in which step of wave file prompts guide the caller and he/she can choose option from phone buttons. By detecting caller choice programmer should able to take action
GUYS
I NEED SMS CODE USING VB,BY WHICH WE CAN SEND SMS IN ALL THE MOBILE
SO KINDLY GIVE ME CODE AND ALSO ALL THE INFORMATION HOW TO USE IT
THANKS
THIS IS URGENT
ASHISH
You can use Wavecom modems - www.wavecom.com. Phones are generally less stable and can hang.
Hi everybody,
I am also working on SMS application via GSM modem, can any one tell which GSM modem will be better for this purpose, why can't we use mobile phones?
Thanks & regards
lsf_kan
http://www.sms-gateway-software.com
Rgds,
Joshua
Hi!
Thanks for the hint for opening COM ports higher than 9. It works fine with the CreateFile("\.\COMx", ...).
Bye!
Vero
i am new user of mscomm control.If you send me material fo making "mobile nokia 3315 using F-Bus protocol project".I will be thank full if you help me
e-mail:asif_kh7@yahoo.com
Hi all i am trying to communicate ny mobile nokia 3315 using F-Bus protocol when i try in VB i am gettin some data in responce with the mscomm but when i tried the same with VC++ i am not able to read the input of the data sent from control
confused:
if any one of u has any information regarding this please help
thanks in advance
bye:
> I have heard that MSCOMM can only handle upto 16 ports only.
> Is this really true?
Yes, MSCOMM only handles port numbers from 1 to 16. I have an issue with this as my laptop's docking station mapped the serial port in at number 27 (COM27
There must be a new mechanism/method of supporting COM ports in XP which completely abstracts the application from the hardware (OSs like Win95/98 provide a software layer, but you had the sense that you were addressing a physical port).
In my case, I think the answer is to find out how XP maps physical serial ports to the logical ports presented to the application layer, especially to legacy apps that only know about COM1 & COM2 (and perhaps COM3 & COM4), and so how to re-establish what I would consider 'normal' COM port numbers.
I have heard that MSCOMM can only handle upto 16 ports only.
Is this really true?
Thanks,
g
I have been trying to work with MSComm control. I am able to recieve messages but not send any. I am working on transmitting messages to a video modulator. The code works in VC++ though it is a different library. It does not work out in VB 6.0. The problem is not with the hardware. I got comEventFrame and comEventRxOver errors. My settings are proper. Can you help with the same?
Regards,
SR
How can I send a print job, directed to LPT1 , to a Network port programatically without pinning the network path to LPT1 at the command promt.(Win2k/XP)
How can i move a print job from one queue to another queue using windows API functions,structures and contants.I can receive the job info but not the job's data(Contents) itself.
change
hCOM = CreateFile(".\COM" & COMNum & "", 0, FILESHAREREAD + FILESHAREWRITE, sec, OPENEXISTING, FILEATTRIBUTENORMAL, 0)
to
hCOM = CreateFile("\.\COM" & COMNum & "", 0, FILESHAREREAD + FILESHAREWRITE, sec, OPENEXISTING, FILEATTRIBUTENORMAL, 0)
Instead of Clng(0), you can use 0&.
if u got the answer please send to me also vpbashir@eim.ae
I think u need to clear the buffer, before your commport load the second data in . it will be a very hard time when you first time do the commport connection. try your best
To send and receive SMS, Dinkum Technology Pte Ltd (Singapore) provides API. The features includes Send and Receive SMS, Maintain Phone Books, Voice Call, Data Call, Alarm and lot more.
http://www.dinkum.com.sg/products/hardware-wmapi.asp
WM-API is easy to use. It needs only 3 lines of code to send SMS from a Visual Basic application. It also supports Java, Visual C++, Delphi and .NET.
Dinkum is also distributors for Wavecom modems. You can purchase Wavecom Fastrack Modems, Quik Modem Modules, Integra Modem Modules from Dinkum Technology Pte Ltd. Please visit www.dinkum.com.sg for more details.
You can also send your questions on sending receiveing SMS and questions related to GSM modems to technical@dinkum.com.sg
James-
Perhaps you should mention that your code as posted, for checking the COM ports, doesn't work under Windows 98, ME, or CE.
In order for it to work under thoses OSes, you must make the following changes:
1) Change the 4th parameter in the declaration of CreateFile() from [courier new]lpSecurityAttributes As SECURITY_ATTRIBUTES[/courier new] to [courier new]lpSecurityAttributes As Any[/courier new]
2) When you call the CreateFile() function, change its 4th parameter to [courier new]ByVal CLng(0)[/courier new] . Just passing plain old 0 (zero) won't work.
The code as posted works under NT, 2000, and I would think later versions (XP), but I haven't tested it.
Cheers,
-Andrew
Thanks for prjMSComm, very useful. However I found and fixed a problem with the COMAvailable Function.
The problem appears to be that Createfile has a problem with the concatenation of ("COM" & COMNum & ""...etc) in the original function
I ran into this problem using an add-in 8 port com card and could not find COM 10 with the code snippet that I put into my project. Even though the project
actually requires only up to COM 9, I would not rest until I solved this. I did not find any relevant documentation about this condition researching the Createfile API function and ended up finding the solution on a Delphi posting! Serial I/O (RS232) Using Delphi (RS232)
Serial I/O (RS232) Using Delphi (RS232)
I have modified your "COMAvailable" function to use a helper function called "GetAlias" which simply parses the proper string to feed to the
"CreateFile" function.
I hope this is helpful...
'// This detects if a COM ports is available.
'// Used by the ListComPorts() procedure
'// Returns TRUE if the COM exists, FALSE if the COM does not exist
Public Function COMAvailable(COMNum As Integer) As Boolean
Dim hCOM As Long
Dim ret As Long
Dim sec As SECURITYATTRIBUTES
'New variable to hold results of GetAlias
Dim commHandle As String
'Original
'try to open the COM port
' hCOM = CreateFile("COM" & COMNum & "", 0, FILESHAREREAD + FILESHAREWRITE, sec, OPENEXISTING, FILEATTRIBUTENORMAL, 0)
'Modified
'get alias which works on all Com ports
commHandle = GetAlias(COMNum)
'revised call uses commHandle returned from "GetAlias" function
hCOM = CreateFile(commHandle & "", 0, FILESHAREREAD + FILESHAREWRITE, sec, OPENEXISTING, FILEATTRIBUTE_NORMAL, 0)
If hCOM = -1 Then
COMAvailable = False
Else
COMAvailable = True
'close the COM port
ret = CloseHandle(hCOM)
End If
End Function
'Patch function to allow CreateFile to get handle for Com Port higher than Com 9
Public Function GetAlias(nIndex As Integer) As String
Dim port As Integer
Dim result As String
port = nIndex
Select Case port
Case 1: result = "\.\COM1" 'Port 1
Case 2: result = "\.\COM2" 'Port 2
Case 3: result = "\.\COM3" 'Port 3
Case 4: result = "\.\COM4" 'Port 4
Case 5: result = "\.\COM5" 'Port 5
Case 6: result = "\.\COM6" 'Port 6
Case 7: result = "\.\COM7" 'Port 7
Case 8: result = "\.\COM8" 'Port 8
Case 9: result = "\.\COM9" 'Port 9
Case 10: result = "\.\COM10" 'Port 10
Case 11: result = "\.\COM11" 'Port 11
Case 12: result = "\.\COM12" 'Port 12
Case 13: result = "\.\COM13" 'Port 13
Case 14: result = "\.\COM14" 'Port 14
Case 15: result = "\.\COM15" 'Port 15
Case 16: result = "\.\COM16" 'Port 16
End Select
GetAlias = result
End Function
Hello, I need some hlep here, Dose MSCommm work with USB? I have Itegno300 with USB , can I deal with it via MSCOMM?
thank you for your prompt response!
A friend of mine gave me his machine to fix after he butchered it. He's run a 98 setup CD again and it gets as far as requesting the product registration. I don't want to enter a product key, but revert the machine back to it's original state. What files do I need to edit or remove to stop the machine booting into the setup screen every time and boot normally as it did before?
A simple solution would be to enter the product key and let it run but I don't want to bugger up all the applications that are currently installed and start re-installing all the stuff all over again. Any help would be appreciated :-)
Hi All,
I have just started using MSComm for serial comunication.
I have heard that we need to close port after we send data once..... and we again need to open port if we want to send data again.
Actually I am using this for communication with a device.
For the first message that I send, I do get an acknowledge.... but when I send the second message(command) I don't get an acknowledge.
Also how do we know whether data has actually been written on the port or not?
Can someone please help me on this.
Thanks all.
Please help me to get the SMS message to be stored in Database
hi
can you help me for get caller id from modem.
i use vc++ compiler and work with com port by
CreatFile function.
and use at command
i used following command but it not worked correctly
and i cant get caller id.
at+fclass=8
at+vcid=1
thanks
Hi
I want a program which can dial the number, if somebody pick-up the number, his phone no as well as name should be entered in my computer database. I have a list of all phone number along with their name. I suceeded in getting the phone number with honour name and also i am able to dial through my computer. The problem is when somebody pick-ups the phone, I am unaware of that and even if somebody press some button say 5, i am not able to trace the tone or data. I am using an external modem and it is configured properly. My source program is:
Private Sub cmdDial_Click()
On Error Resume Next
Dim str As String, dummy
str = InputBox("Enter the phone no", "Dialer", 27)
MSComm1.CommPort = 2
MSComm1.PortOpen = True
MSComm1.Output = "ATDT" + str + vbCr
Do
dummt = DoEvents()
Text1.Text = Text1 + MSComm1.Input 'StrConv(MSComm1.Input, vbUnicode)
Text2.Text = Text2 + MSComm1.Output 'StrConv(MSComm1.Output, vbUnicode)
Loop
End Sub
Private Sub Form_Load()
MSComm1.DTREnable = True
MSComm1.InBufferSize = 100
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText
MSComm1.NullDiscard = True
MSComm1.OutBufferSize = 100
MSComm1.RThreshold = 1
MSComm1.RTSEnable = True
MSComm1.Settings = "9600,N,8,1"
MSComm1.SThreshold = 1
MSComm1.Handshaking = comRTSXOnXOff ' GetSetting(App.Title, "Properties", "Handshaking", "") 'frmTerminal.MSComm1.Handshaking
End Sub
Private Sub MSComm1_OnComm()
On Error Resume Next
Dim i As Integer, j
For i = 0 To 1255
For j = 0 To 1255
Next
Next
Select Case MSComm1.CommEvent
Case comEventBreak ' A Break was received.
Case comEventFrame ' Framing Error
Case comEventOverrun ' Data Lost.
Case comEventRxOver ' Receive buffer overflow.
Case comEventRxParity ' Parity Error.
Case comEventTxFull ' Transmit buffer full.
Case comEventDCB ' Unexpected error retrieving DCB]
Case comEvCD ' Change in the CD line.
Text1.Text = test1.Text & "1"
Case comEvCTS ' Change in the CTS line.
Text1.Text = Text1.Text & "2"
Case comEvDSR ' Change in the DSR line.
Text1.Text = Text1.Text & "3"
Case comEvRing
Text1.Text = Text1.Text & " Ring" & vbCrLf
Case comEvReceive ' Received RThreshold # of
Text1.Text = Text1.Text & StrConv(MSComm1.Input, vbUnicode) & vbCrLf
Case comEvSend ' There are SThreshold number of
Text1.Text = Text1.Text & " 5 " & StrConv(MSComm1.Input, vbUnicode) & vbCrLf ' characters in the transmit
Case comEvEOF ' An EOF charater was found in
Text1.Text = Text1.Text & "6" ' the input stream
End Select
End Sub
Please help me how to solve this problem.
Pls help me how to recoeve message.Give the sample code.
The com ports are not listed thru VB but are available in the device manager of My Computer. How to go about?
Add one more \ in front of ".\COM" in line hCOM = CreateFile("\\.\COM" ....
i.e. Originally the line was
hCOM = CreateFile("\.\COM" ....
make it
hCOM = CreateFile("\\.\COM" ....
to work for comports above 9.
I am facing the same problem also! And the curious thing is that after unsuccesfully reading from the modem... all the data is thrown out when i connect with hyperterminal.
I used the "list available com ports" function and it worked great until I used a PCMCIA socket card that assigned the com port number 10 to the serial port. I couldnt get it to list. I went into device manager and changed it back to number 7 and it showed up fine.
Any suggestions?
Thanks
Pranav
Thanks for this great tutorial.
I would like to know How to use the MSComm control inside a Activex DLL, in other words, How can I use the control without obtain and Object Variable Definition error from the server application.
Regards,
Marcelo.
Great tutorial - got some serial weighing-scales implemented into our system in under an hour.
string Buffer = "ATDT 916016644844 \n";
Object oBuffer = (object)Buffer;
axNETComm1.PortOpen = true;
axNETComm1.set_Output(ref oBuffer);
Can anyone please give me some suggestions?????
Thanks,
Kendal
For whatever reason none of my comm ports are registering as available on either one of my computers (both w98se). When I try to run the program (the one with the screen shot on pg3)
I get:
Run-time error '380'
Invalid Property value
as far as I can tell this happens at the end of ListComPorts()
...
cboComm.ListIndex = 0 <----- Since nothing ever populated the cboBox, index is -1 and the assignment fails.
Has anybody else run into this problem?...I've tried adding ports through windows add hardware but no luck. Thanks for any help you can provide
--jeremy
hi thanks for your reply
please help me how to clear the buffer in the modem.
i am using AT+CMGR -> for receiving and At+CMGS -> for sending and AT+CMGD-> for deleting the message in the modem.
is there any command available to clear the buffer?
Thanks
Regards
Karthik
"hi
already i am using AT+CMGF=1 ( i.e in Text mode option ).
i am able to send and receive using the itegno modem. i only issue is that while receiving the message , i am getting the received message plus the previously sent message.
this happens only when too many messages are sent and received continuously.
please help me to solve this problem.
Thanking you
Karthik"
Are you sending message to your own number? That's why you see all the messages ? Did you clear the buffer ?
Please write e-mail directly to developers@itegno.com for more help
hi
already i am using AT+CMGF=1 ( i.e in Text mode option ).
i am able to send and receive using the itegno modem. i only issue is that while receiving the message , i am getting the received message plus the previously sent message.
this happens only when too many messages are sent and received continuously.
please help me to solve this problem.
Thanking you
Karthik
check if
AT+CMGF?
iF RETURN IS ZERO, PLEASE set at+cmgf=1 and at&w to save
Karthik,
check if
AT+CMGF?
iF RETURN IS ZERO, PLEASE set at+cmgf=1 and at&w to save
Hey,
Is this Karthik Nahender?
If so, send me email at dia.abavar@terra.com.br
If not, oh well.......
how to receive the telephone call through modem using Vb. actually it does not established the connection with telephone
Hi
I am Karthik and I am involved in developing a SMS Application using GSM Itegno modem. I am
facing some problems in reading the SMS message from modem. I am using C# language and
windows 2000 Professional operating System.
Problem
While reading a particular message, I am getting the message received along with the message I have sent previously from the modem. Please help to solve this issue.
Thanks you in advance
Regards
C.S.Karthikeyan
RIER
Why is this and what is the Fix.......
Thanks in advance .......Richard
I am currently using the RS232.vb module in VB.NET.
Thanks,
- Steve
Receiving no data when key is pressed after the phone is connected
pls help me its very very urgent
Forgot one thing: When passing the zero, use the syntax "ByVal 0&". This seems to pass a null pointer.
The problem (at least in Win 95) is Security Attributes. Change the Alias at the top of the function so that instead of taking his user defined SECURITY_ATTRIBUTES data structure, it takes a Long. Then, pass a zero (aka NULL) to indicate default security attributes. This seems to fix it.
i want to develope a online billing system
first i have to dial a telephone number by press the number on the telephone
how the dial number print in vb text box
I also would be very interested in a solution for a W98 PC.
My work around is to use the GetAvailablePorts function of the program which gets the COM port. Then just strip out the others
i need to know how to trace the numbers being pressed on the phone after a call is connected(MSComm)?.
but u didn't explain if there is something goes wrong, how we would solve theproblem ?
i got NO CARRIER response from my Itegno modem ?
so any idea ?
first i have to dial a telephone number by press the number on the telephone
how the dial number print in vb text box
hi, when I comm with my motor via com1, it show receive break and frame error. why is that? |I have set the "setting" 9600,7,1
hi virdi_ds,
trapping the callerid through the modem is the project i'm currently doing.
i got the caller id provision from the telephone company and have checked it.
but my conexant hcf data fax modem is not helping me in capturing the number.
may i know which modem ur using?
have u got idea of how a telephone conversation can be recorded?
please help
john
Hi, Ezmy!
I have just seen your message, and I have a problem with the communication with MSComm like your problem. I'm doing a communication between PC and one sort of multimeters, and it is possible for me to read the data from them but not to send command in order to control them.
If you would like, you could send to me your program and your question, and we will investigate what is the trouble.
Let's meeting by e-mail.
Chenel. carloslis13@hotmail.com
You should try using a laser scanner with rs232 and connecting it to an odbc data base. Thats a trip. Control is rock solid though.
Hi
I want a program which can dial the number, if somebody pick-up the number, his phone no as well as name should be entered in my computer database. I have a list of all phone number along with their name. I suceeded in getting the phone number with honour name and also i am able to dial through my computer. The problem is when somebody pick-ups the phone, I am unaware of that and even if somebody press some button say 5, i am not able to trace the tone or data. I am using an external modem and it is configured properly. My source program is:
Private Sub cmdDial_Click()
On Error Resume Next
Dim str As String, dummy
str = InputBox("Enter the phone no", "Dialer", 27)
MSComm1.CommPort = 2
MSComm1.PortOpen = True
MSComm1.Output = "ATDT" + str + vbCr
Do
dummt = DoEvents()
Text1.Text = Text1 + MSComm1.Input 'StrConv(MSComm1.Input, vbUnicode)
Text2.Text = Text2 + MSComm1.Output 'StrConv(MSComm1.Output, vbUnicode)
Loop
End Sub
Private Sub Form_Load()
MSComm1.DTREnable = True
MSComm1.InBufferSize = 100
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText
MSComm1.NullDiscard = True
MSComm1.OutBufferSize = 100
MSComm1.RThreshold = 1
MSComm1.RTSEnable = True
MSComm1.Settings = "9600,N,8,1"
MSComm1.SThreshold = 1
MSComm1.Handshaking = comRTSXOnXOff ' GetSetting(App.Title, "Properties", "Handshaking", "") 'frmTerminal.MSComm1.Handshaking
End Sub
Private Sub MSComm1_OnComm()
On Error Resume Next
Dim i As Integer, j
For i = 0 To 1255
For j = 0 To 1255
Next
Next
Select Case MSComm1.CommEvent
Case comEventBreak ' A Break was received.
Case comEventFrame ' Framing Error
Case comEventOverrun ' Data Lost.
Case comEventRxOver ' Receive buffer overflow.
Case comEventRxParity ' Parity Error.
Case comEventTxFull ' Transmit buffer full.
Case comEventDCB ' Unexpected error retrieving DCB]
Case comEvCD ' Change in the CD line.
Text1.Text = test1.Text & "1"
Case comEvCTS ' Change in the CTS line.
Text1.Text = Text1.Text & "2"
Case comEvDSR ' Change in the DSR line.
Text1.Text = Text1.Text & "3"
Case comEvRing
Text1.Text = Text1.Text & " Ring" & vbCrLf
Case comEvReceive ' Received RThreshold # of
Text1.Text = Text1.Text & StrConv(MSComm1.Input, vbUnicode) & vbCrLf
Case comEvSend ' There are SThreshold number of
Text1.Text = Text1.Text & " 5 " & StrConv(MSComm1.Input, vbUnicode) & vbCrLf ' characters in the transmit
Case comEvEOF ' An EOF charater was found in
Text1.Text = Text1.Text & "6" ' the input stream
End Select
End Sub
Please help me how to solve this problem.
I have connected my phone to modem and modem to my computer. what i need is, when somebody pick-up his phone as dial by me, i should be notified. I know how to dial others phone, but don't know how to receive the voice or data. kindly suggest.
I have a issue with MSComm, I will be receiving messages without any problems and all of a sudden, information will stop just coming in. Do you know any reason for this.
I already completed a program to communicate with 8052(microcontroller). when i sent a byte to get 8052 attention it seems that i havent received any acknowledgement from 8052. Until now i cannot figured out how to solve this problem. Is there anything wrong with the mscomm that the 8052 is not responding or it is the hardware problem?
I already completed a program to communicate with 8052(microcontroller). when i sent a byte to get 8052 attention it seems that the i havent received any acknowledgement from 8052. Until now i cannot figured out how to solve this problem. Is there anything wrong with the mscomm that the 8052 is not responding or it is the hardware problem?
Dim Communications As MSCommLib.MSComm
Set Communications = CreateObject("MSCommLib.MSComm")
This is if you want to instantiate the MSComm control as an object, so go to Project menu in your VB IDE and down to references and make sure you add the MSCommLib reference.
If you just want to use it as a control, then dont need to instantiate it as an object.
sal
Hi
I'm programming one monitor, sniffer, in VB for RS 232- that works nice when its set to ModeText,
but when I tryed for comInputModeBinary, the serial port assumes is a array,
Could you kindly help me?
Have a look at the code.
Private Sub Command1_Click()
Dim buffer0, buffer As String
Dim dados As String
Dim TheMsg() As Byte, sTemp$
Text1.Text = ""
If Not (MSComm1.PortOpen) Then
MSComm1.PortOpen = True
End If
MSComm1.InputMode = 1 ' Set InputMode to read binary data
' If MSComm1.InBufferCount > 0 Then
' buffer0 = MSComm1.Input
While w <= 204809
DoEvents
w = w + 1
sTemp = MSComm1.Input
TheMsg = sTemp
If UBound(TheMsg, 1) > -1 Then
'Dim p&, i&
'p& = LBound(TheMsg)
Text1 = Text1 & UBound(TheMsg, 1)
End If
'Text1 = StrConv(MSComm1.Input, vbFromUnicode)
'dados = (Mid(MSComm1.Input, w, 1)) 'convert each binay value to ASCII
'If dados <> "" Or dados <> Null Then
'buffer = Asc(Mid(MSComm1.Input, w, 1)) 'convert each binay value to ASCII
'buffer0 = Hex(Mid(buffer, w, 1)) 'convert each binay value to ASCII
'Text1.Text = Text1.Text + buffer + Chr$(32)
'End If
Wend
' Text1.Text = Text1 + buffer
' End If
w = 0
End Sub
I'm programming one monitor, sniffer, in VB for RS 232- that works nice when its set to ModeText,
but when I tryed for comInputModeBinary, the serial port assumes is a array,
Could you kindly help me?
Thanks
->The Code:
Private Sub Command1_Click()
Dim buffer0, buffer As String
Dim dados As String
Dim TheMsg() As Byte, sTemp$
Text1.Text = ""
If Not (MSComm1.PortOpen) Then
MSComm1.PortOpen = True
End If
MSComm1.InputMode = 1 ' Set InputMode to read binary data
' If MSComm1.InBufferCount > 0 Then
' buffer0 = MSComm1.Input
While w <= 204809
DoEvents
w = w + 1
sTemp = MSComm1.Input
TheMsg = sTemp
If UBound(TheMsg, 1) > -1 Then
'Dim p&, i&
'p& = LBound(TheMsg)
Text1 = Text1 & UBound(TheMsg, 1)
End If
'Text1 = StrConv(MSComm1.Input, vbFromUnicode)
'dados = (Mid(MSComm1.Input, w, 1))
'If dados <> "" Or dados <> Null Then
'buffer = Asc(Mid(MSComm1.Input, w, 1)) 'convert each binay value to ASCII
'buffer0 = Hex(Mid(buffer, w, 1)) 'convert each binay value to ASCII
'Text1.Text = Text1.Text + buffer + Chr$(32)
'End If
Wend
' Text1.Text = Text1 + buffer
' End If
w = 0
End Sub
As I can know when they answered I telephone using the MSComm
my code is :
Private Sub InicializarModem()
With msModem
.CommPort = 3
.Handshaking = comRTSXOnXOff
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.EOFEnable = True
.InputMode = comInputModeText
.InputLen = 0
.PortOpen = True
.Output = "ATZ"
.PortOpen = False
End With
end sub
Private Sub CallNumber(Byval sOutput as String)
With msModem
.PortOpen = True
.Output = "ATDT" & sOutput & vbCrLf
End With
end sub
Private Sub msModem_OnComm()
'Occurs when there's a change in the modem signal
Dim InBuff As String
Select Case msModem.CommEvent
'Case comEventBreak : A Break was received from the line : not required
'The next three cases are timeout values, no longer detected in Win32 systems
'Case comEventCDTO
'Case comEventCTSTO
'Case comEventDSRTO
'Case comEventFrame
Case comEventOverrun ' Data Lost during transfer
MsgBox "Some Data was lost during transfer."
Case comEventRxOver ' Receive buffer overflow.
'taken care in another sub in form2
Case comEventRxParity ' Parity Error.
MsgBox "Parity Error !"
Case comEventTxFull ' Transmit buffer full.
'taken care in another module in form2
Case comEvCD ' Change in the CD line.
'Used to detect connection state :
'Though it's taken care by using ATX4 modem command, it's required
'for AT non compatible modems
If msModem.CDHolding = True Then
'connected
Connected = True
Else
'Disconnected
Connected = False
End If
Case comEvReceive 'Received RThreshold no. of chars.
'Use strconv to convert the binary data got from modem
'InBuff = StrConv(msModem.Input, vbUnicode)
InBuff = msModem.Input
Call ScanCom(InBuff)
Case comEvSend 'There are SThreshold number of characters in the
'transmit buffer.(this should never occur as there's form2, but, in case)
Do While msModem.OutBufferCount > 0
DoEvents
Loop
End Select
End Sub
Private Sub ScanCom(ByVal instring As String)
' This routine will work on data (instring) received from the Com Port.
Dim X As Integer 'position being read from instring
Dim Y As String 'data in position being read (X)
If Connected = False Then
' Not connected...so data may be modem responce.
' Work on data (instring) received between vbcrlf's:
For X = 1 To (Len(instring) + 1)
Y = Mid$(instring, X, 1)
If Y = Chr$(13) Then
Y = ""
'"MessageHandler" is where to do the processing on
' the packet after it is fully parsed here:
Call MessageHandler(UseString)
UseString = ""
End If
UseString = UseString & Y
Next X
Else
'Connected=true. So parse data.
'Data begins with <modem> , ends with <xodem> + chr$(13)
For X = 1 To (Len(instring) + 1)
Y = Mid$(instring, X, 1)
If Y = Chr$(13) Then
If Len(UseString) > 11 And Right(UseString, 7) = "<xodem>" Then
Y = ""
Call MessageHandler(UseString)
'Process the data
UseString = ""
End If
End If
UseString = UseString & Y
Next X
End If
End Sub
Private Sub MessageHandler(InBuff As String)
If IsVacio(InBuff) Then Exit Sub
If InStr(1, InBuff, "=") <> 0 Then Exit Sub
If Len(InBuff) <= 1 Then Exit Sub
InBuff = Right(InBuff, Len(InBuff) - 1)
'Modem responses
'Occurs when a command sent to modem is accepted
If InStr(InBuff, "OK") Then
InBuff = ""
Exit Sub
End If
'if command "ATX4" has been sent to modem,
'inbuff will be "CONNECT #####" where ##### = speed
'connected to remote comp
If InStr(InBuff, "CONNECT") Then
Connected = True
lblLlamada(3) = "CONECTADO"
strHoraInicioLlamada = Format(Time, "HH:MM
InBuff = ""
Exit Sub
End If
If InStr(InBuff, "CARRIER") Then
If MsgBox("No se recibio respuesta del telefono marcado, desea capturar alguna observación ?", vbYesNo + vbQuestion, "Automarcado") = vbYes Then
tmpObs = InputBox("Capture aqui las observaciones de la llamada", "Automarcado", " ")
If tmpObs <> "" Then
txtObservacionesLlamada = "" & UCase(tmpObs)
End If
End If
InBuff = ""
Call ActualizaEstatusLlamada(NO_CONTESTO)
txtObservacionesLlamada = ""
Call ColgarTelefono
Call Actualiza
' Se mueve al siguiente registro
If TDBG1.EOF Then
TDBG1.MoveFirst
Else
TDBG1.MoveNext
End If
Exit Sub
End If
If InStr(InBuff, "ERROR") Then
InBuff = ""
MsgBox "Ocurrio un error al marcar al número " & TDBG1.Columns("TelCasa"), vbCritical
Exit Sub
End If
Halo,
I can fire the commevent but not always...that's make my prg not consistant.. any help
Hi,
I faced the same prob with you. can some one offer help!!
by the way, I'm doing the sms thing I'm can send out the msg but can't receive the msg. why ah?
If you don't mind sharing, what was your workaround.
Terry
no real answer, I have used alternate means to read the com port that works (sort of)
kevin
Kevin,
Have you found a solution to this yet? I am having the same problem (error 424).
I would appreciate any insight you may have.
Terry
How do i create a marquee script for an email signature....ive seen it on someones email they sent me and it looks so cool, i am on a works network p.c so i dont know if i am able to do it or not, please supply the code and instructions if poss
kind regards
chris
i have a copy (from legit source) of mscomm ocx and have added to available controls, but vb 6 does not recognise mscomm (says it need an object declaration) - the downloaded code from here causes error - any thoughts?
kevin
Please help me regarding the usage of the MSComm control.Iam able to recieve messages but not able to transmit messages.I can clearly hear the other parties voice but they r not able to hear me.
Dear All,
I got some problem when I try to capture data using the onComm1.commEvent
Case comEvReceive
' receive log here
inBuffer = inBuffer & MSComm1.Input
Debug.Print MSComm1.Input
I have to put the break point infront of the MsComm1_OnComm() inorder to have it fire.
my configure of MsComm1 is:
Private Sub Form_Load()
With MSComm1
.CommPort = 1
.Handshaking = comRTSXOnXOff
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.PortOpen = True
.EOFEnable = True
.InputMode = comInputModeText
.InputLen = 0
End With
End Sub
According to the posting above it should be working fine.
But for my case it was not .
Help,
Many Thanks
Hi Ashsoliman,
I'm having that problem too, actually with Win Me, but I suspect it doesn't work with any non-XP/2000/NT PCs.
I have based a port detection part of a project I'm working on around this method, and it worked fine until I came to install the final program on a Win Me system.
Have you found a solution yet ??
I'll let you know if I find one.
Cheers
Mark
OK guys, don't all rush to help ... sussed it anyway!!
Anyone experiencing the same problem, use comInputModeBinary reception mode and receive the entire buffter into a byte array, then get the size of the array using UBound (+1 to include the first byte stored in the zero element) and write your decoding routine within a for next loop to work through each received byte. (Did that make any sense??
Mark H
Can i transfer a file to my friend with whom i am talking on a phone by holding on the connection using the mscomm control?
(this refers to use of voiceview at-commands). please help me out.
I tried using your comport example but it didn't work on windows 98. is there any supporting DLL's or components I need to attach to my project.
Hi,
Hopefully there's a simple solution to this one, but I'm pulling my hair out right now, coz I've tried everyway I can think of ....
Please forgive me if I'm overlooking the obvious, but though I'm an experienced programmer, I am very new to VB!
I am trying to write an application to emulate a thermal printer to allow printing 'through' a PC. The received data includes nulls/zeros, mainly as part of command properties, which I need the app to recognise.
I have tried to receive the data as text (comInputModeText) but as null is an empty string, that doesn't work! I have tried receiving the data numerically (comInputModeBinary) but as soon as I try to run the app with 'NullDiscard' as false it hangs, seemingly receiving infinate nulls/zeros, long after the input data has ceased. The program does not hang if I set 'NullDiscard' to true, but of course then I don't get my nulls!!
Please Help!! ... anyone!!
Cheers,
Mark H
Hello,
How can receive the numbers pressed by anyone while I am talking with him/her via telephone. I think this is the way PABX works.
My compiler is showing syntax error with the following code-
txtOutput.Text = txtOutput.Text & StrConv(MSComm1.Input, vbUnicode)
Please help...
Anup
Can we use mscomm control to read synchronous binary data. If yes, please tell me how?
Thank you.
hi..there...
I would like to ask you the following questions.
1. If I open my Com port, does it mean I am always listening to incoming data from that com port?
2. If it does not keep listening, how do I do the polling in my program so that it will keep listening to incoming data from that com port?
Hope you would like to answer my questions....
Thank You very much
Nelly
This thread is for discussions of Com Ports and the MSComm Control.