Need help on sending character to comm in echo mode 
Author Message
 Need help on sending character to comm in echo mode

Hello,

I need some help sending characters to the serial port with eVB. The
device runs in echo mode. That means it receives a string character by
character. The Pocket PC (IPAQ) has to wait for the echo before
sending the next character.

The problem is : the whole output buffer will be sent no matter the
value of SThreshold.

My code :
Private Sub Comm1_OnComm()
    Select Case Comm1.CommEvent
        Case comEvSend
            Timer1.Enabled = True
        Case comEvReceive
            ' compare received character with sent character
            Timer1.Enabled = False
    End Select

End Sub

Private Function send_string(daten As Variant) As Boolean
    Dim i, ZeilenNummer As Integer
    Dim tmpStr, PrgSchritt As String
    Dim lpBytesWritten, lDummy As Long

    On Error Resume Next

    send_string = True
    daten = daten & vbCr

    Comm1.Output = daten
End Function

Sub port_open()
    On Error Resume Next
    'Set input to text mode
    Comm1.InputMode = 0
    'Read whole buffer
    Comm1.InputLen = 0
    'Set com port
    Comm1.CommPort = 1
    'configure comm port settings to 9600 bd, 8 Bit, no parity, 1
Startbit
    Comm1.Settings = "9600,N,8,1"
    'no handshaking
    Comm1.Handshaking = 0
    Comm1.PortOpen = True
    Comm1.RThreshold = 1
    Comm1.SThreshold = 1
End Sub

Sub port_close()
    On Error Resume Next

    If Comm1.PortOpen Then Comm1.PortOpen = False
End Sub
.
.
.
port_open
send_string("test")
port_close

thanks for help
        Holger



Fri, 26 Aug 2005 18:02:42 GMT  
 Need help on sending character to comm in echo mode
You can't use the SThreshold event to control the maximum number of
characters to send.  It is designed to be used where you are sending strings
of variable length and you need an event to indicate when the send buffer
should be refilled with new characters to send, or when the send buffer is
empty, ie, all data has been sent.

Instead of using comEvSend use a loop to send your string character by
character, waiting either for confirmation or a timeout at each character.

Dim Waiting as Boolean

Private Sub Comm1_OnComm()
    Select Case Comm1.CommEvent
        Case comEvReceive
    ' compare received character with sent character
        Timer1.Enabled = False
        Waiting = False
    End Select
End Sub

Private Sub send_string(daten As Variant)
    Dim i As Integer

    daten = daten & vbCr
    For i = 1 to len(daten)
      Waiting = True
      Timer1.Enabled = True
      Comm1.Output = mid(daten,i,1)
      While Waiting = True
      ' DoEvents
      Wend
     Next i
End Sub

Private Sub Timer1_Timer()
    MsgBox "TimeOut!"
    Timer1.Enabled = False
    Waiting = False
End Sub
--
Jeff Richards


Quote:
> Hello,

> I need some help sending characters to the serial port with eVB. The
> device runs in echo mode. That means it receives a string character by
> character. The Pocket PC (IPAQ) has to wait for the echo before
> sending the next character.

> The problem is : the whole output buffer will be sent no matter the
> value of SThreshold.

> My code :
> Private Sub Comm1_OnComm()
>     Select Case Comm1.CommEvent
>         Case comEvSend
>             Timer1.Enabled = True
>         Case comEvReceive
>     ' compare received character with sent character
>             Timer1.Enabled = False
>     End Select

> End Sub

> Private Function send_string(daten As Variant) As Boolean
>     Dim i, ZeilenNummer As Integer
>     Dim tmpStr, PrgSchritt As String
>     Dim lpBytesWritten, lDummy As Long

>     On Error Resume Next

>     send_string = True
>     daten = daten & vbCr

>     Comm1.Output = daten
> End Function

> Sub port_open()
>     On Error Resume Next
>     'Set input to text mode
>     Comm1.InputMode = 0
>     'Read whole buffer
>     Comm1.InputLen = 0
>     'Set com port
>     Comm1.CommPort = 1
>     'configure comm port settings to 9600 bd, 8 Bit, no parity, 1
> Startbit
>     Comm1.Settings = "9600,N,8,1"
>     'no handshaking
>     Comm1.Handshaking = 0
>     Comm1.PortOpen = True
>     Comm1.RThreshold = 1
>     Comm1.SThreshold = 1
> End Sub

> Sub port_close()
>     On Error Resume Next

>     If Comm1.PortOpen Then Comm1.PortOpen = False
> End Sub
> .
> .
> .
> port_open
> send_string("test")
> port_close

> thanks for help
> Holger



Sat, 27 Aug 2005 13:41:35 GMT  
 Need help on sending character to comm in echo mode
