Results 1 to 2 of 2

Thread: BNComm by Banasoft

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    54

    BNComm by Banasoft

    I hope this is posted in the correct place, perhaps an Administrator can move it for me if it isn't.

    Does anyone use the BNComm control? I am sending a string to a chip embedded in an electronic product. It responds with an "OK" or "NOK".

    How do I pause my code while I wait for the reply when the BNComm1.ComEvent is triggered? If I use Sleep api, the event isn't triggered if the string is returned by the unit when the program is Sleeping.
    Same problem with a 'Do until' to wait for an event, it just locks my code.

    Can anyone please help, this is a major problem for me, as I have a customer who is getting impatient.

    Thank you.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: BNComm by Banasoft

    Hi,

    Don't know much about BNComm but with MSComm you'd do something like
    VB Code:
    1. Private Sub cmdSend_Click()
    2. MSComm1.Output strMyData
    3. End Sub
    4.  
    5. Private Sub MSComm1_OnComm()
    6. Select Case MSComm1.ComEvent
    7.     Case comEvReceive
    8.         Do
    9.             strData = strData & MSComm1.Input
    10.         Loop Until MSComm1.InBufferCount = 0
    11.         If strData = "OK" then
    12.             '
    13.             '  Chip has responded with OK
    14.             '
    15.         Else
    16.             '
    17.             ' Chip has responded with something else
    18.             '
    19.         End If
    20. End Select      
    21. End Sub
    With MSComm you have to set RThreshold value to non zero (recommend 1) in order to have the OnComm event trigger.

    You should also be able to Poll the device in a loop:
    VB Code:
    1. Private Sub cmdSend_Click()
    2. MSComm1.Output strMyData
    3. '
    4. ' Loop until something is received
    5. '
    6. Do Until MSComm1.ComEvent = comEvReceive
    7.     DoEvents
    8. Loop
    9. Do
    10.     strData = strData & MSComm1.Input
    11. Loop Until MSComm1.InBufferCount = 0
    12. If strData = "OK" then
    13.     '
    14.     '  Chip has responded with OK
    15.     '
    16. Else
    17.     '
    18.     ' Chip has responded with something else
    19.     '
    20. End If
    21. End Sub
    If you choose the Polling option it would be 'safe' to have a timeout in the loop waiting for a response, just in case the device is switched off or otherwise unavailable. You could put a timer on the Form and set its interval to a reasonable timeout period and when that triggers, stop the loop.
    eg
    VB Code:
    1. Dim boTimeout as Boolean   ' This should be in the Declaration Section
    2.  
    3. Private Sub Form_Load()
    4. Timer1.Enabled = False
    5. Timer1.Interval = 2000  ' 2000 = 2 Seconds
    6. End Sub
    7.  
    8. Private Sub Timer1_Timer()
    9. boTimeout = True
    10. End Sub
    11.  
    12. Private Sub cmdSend_Click()
    13. MSComm1.Output strMyData
    14. '
    15. ' Loop until something is received
    16. ' or the request times out
    17. '
    18. boTimeout = False
    19. Timer1.Enabled = True
    20. Do Until MSComm1.ComEvent = comEvReceive Or boTimeout = True
    21.     DoEvents
    22. Loop
    23. If boTimeout = False Then
    24.     Do
    25.         strData = strData & MSComm1.Input
    26.     Loop Until MSComm1.InBufferCount = 0
    27.     If strData = "OK" then
    28.         '
    29.         '  Chip has responded with OK
    30.         '
    31.     Else
    32.         '
    33.         ' Chip has responded with something else
    34.         '
    35.     End If
    36. Else
    37.     MsgBox "Equipment hasn't responded after " & Timer1.Interval / 1000 & " Seconds"
    38. End if
    39. End Sub
    InBufferCount is the number of bytes in the input buffer waiting to be read.
    comEvReceive is the constant assigned to the .ComEvent property when a receive event occurs.

    I suspect that BNComm has similar capabilities and properties

    Regards
    Doug

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