Results 1 to 3 of 3

Thread: Comm Starter

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    6

    Arrow Comm Starter

    Hi im trying to access the com port with VB6 programming does anyone have any code to get me on my way....

  2. #2
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    I've been trying to do that for the longest while without the use of 3rd party controls....

    Currently I'm still looking...

    Anyone with a solution?
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  3. #3
    New Member
    Join Date
    Dec 2003
    Posts
    2
    I have created an application that communicates with a modem connected to a com port. This uses 'Microsoft comm control 6.0' (MSCOMM32.OCX).

    I have put one of these controls and a timer on a form. The application answers the phone when it rings, and then disconnects after a given time. the code is below, hope it is of some use.


    ####Code Below####

    Option Explicit
    Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    Private Declare Function WritePrivateProfileSection Lib "Kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
    Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long


    Private Sub ListenForRing()

    ' Buffer to hold input string
    Dim DataString As String
    Dim rc As Long

    DataString = String(255, 0)

    Dim Instring As String
    Dim Comm_Baud As String
    Dim Comm_Port As Integer
    Dim Comm_Parity As String
    Dim Comm_Data As String
    Dim Comm_Stop As String
    Dim Comm_Rings As String
    Dim Comm_Buffer As Integer

    rc = GetPrivateProfileString("COMMS", "PORT", "3", DataString, 10, "C:\windows\MODEMANS.INI")
    Comm_Port = Val(DataString)
    rc = GetPrivateProfileString("COMMS", "BAUD", "4800", DataString, 10, "C:\windows\MODEMANS.INI")
    Comm_Baud = Trim$(Str$(Val(DataString)))
    rc = GetPrivateProfileString("COMMS", "PARITY", "n", DataString, 10, "C:\windows\MODEMANS.INI")
    Comm_Parity = Left$(DataString, 1)
    rc = GetPrivateProfileString("COMMS", "DATA BIT", "8", DataString, 10, "C:\windows\MODEMANS.INI")
    Comm_Data = Trim$(Str$(Val(DataString)))
    rc = GetPrivateProfileString("COMMS", "STOP BIT", "1", DataString, 10, "C:\windows\MODEMANS.INI")
    Comm_Stop = Trim$(Str$(Val(DataString)))
    rc = GetPrivateProfileString("COMMS", "RINGS", "1", DataString, 10, "C:\windows\MODEMANS.INI")
    Comm_Rings = Trim$(Str$(Val(DataString)))
    rc = GetPrivateProfileString("COMMS", "BUFFER", "22", DataString, 10, "C:\windows\MODEMANS.INI")
    Comm_Buffer = Val(DataString)

    'Comm_Baud "," + Comm_Port + "," + Comm_Parity + "," + Comm_Data + "," + Comm_Stop

    ' Use COM1.
    MSComm1.CommPort = Comm_Port
    ' 9600 baud, no parity, 8 data, and 1 stop bit.
    MSComm1.Settings = Comm_Baud + "," + Comm_Parity + "," + Comm_Data + "," + Comm_Stop '"4800,N,8,1"
    ' Tell the control to read entire buffer when Input
    ' is used.
    MSComm1.InputLen = 0
    ' Open the port.
    MSComm1.PortOpen = True
    ' Send the attention and answer on first ring commands to the modem.
    MSComm1.Output = "AT S0=" + Comm_Rings + Chr$(13)
    ' Wait for data to come back to the serial port.

    Do
    DoEvents
    Loop Until MSComm1.InBufferCount >= Comm_Buffer

    ' Read the "OK" response data in the serial port.

    Instring = MSComm1.Input

    Timer1.Enabled = True
    End Sub

    Private Sub cmdQuit_Click()
    End
    End Sub

    Private Sub Form_Load()


    Dim DataString As String
    Dim rc As Integer
    'Get value for timer (in seconds)

    If App.PrevInstance = True Then
    MsgBox "Program already running.", vbCritical, "Modem Answer"
    End
    End If

    DataString = String(255, 0)

    rc = GetPrivateProfileString("TIMING", "ANSWERTIME", "<no file>", DataString, 10, "C:\windows\MODEMANS.INI")
    If Val(DataString) < 1 Then
    rc = WritePrivateProfileString("TIMING", "ANSWERTIME", "55", "C:\windows\MODEMANS.INI")

    rc = WritePrivateProfileString("COMMS", "PORT", "3", "C:\windows\MODEMANS.INI")
    rc = WritePrivateProfileString("COMMS", "BAUD", "4800", "C:\windows\MODEMANS.INI")
    rc = WritePrivateProfileString("COMMS", "PARITY", "n", "C:\windows\MODEMANS.INI")
    rc = WritePrivateProfileString("COMMS", "DATA BIT", "8", "C:\windows\MODEMANS.INI")
    rc = WritePrivateProfileString("COMMS", "STOP BIT", "1", "C:\windows\MODEMANS.INI")

    rc = WritePrivateProfileString("COMMS", "RINGS", "1", "C:\windows\MODEMANS.INI")
    rc = WritePrivateProfileString("COMMS", "BUFFER", "22", "C:\windows\MODEMANS.INI")

    rc = GetPrivateProfileString("TIMING", "ANSWERTIME", "<no file>", DataString, 10, "C:\windows\MODEMANS.INI")

    End If
    Timer1.Interval = Val(DataString) * 1000

    'Start program running with timer value got from INI
    ListenForRing
    End Sub



    Private Sub Timer1_Timer()
    ' Close the serial port.
    MSComm1.PortOpen = False
    'Switch off timer
    Timer1.Enabled = False

    'Restart program
    ListenForRing


    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width