Страница: 1 |
|
Вопрос: Как набрать номер телефона в MSComm?
|
Добавлено: 25.08.04 11:21
|
|
Автор вопроса: LamerOnLine | ICQ: 334781088
|
Че-то я не догнал немного - как с помощью MSComm Control дозвониться куда-либо. Где номер-то указывать?
Ответить
|
Номер ответа: 3 Автор ответа: LamerOnLine
ICQ: 334781088
Вопросов: 108 Ответов: 2822
|
Профиль | | #3
|
Добавлено: 25.08.04 12:59
|
Ну вот маленький примерчик из MSDN
Knowledge Base Articles
INFO: Receiving Data Using the MSComm Control's OnComm Event
Q194922
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Visual Basic Learning Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0
--------------------------------------------------------------------------------
SUMMARY
This article demonstrates a basic template for using an event driven data receiving routine with the OnComm event. This is the recommended method of receiving all types of data using the MSComm control. For information on converting binary data, please see the REFERENCES section at the end of this article.
MORE INFORMATION
When using the MSCOMM control to send and receive serial data, it is best to use event driven communications. This method is more efficient than polling, as it uses less CPU time and will only initiate an action when input is received. Below is a simple template to use which will allow for very efficient receiving of characters with minimal data loss.
The idea is to use the OnComm event to receive the data, then write the raw data to a string and pass it to another routine to do the processing of the raw data. Passing the data to another routine allows the OnComm event to receive every event without being "suppressed," while the actual parsing of the string takes place elsewhere.
The following example will assume that you have a null modem cable attached between COM1 and COM2. This is only necessary for testing. App1 is the COM1 application, App2 is the COM2 application.
Steps to Create App1
Create a new Standard EXE project. Form1 is created by default.
Choose Components from the Project menu, check the "Microsoft Comm Control," and click OK.
Add an MSCOMM control to the form.
Add a TextBox and a CommandButton to the form. Change the MultiLine property of the TextBox to True.
Add the following code to Form1's code window:
Private Sub Form_Load()
Form1.Caption = "App1"
With MSCOMM1
.Handshaking = 2 - comRTS
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.PortOpen = True
' Leave all other settings as default values.
End With
Command1.Caption = "&Send"
Text1.Text = "Test string from App1 "
End Sub
Private Sub Command1_Click()
MSComm1.Output = Text1.Text
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
Steps to Create App2
Start a new instance of Visual Basic.
Create a new Standard EXE project. Form1 is created by default.
Choose Components from the Project menu, check the "Microsoft Comm Control," and click OK.
Add an MSCOMM control to the form.
Add a TextBox to the form. Change the MultiLine property of the TextBox to True. Enlarge the TextBox so it will cover most of the form, as you will be displaying all the received data in it.
Add the following code to Form1's code window:
Private Sub Form_Load()
Form1.Caption = "App2"
With MSComm1
.CommPort = 2
.Handshaking = 2 - comRTS
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.PortOpen = True
' Leave all other settings as default values.
End With
Text1.Text = ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
 im InBuff As String
Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement.
' This template is found in the Example
' section of the OnComm event Help topic
' in VB Help.
' Errors
Case comEventBreak ' A Break was received.
Case comEventCDTO ' CD (RLSD) Timeout.
Case comEventCTSTO ' CTS Timeout.
Case comEventDSRTO ' DSR Timeout.
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]
' Events
Case comEvCD ' Change in the CD line.
Case comEvCTS ' Change in the CTS line.
Case comEvDSR ' Change in the DSR line.
Case comEvRing ' Change in the Ring Indicator.
Case comEvReceive ' Received RThreshold # of chars.
InBuff = MSComm1.Input
Call HandleInput(InBuff)
Case comEvSend ' There are SThreshold number of
' characters in the transmit buffer.
Case comEvEOF ' An EOF character was found in the
' input stream.
End Select
End Sub
Sub HandleInput(InBuff As String)
' This is where you will process your input. This
' includes trapping characters, parsing strings,
' separating data fields, etc. For this case, you
' are simply going to display the data in the TextBox.
Text1.SelStart = Len(Text1.Text)
Text1.SelText = InBuff
End Sub
Steps to Run Applications
Press the F5 key or click the run button on each project. You will need to move the apps around so you can see them both running at the same time.
Make sure you have a standard null modem cable between COM1 and COM2, or change the MSComm1.Port properties to match the comm ports you are using.
Click the CommandButton on App1; you should see the string "Test string from App1" appear in App2's TextBox for each button click.
REFERENCES
For information on converting binary data, please see the following article in the Microsoft Knowledge Base:
Q158008 : HOWTO: Use MSCOMM32.OCX to Transfer Data on DBCS Windows
For additional information, please see the following article in the Microsoft Knowledge Base:
Q194923 : HOWTO: Trap Control Characters Using the MSComm Control
Additional query words: mscomm
Keywords : kbcode kbIO kbVBp kbVBp500 kbVBp600 kbGrpDSVB kbCodeSam
Issue type : kbinfo
Technology : kbVBSearch kbAudDeveloper kbZNotKeyword6 kbZNotKeyword2 kbVB500Search kbVB600Search kbVB500 kbVB600
Last Reviewed: July 24, 2001
--------------------------------------------------------------------------------
Send feedback to Microsoft
© 2002 Microsoft Corporation. All rights reserved.
Ответить
|
Страница: 1 |
Поиск по форуму