您现在所在的是:

串口通信

回帖:0个,阅读:7587 [上一页] [1] [下一页]
29673
思南 管理员
文章数:14047
年度积分:62
历史总积分:29673
注册时间:2001/3/12
发站内信
发表于:2001/8/18 7:57:00
#0楼
好象是直接使用AT指令完成的拨号。

Communications under Win32 have been simplified to use standard Windows file functions, such as CreateFile(), WriteFile(), and CloseHandle().

The following steps show you how to create and use the DialNumber() function in Microsoft Access.

1、Open the sample database Northwind.mdb.

2、Create a module and type the following line in the Declarations section.

NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.

NOTE: All Declare statements must be typed exactly as shown, including capitalization, because Win32 names are case-sensitive. To help eliminate errors by you or others who use your Declare statements, create Alias clauses for Declare statements that do not have an existing Alias. As long as the Alias is correctly spelled and capitalized, it doesn't matter how the function name is capitalized.
          Option Explicit
     Declare Function WriteFile& Lib "kernel32" _
        (ByVal hFile As Long, lpBuffer As Any, _
        ByVal nNumberOfBytesToWrite&, _
        lpNumberOfBytesWritten&, ByVal lpOverlapped&)
     Declare Function CreateFile& Lib "kernel32" Alias "CreateFileA" _
        (ByVal lpFileName$, ByVal dwDesiredAccess&, _
        ByVal dwShareMode&, ByVal lpSecurityAttributes&, _
        ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, _
        ByVal hTemplateFile&)
     Declare Function CloseHandle& Lib "kernel32" (ByVal hObject&)
     Declare Function FlushFileBuffers& Lib "kernel32" (ByVal hFile&)

     ' The number of seconds to wait for the modem to dial before
     ' .. resetting the modem. If the phone hangs up prematurely
     ' .. try increasing this value by small increments.
     Public Const WAITSECONDS = 4

     Public Const ID_CANCEL = 2
     Public Const MB_OKCANCEL = 1
     Public Const MB_ICONSTOP = 16, MB_ICONINFORMATION = 64



3、Type the following procedure:

     Function DialNumber(PhoneNumber, CommPort As String)
     ' PURPOSE: To dial a telephone number using the computer's modem
     ' ARGUMENTS:
     '    PhoneNumber: The telephone number to dial
     '    CommPort: The communications port the modem is connected
     '              to. Typically, modems are found on COM2, however,
     '              they can be configured for any COM port.
     '
     ' EXAMPLE:
     '    Type the following in the Immediate window using a modem
     '    connected to the COM2 port:
     '
     '       ? DialNumber("555-1212", "COM2")
     '
     ' ***********************************************************

        Dim Msg As String, MsgBoxType As Integer, MsgBoxTitle As String
        Dim bModemCommand(256) As Byte, ModemCommand As String
        Dim OpenPort As Long
        Dim RetVal As Long, RetBytes as Long, i as integer
        Dim StartTime

        ' Ask the user to pick up the phone.
        Msg = "Please pickup the phone and choose OK to dial " _
           & PhoneNumber
        MsgBoxType = MB_ICONINFORMATION + MB_OKCANCEL
        MsgBoxTitle = "Dial Number"
        If MsgBox(Msg, MsgBoxType, MsgBoxTitle) = ID_CANCEL Then
           Exit Function
        End If

        ' Open the communications port for read/write (&HC0000000).
        ' Must specify existing file (3).
        OpenPort = CreateFile(CommPort, &HC0000000, 0, 0, 3, 0, 0)
        If OpenPort = -1 Then
           Msg = "Unable to open communication port " & CommPort
           GoTo Err_DialNumber
        End If

        ' Send the telephone number to the modem.
        ModemCommand = "ATDT" & PhoneNumber & vbCrLf
        ' Pack the string in a Byte array.
        For i = 0 To Len(ModemCommand) - 1
           bModemCommand(i) = Asc(Mid(ModemCommand, i + 1, 1))
        Next

        ' Write the string to the Com port.
        RetVal = WriteFile(OpenPort, bModemCommand(0), _
           Len(ModemCommand), RetBytes, 0)
        If RetVal = 0 Then
           Msg = "Unable to dial number " & PhoneNumber
           GoTo Err_DialNumber
        End If

        ' Flush the buffer to make sure it actually wrote
        RetVal = FlushFileBuffers(OpenPort)

        ' Wait WAITSECONDS seconds for the phone to dial.
        StartTime = Timer
        While Timer < StartTime + WAITSECONDS
           DoEvents
        Wend

        ' Reset the modem and take it off line.
        ModemCommand = "ATH0" & vbCrLf
        ' Pack the byte array again.
        For i = 0 To Len(ModemCommand) - 1
           bModemCommand (i) = Asc(Mid(ModemCommand, i + 1, 1))
        Next
        RetVal = WriteFile(OpenPort, bModemCommand(0), _
           Len(ModemCommand), RetBytes, 0)

        'Flush the buffer again.
        RetVal = FlushFileBuffers(OpenPort)

        ' Close the communications port.
        RetVal = CloseHandle(OpenPort)

        Exit Function

     Err_DialNumber:      'This is not an On Error routine.
        Msg = Msg & vbCr & vbCr & _
           "Make sure no other devices are using Com port " & CommPort
        MsgBoxType = MB_ICONSTOP
        MsgBoxTitle = "Dial Number Error"
        MsgBox Msg, MsgBoxType, MsgBoxTitle

     End Function



4、Open the Employees form in Design view.

5、Add a command button next to the Home Phone field and set the following properties:


Command Button:
Name: btnDialPhone
Caption: Dial
OnClick: =DialNumber([HomePhone], "COM2")


6、View the form in Form view. To dial an employee's home phone number, click the Dial button.

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

46.8003