Jump to content

ascii to binary strings


Recommended Posts

Iv been trying to decode the output of a serial mouse to a binary file to then obtain the coordinates of the mouse. I managed to determine these by using the aquire mouse functions last week but my boss has said that i need to use the serial port of my computer instead so that i can then ultimately run two mice in parallel.

From searching through examples on NI's website i cam across Convert ascii strings to individual bits.vi but when i come to save the output into a excel document all i get are squares and an error message from excel. (nothing new here!) Could someone point out to me where im going wrong please?

Topper99

Download File:post-586-1092663021.vi

Link to comment

I don't have LV7.1 installed right now so someone else will be more specific to your vi. However, if you want to view binary data in Excel, use an array of hex strings ("format into string.vi" format string = %x). Convert the array of strings to one string delimited with comma (for one Excel row) or CRLF (for one Excel column) and write the string of characters to a file. Excel functions HEX2DEC() and HEX2BIN() may be useful, too.

Link to comment
I don't have LV7.1 installed right now so someone else will be more specific to your vi. However, if you want to view binary data in Excel, use an array of hex strings ("format into string.vi" format string = %x). Convert the array of strings to one string delimited with comma (for one Excel row) or CRLF (for one Excel column) and write the string of characters to a file. Excel functions HEX2DEC() and HEX2BIN() may be useful, too.

1470[/snapback]

Cheers.

I also need to separate the string into 3 byte packages. my algorithm is to firstly look for the string header of 0x40 by anding my string with 0xc0. If this is true then capture the following 3 bytes. If not then these then also must be mixed and matched into an appropriate order. This i know can be done by shifting the various bits to where needed. Ive looked for some vi's on the NI.zone website to no avail but thats probably because i dont know what im looking for.

I start with a string data type and my hopefull output is a list of my three bytes in their correct order.

Can anyone help?

Link to comment
Iv been trying to decode the output of a serial mouse to a binary file to then obtain the coordinates of the mouse [snip]

[snip]when i come to save the output into a excel document all i get are squares [snip]

1460[/snapback]

I cannot see your code (not all of us have 7.1) :) but if I understand your question corectly you might be using the wrong tool. The reason excel doesn't like the "bits" is that they are non printable characters. Each character received in a string like this represents a byte (8 bits) that can be interpreted as an ASCII character (0..255), some of which are the characters A, a, 1, etc, but many which are non printable. You can convert tthe string you receive into bytes using the (A) tool in figure below, alternatively you may want to see the ascii "hex" representation of the string (B). What I think you need to do is "decode" the array of bytes into the numbers, then write the numbers as a string to file ©.

cheers, Alex.

post-111-1092749401.gif?width=400

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.