Results 1 to 3 of 3

Thread: MSComm

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    17

    MSComm

    I have a problem that only happens sometimes. I send a string to the comport and then wait for a reply. I am tring to receive a 7 byte block form the comport and sometimes I lose the first byte. When this happen it will do it every time I try I can resend the request and will recive 6 bytes. Other times it will work fine when I run it and every time I try after that. Any Ideas?

    This is what I should reciev in HEX if that matters
    31 0D 0a 50 54 58 3E


    Opening port

    VB Code:
    1. With MSComm1
    2.       .CommPort = 5 'ComPort
    3.       .Handshaking = comNone '2 - comRTS
    4.       .RThreshold = 1
    5.       .RTSEnable = True
    6.       .DTREnable = True
    7.       .Settings = "9600,n,8,1"
    8.       .SThreshold = 1
    9.       .InputMode = comInputModeText
    10.       .InputLen = 1
    11.       .PortOpen = True
    12.       ' Leave all other settings as default values.
    13.     End With

    Writing what read to text1.text

    VB Code:
    1. Do While Timer < TimeOut + 1
    2.     If FrmHitScores.MSComm1.InBufferCount > 0 Then             'to be sure something in the buffer
    3.       sTEMP = MSComm1.Input                           'get a byte
    4.       strRX = strRX & sTEMP                           'assemble the input bytes into strRX
    5.     End If
    6.     If Len(strRX) = 7 Then      
    7.       for a = 1 to 7
    8.          text1.text = text1.text & Hex(Asc(Mid$(strRX, a, 1)))
    9.       next a
    10.       strRX = ""
    11.       Exit Do
    12.     End If
    13.   Loop

  2. #2
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: MSComm

    Is it possible you receive Hex 0x00?
    In that case change inputmode to binary and check the "NullDiscard" property. You have to work with byte arrays then.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    17

    Re: MSComm

    namrekka
    I can monitor what is being sending and I know the first byte it is sending is a Hex 31. But I do not know what VB is seeing.
    I found a work around that seems to work. If I open the port then close it and open it again it seems to work every time.
    Not what I want but is ok for testing

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