Thanx Jeff,
 I tried this but now I get a endless loop.
Quote:

> You can't use the SThreshold event to control the maximum number of
> Private Sub send_string(daten As Variant)
>     Dim i As Integer

>     daten = daten & vbCr
>     For i = 1 to len(daten)
>       Waiting = True
>       Timer1.Enabled = True
>       Comm1.Output = mid(daten,i,1)
>       While Waiting = True
>       ' DoEvents
>       Wend

        ^ this loop is endless. The timer never sets Waiting to False
...
Quote:
> Private Sub Timer1_Timer()
>     MsgBox "TimeOut!"
>     Timer1.Enabled = False
>     Waiting = False
> End Sub

  ^ The program never starts this procedure

Thanx from Holger



Sun, 28 Aug 2005 00:34:17 GMT  
 Need help on sending character to comm in echo mode
What timeout period have you specified for timer1, and have you waited long
enough for the timer to time out?

I have not tested the logic because I do not have a device that handshakes
in this fashion, but the While/Wend loop should be exited either when a
response is received or the timer times out.  Have you determined whether it
is looping in the While/Wend or in the For/Next?
--
Jeff Richards
MS MVP W95/W98


Quote:
> Thanx Jeff,
>  I tried this but now I get a endless loop.



Quote:
> > You can't use the SThreshold event to control the maximum number of
> > Private Sub send_string(daten As Variant)
> >     Dim i As Integer

> >     daten = daten & vbCr
> >     For i = 1 to len(daten)
> >       Waiting = True
> >       Timer1.Enabled = True
> >       Comm1.Output = mid(daten,i,1)
> >       While Waiting = True
> >       ' DoEvents
> >       Wend
>         ^ this loop is endless. The timer never sets Waiting to False
> ...
> > Private Sub Timer1_Timer()
> >     MsgBox "TimeOut!"
> >     Timer1.Enabled = False
> >     Waiting = False
> > End Sub
>   ^ The program never starts this procedure

> Thanx from Holger



Sun, 28 Aug 2005 07:02:20 GMT  
 Need help on sending character to comm in echo mode
Hello Jeff,

the timer value is 1000 . I understood this as the time in
milliseconds. So I have 1 second.

