Results 1 to 4 of 4

Thread: MSComm in class???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Antrim
    Posts
    80

    Talking MSComm in class???

    Hi,

    I'm building an object oriented solution for work at the moment.

    I need to send and recieve information via the com port. I can't get a comm control into my class without adding a form to my dll project (which I hate doing).

    Does anyone know of a way to re-use the comm control in code or else another means of sending and recieving data through the comm port.

    Any suggestions would be much appreciated.

    Best regards,

    Rob Brown.

  2. #2
    Keith Bradley
    Guest

    Talking Yea, Tell Us About it Rob! Try dis

    Berite there may or may not be something in the attached file to interest you It does not use MScomm.

    See ya in work on Monday

    K

    Text Included with the example :

    VB Port Test, Visual Basic 6 Sample

    This program will try to open a specified range of ports and
    then transfer packets of 128 Bytes each.

    The transfers are not overlapped (or multi-threaded) therefore if one port is not
    working and is waiting for the timeout, then the whole program
    waits.

    For some undertmined (at this time) reason, the program does
    not want to compile and run correctly unless you compile it to
    P-Code.

    Please be advised that this program is for reference only and
    has in no way been written and/or tested for daily usage.

  3. #3
    Keith Bradley
    Guest

    Cool more........

    The most reliable method in 32 bit Windows is to use the CreateFile, WriteFile, ReadFile and CloseHandle API calls. Do not try to use MSComm.ocx. It is very unreliable.

    Here is a VB code snippet to initialise com1. It was written to output only
    and share the port but it should give you the basics.



    Dim CommDCB As DCB
    Outfile = -1
    Picture1.Cls
    du = BuildCommDCB("9600,n,8,1", CommDCB) 'create device control block
    for com1
    CommDCB.fBitFields = fBinary + fOutxCtsFlow + fOutX 'file attributes
    If du <> 0 Then
    Outfile = CreateFile("com1:", GENERIC_READ_WRITE, FILE_SHARE_READ +
    FILE_SHARE_WRITE, 0, OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL, 0)
    End If
    If Outfile = -1 Then
    MsgBox "Could not open com1"
    Else
    du = SetCommState(Outfile, CommDCB) 'initialise port
    If du = 0 Then
    Outfile = -1
    MsgBox "Unable to set comm state"
    Else
    LineTrack = 0
    Status.Caption = "Transmitting data"
    Status.Refresh
    End If
    End If




    To write data to the port use the WriteFile API call
    To read from the port use the ReadFile API call
    To close the port use the CloseHandle API call

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    check out this thread hope it does help you

    regards,

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