Results 1 to 5 of 5

Thread: receiving binary data with mscomm

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    The Netherlands
    Posts
    12
    Hello,

    I have a problem to receive binary data from a rs232 device which is connected to my serial port. I receive only strange letters en symbols but I want to receive binary data. I have tried a couple of codes which are posted on this forum but it still don't work.

    With a shareware program to receive serial data I can read the data perfect, why can't I do it with visual basic.

    Thanks for your help.

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    I hate to break it to you, but the strange letters and symbols are the binary data.

    If it is in a string, then you can copy it to a byte array using the StrConv function:
    Code:
    Dim sData As String
    Dim btData() As Byte
    
    ' sData receives the binary data here
    btData = StrConv(sData, vbFromUnicode)
    Then, you can use the btData as a byte array, and read the bytes from it, or do whatever you want to do with it.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    The Netherlands
    Posts
    12

    Question how to use a binary array

    Thank you for your reply.

    I only don't know how to read the data form a binary array.
    I have tested the function

    btData = StrConv(sData, vbFromUnicode)

    but I don't can read the data of that array.
    How can I display on my screen and
    how can I use the data in the array.
    I want to test of I different data receive then 00000000.

    Greetings.

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Try this, to read data from the byte array and print it to the debug window:
    Code:
    Dim I As Integer
    Dim sData As String
    Dim btData() As Byte
    
    Something ' sData receives data here
    btData = StrConv(sData, vbFromUnicode)
    
    For I = LBound(btData) To UBound(btData)
        Debug.Print Hex(btData(I)) & " ";
    Next
    
    Debug.Print
    The data will appear in the Immediate window.
    If you don't see it (although you really really should!) then press Ctrl+G and it should appear.

  5. #5
    Addicted Member Electro414's Avatar
    Join Date
    Nov 2000
    Location
    Do you know? I don't...
    Posts
    128
    Yonatan can you do this sending hex out of the port?

    Thanks,
    Electro414

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