Results 1 to 7 of 7

Thread: Serial Port Binary Data Conversion

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    2

    Serial Port Binary Data Conversion

    I've searched the forum and although some threads come close, none answer my question. I have a data acq box that transmits data via RS232. The data is binary with two header bytes (250 or 11111010) and one EOM byte (254 or 11111110). The data that I'm interested in resides in the 28 bytes in between the headers and EOM. I can connect to the box and receive data but I can't figure out how to parse it and use it. If I try to put it in a text box a get a lot of ? and some random characters. I know the box is working because I used a port monitor setup for binary and was able to see all of the data. My problem is how do I collect the data, identify the headers and EOM, parse the bytes and convert the data into a number that I can assign to a varible and use to set the properties of a gauge. I wrote a function to convert a byte to a number but I think it needs 1 and 0 characters for it to work. I don't want to convert it to characters unless I have to. I rather just convert it to numbers. Also, most are single byte data but some of the data requires two bytes. How does that change things. Thanks

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Serial Port Binary Data Conversion

    Do you know what form you receive the data in now? Is it a byte array?
    What have you got?

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Serial Port Binary Data Conversion

    To me it sounds like you're putting byte array data as-is into a textbox. The problem with this is that two bytes get coerced into one character, and because VB6 controls are ANSI only you'll mostly get question marks. You could use StrConv(ByteArrayName, vbUnicode) to get single character to represent single byte, but most likely that still wouldn't ease with debugging.

    As a tip, hex and binary numbers are probably the easiest to read, generally you may want to look for which bits change when data comes differently than in other situatation. Thus you backtrack how things work. Of course, giving further information and example data and code does make things easier for us.
    Last edited by Merri; Aug 2nd, 2008 at 11:14 PM.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    280

    Re: Serial Port Binary Data Conversion

    Also, most are single byte data but some of the data requires two bytes. How does that change things.
    As long as you know which are which it should be fine. I doubt we will be able to guess that one otherwise. Also are you reading the data into bytes or integers?

    But as mentioned we will need code and a bit more information.
    Slower than a crippled Vista
    More buggy than a fresh XP install
    Look! Down the road, some 50 miles behind the drunken snail.
    It's Ubuntu!

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    2

    Re: Serial Port Binary Data Conversion

    Ok, I'm not explaining myself well. The data acq box puts out a stream of data that looks like this: (I highlighted the header bytes in blue and the EOM byte in red)

    00000110 01110100 00000000 00000000 00000000 11111110 11111010 11111010 10000110 01010111 11110011 00000100 11101100 00011110 10000001 10101010 11111111 00000001 11100000 00000001 11100000 00000001 11100000 00000001 11100000 00000110 01110100 00000110 01110100 00000110 01110100 00000110 01110100 00000000 00000000 00000000 11111110 11111010 11111010 10000110 01010111
    Note: I captured this data using a port monitor set up to recieve binary.

    The box constantly transmits this data one byte at a time. Each of the 28 bytes between the headers and the EOM is a measured parameter value. What I need help with is identifying the begining of the data (headers) and parsing out each byte so I can assign the value to a varible. I know how to parse a string. If I had the data above in a string I could parse it out and convert the bytes to numbers. But I don't know how to manipulate binary data the same way. Also, I know I will not be able to read it in a text box but I did that to make sure that my MSCOMM portion of the code is working. I hope this makes my question more clear. Thanks

  6. #6
    Registered User
    Join Date
    Sep 2014
    Posts
    3

    Re: Serial Port Binary Data Conversion

    Quote Originally Posted by cguarino View Post
    I've searched the forum and although some threads come close, none answer my question. I have a data acq box that transmits data via RS232. The data is binary with two header bytes (250 or 11111010) and one EOM byte (254 or 11111110). The data that I'm interested in resides in the 28 bytes in between the headers and EOM. I can connect to the box and receive data but I can't figure out how to parse it and use it. If I try to put it in a text box a get a lot of ? and some random characters. I know the box is working because I used a port monitor setup for binary and was able to see all of the data. My problem is how do I collect the data, identify the headers and EOM, parse the bytes and convert the data into a number that I can assign to a varible and use to set the properties of a gauge. I wrote a function to convert a byte to a number but I think it needs 1 and 0 characters for it to work. I don't want to convert it to characters unless I have to. I rather just convert it to numbers. Also, most are single byte data but some of the data requires two bytes. How does that change things. Thanks
    can u give me solution for this if it is found

  7. #7
    Registered User
    Join Date
    Sep 2014
    Posts
    3

    Re: Serial Port Binary Data Conversion

    can u give me solution to above problem

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