The first version (see #1 of this thread) worked well with this value.

I've tested the program in debug modus and it's exactly the
while-wend-loop which never ends.

<- Debug break point is here
       While Waiting = True
       ' DoEvents
       Wend

Thanx from Holger



Sun, 28 Aug 2005 17:12:07 GMT  
 Need help on sending character to comm in echo mode
If the timer never times out then it must be reset by the EvReceive event.
Put your debug statements in the CommEvent EvReceive case to check if that
event is being fired and that Waiting is being reset to false when the event
occurs.
--
Jeff Richards
MS MVP W95/W98


Quote:
> Hello Jeff,

> the timer value is 1000 . I understood this as the time in
> milliseconds. So I have 1 second.

> The first version (see #1 of this thread) worked well with this value.

> I've tested the program in debug modus and it's exactly the
> while-wend-loop which never ends.

> <- Debug break point is here
>        While Waiting = True
>        ' DoEvents
>        Wend

> Thanx from Holger



Mon, 29 Aug 2005 05:24:39 GMT  
 Need help on sending character to comm in echo mode
Hello Jeff,

the procedure Comm1_OnComm() will never executed too.

Comm1.OutBufferCount is never greater than 0.

Private Function send_string(daten As Variant) As Boolean
...

    Label1.Caption = Label1 & " " & daten
...
    daten = daten & vbCr

    For i = 1 To Len(daten)
        Timer1.Enabled = True
        Waiting = True
        Comm1.Output = Mid(daten, i, 1)
        Do While Comm1.OutBufferCount > 0
            Label1.Caption = Label1 & ", OutBufferCount=" & Comm1.OutBufferCount
                ^ This loop will never executed. The output buffer is empty ???
        Loop
        While Waiting
            ' DoEvents
        Wend
    Next i

End Function

thanx   Holger



Mon, 29 Aug 2005 18:00:09 GMT  
 Need help on sending character to comm in echo mode
I don't understand what you are trying to do in the additional code. I would
expect the output buffer to always be empty, because you are sending one
character at a time with no flow control - the character should be sent as
soon as it is transferred to the output buffer, and the buffer will always
be empty.

The important question is whether the While Waiting ... loop is exited -
either on the Timer timeout or on the acknowledge character being received.
If this loop is not being exited then there might be a problem in your
DoEvents code.
--
Jeff Richards


Quote:
> Hello Jeff,

> the procedure Comm1_OnComm() will never executed too.

> Comm1.OutBufferCount is never greater than 0.

> Private Function send_string(daten As Variant) As Boolean
> ...

>     Label1.Caption = Label1 & " " & daten
> ...
>     daten = daten & vbCr

>     For i = 1 To Len(daten)
>         Timer1.Enabled = True
>         Waiting = True
>         Comm1.Output = Mid(daten, i, 1)
>         Do While Comm1.OutBufferCount > 0
>             Label1.Caption = Label1 & ", OutBufferCount=" &

Comm1.OutBufferCount

- Show quoted text -

Quote:
> ^ This loop will never executed. The output buffer is empty ???
>         Loop
>         While Waiting
>             ' DoEvents
>         Wend
>     Next i

> End Function

> thanx Holger



Tue, 30 Aug 2005 05:32:32 GMT  
 Need help on sending character to comm in echo mode
Hello Jeff,

...

Quote:
> The important question is whether the While Waiting ... loop is exited -
> either on the Timer timeout or on the acknowledge character being received.
> If this loop is not being exited then there might be a problem in your
> DoEvents code.
> --
> Jeff Richards

thanx for your reply. Unfortunately I have no experience with eVB. So
can you give a little example for a "DoEvent" code?

thanx Holger



Tue, 30 Aug 2005 16:52:02 GMT  
 Need help on sending character to comm in echo mode
A sample DoEvents is below.

Although the sample should work just fine without a DoEvents you could check
it out when all other debugging attempts have failed.

Declare Function PeekMessage Lib "coredll.dll" Alias "PeekMessageW" _
    (ByVal MSG As String, ByVal hWnd As Long, ByVal wMsgFilterMin As _
    Integer, ByVal wMsgFilterMax As Integer, ByVal wRemoveMsg As _
    Integer)  As Boolean

Declare Function TranslateMessage Lib "coredll.dll" (ByVal MSG As _
String) As Boolean

Declare Function DispatchMessage Lib "coredll.dll" Alias _
    DispatchMessageW" (ByVal MSG As String) As Boolean

Public Const PM_REMOVE = 1
Public MSG  As String

Public Sub DoEventsCE()
    MSG = String(18, Chr(0))
    ' Get message from queue and dispatch it
    If PeekMessage(MSG, 0, 0, 0, PM_REMOVE) Then
        TranslateMessage (MSG)
        DispatchMessage (MSG)
    End If
End Sub

--
Jeff Richards


Quote:
> Hello Jeff,


> ...
> > The important question is whether the While Waiting ... loop is exited -
> > either on the Timer timeout or on the acknowledge character being
received.
> > If this loop is not being exited then there might be a problem in your
> > DoEvents code.
> > --
> > Jeff Richards

> thanx for your reply. Unfortunately I have no experience with eVB. So
> can you give a little example for a "DoEvent" code?

> thanx Holger



Wed, 31 Aug 2005 05:09:44 GMT  
 Need help on sending character to comm in echo mode
Hello Jeff,

sorry, but it's still not working. The whole output buffer will sent
in one step.

Yesterday I was at the Cebit/Hannover and I asked one guy from
microsoft. He told me, that this is normal and one can't modify this
property of the comm control. He suggested to make a eVC++ .dll and
use it in my eVB code.

What do you think about that ? And how to make it ?

greetings Holger



Sat, 03 Sep 2005 17:52:34 GMT  
 Need help on sending character to comm in echo mode
That is correct - the whole output buffer is sent as it is loaded.

That's why the code sample I provided loads the output buffer with one
character at a time (the For loop).  The character is sent, and the system
then 'waits' for either the acknowledge (the Comm1.CommEvent) or the timeout
(Timer1_Timer).

If it's not working it is not due to the fact that the whole output buffer
is sent in one step - that's the way the code is designed to work.  You need
to determine why neither the Timer1_Timer event or the CommEvent
(comEvReceive) is not firing after the character is sent.
--
Jeff Richards
MS MVP W95/W98


Quote:
> Hello Jeff,

> sorry, but it's still not working. The whole output buffer will sent
> in one step.

> Yesterday I was at the Cebit/Hannover and I asked one guy from
> microsoft. He told me, that this is normal and one can't modify this
> property of the comm control. He suggested to make a eVC++ .dll and
> use it in my eVB code.

> What do you think about that ? And how to make it ?

> greetings Holger



Sun, 04 Sep 2005 06:52:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Need the Win32 API call for sending a ICMP Echo (Ping) from VB4

2. Flushing the comm control and sending characters..

3. need help sending control characters epson printer

4. comm ports & sleep mode

5. Terminal vs Data mode Comm

6. HELP: Sending Escape Characters for RLF to printer

7. keybd_event does not send all characters, please help!

8. Need help reading data from comm port

9. QB Comm help needed

10. Need help with comm control

11. Need help with Modem List & Comm Setting

12. Comm help needed !!!!

 

 
Powered by phpBB® Forum Software