COMmunication Problem... 
Author Message
 COMmunication Problem...

Hi there!,

I have problems using the WriteFile API call in VB5.0.
I want to write a VERY small app for some easy communications!

I use(d) the following code for some testing if I could do it, but it seems
I can't.
Please someone tell me what I'm doing wrong...

- - CODE STARTS HERE - -
 hCom = CreateFile("COM3", GENERIC_READ, 0, Empty, OPEN_EXISTING, 0, Empty)

  sInBuffer = "ATI1" + vbCr
  nInBufferSize = Len(sInBuffer)
  l = WriteFile(hCom, sInBuffer, nInBufferSize, lBytesReturned, Empty)

 CloseHandle hCom
- - CODE ENDS HERE - -

I also wonder why I can't use Null for this variable like the Example in the
Windows API-Help does (for C++ anyway)

PLEASE HELP ME!

Greets

Quote:
>> {*filter*}SnooP >>

P.S. Sorry for my bad English, I'm from Holland (so answering in Dutch is
allowed :-)


Mon, 10 Dec 2001 03:00:00 GMT  
 COMmunication Problem...
One apparent problem that jumps right out at me is that you open the COM
port for *read* only, then the only operation you attempt to perform is a
*write*. Perhaps you should try opening the COM port for read and write
access.

Steve


Quote:
> Hi there!,

> I have problems using the WriteFile API call in VB5.0.
> I want to write a VERY small app for some easy communications!

> I use(d) the following code for some testing if I could do it, but it
seems
> I can't.
> Please someone tell me what I'm doing wrong...

> - - CODE STARTS HERE - -
>  hCom = CreateFile("COM3", GENERIC_READ, 0, Empty, OPEN_EXISTING, 0,
Empty)

>   sInBuffer = "ATI1" + vbCr
>   nInBufferSize = Len(sInBuffer)
>   l = WriteFile(hCom, sInBuffer, nInBufferSize, lBytesReturned, Empty)

>  CloseHandle hCom
> - - CODE ENDS HERE - -

> I also wonder why I can't use Null for this variable like the Example in
the
> Windows API-Help does (for C++ anyway)

> PLEASE HELP ME!

> Greets
> >> {*filter*}SnooP >>

> P.S. Sorry for my bad English, I'm from Holland (so answering in Dutch is
> allowed :-)



Mon, 10 Dec 2001 03:00:00 GMT  
 COMmunication Problem...
van Leur wrote :

Quote:

> I have problems using the WriteFile API call in VB5.0.
> I want to write a VERY small app for some easy communications!

> - - CODE STARTS HERE - -
>  hCom = CreateFile("COM3", GENERIC_READ, 0, Empty, OPEN_EXISTING, 0, Empty)

Try this:

Public TimeOuts As COMMTIMEOUTS
Public myDcb As DCB
Public hCom As Long

    hCom = CreateFile("\\.\com3", GENERIC_READ + GENERIC_WRITE, 0, 0,
OPEN_EXISTING, 0, 0)
    InitComm hCom, 57600, 1024, 1024
    sBuffer = "ATI1" + vbCr
    nBufferSize = Len(sBuffer)
    WriteFile hCom, sBuffer, nBufferSize, lBytesReturned, 0
    if nBufferSize <> lBytesReturned Then debug.print "Write error"
    CloseHandle hCom

Public Function InitComm(hCom As Long, BaudRate As Long, ReadBufferLen
As Integer, WriteBufferLen As Integer) As Long
    On Error Resume Next
    If hCom = -1 Then
        CloseHandle hCom
    Else
        ' Timeouts initialization
        TimeOuts.ReadIntervalTimeout = 0
        TimeOuts.ReadTotalTimeoutMultiplier = 0
        TimeOuts.ReadTotalTimeoutConstant = 200 ' 200 ms timeout
        TimeOuts.WriteTotalTimeoutMultiplier = 0
        TimeOuts.WriteTotalTimeoutConstant = 0

        ' Get the current DCB
        myDcb.DCBlength = 28
        GetCommState hCom, myDcb

        ' The following lines depend of the settings of the
        ' communication that you need (protocol, parity, etc...)
        ' See the MSDN documentation
        myDcb.BaudRate = BaudRate
        myDcb.ByteSize = 8
        myDcb.Parity = NOPARITY
        myDcb.StopBits = ONESTOPBIT
        myDcb.fFlags = &H1011&
        myDcb.XoffLim = CInt(0.8 * ReadBufferLen)
        myDcb.XonLim = CInt(0.2 * ReadBufferLen)

        ' Set the new DCB
        SetCommState hCom, myDcb

        ' Set the read and write buffers
        SetupComm hCom, ReadBufferLen , WritedBufferLen
        SetCommTimeouts hCom, TimeOuts
    End If
    InitComm = hCom
End Function

Hope this help...
--



Tue, 11 Dec 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Communication problems, not relation problems:)

2. Communication Problem

3. Communications Problem in QuickBasic

4. QB$% QB45, serial communications problem

5. communications problem

6. Serial Communications Problem

7. Sportrak pro communications problem

8. IO Communication problem

9. VB6: serial communication problem

10. WHY?????? ( serial communications problem)

11. serial communication problems

12. communications problem

 

 
Powered by phpBB® Forum Software