05-27-2010 10:17 AM
Hi,
I just started using LabView two days ago and need some help with what is probably very basic stuff. My objective is to take a .txt file containing some message (letters, numbers, etc) and convert this into a serial stream of bits. In MATLAB, I would have done this like so:
temp=textread('CommsInput.txt', '%1s', 'whitespace', ''); %load .txt file
Ultimately, this would give me an (8*N x 1) vector where N is the number characters in the text file.
From here I would be able to easily access each bit to create a Pulse Position Modulation signal I want to use for laser communication.
If anyone has any tips on how to implement this in LabView 8.2, it would be greatly appreciated!
Thanks
Solved! Go to Solution.
05-27-2010 11:28 AM
Go to help in the toolbar. Then select "Find Examples" and do a search for Read Binary File.vi. Use this as a template for reading binary files of any type. Remember to use "save as" then saving so you do not overwrite existing files 😉
05-27-2010 01:40 PM
Hello,
thanks for your reply. I found the example you mentioned but it's not really working the way I expected it to. Instead of opening a .bin file, it prompts me for a .dat file. If I force it to choose my .txt file a whole bunch of numbers (not just one and zero) replace the graph which was originally on the front panel.
I also tried out the 'open a text file.vi' but that simply displayed a string of the message which is in there.
Am I missing something?
Thanks
05-27-2010 01:55 PM
What is the format of your text file? I am not very familiar with MATLAB file and text functions, but I suspect that there may be a fairly easy way to get what you want.
Lynn
05-27-2010 01:59 PM
Post your file. Then we can have a look at your problem.
05-27-2010 02:01 PM - edited 05-27-2010 02:02 PM
The file extension is irrelevant. Every file is ultimately binary. Even text files. If I understand the objective, I believe one of these two approaches will do what you need:
This is for a text file that contained the text "ABCDEF"
05-27-2010 02:23 PM
Great! Thanks smercurio_fc!
This is exactly what I wanted. Now I'm going to try to understand what you did...
05-27-2010 02:32 PM
sp306 wrote:Great! Thanks smercurio_fc!
This is exactly what I wanted. Now I'm going to try to understand what you did...
The first part is just reading the file as an array of U8. These will be the ASCII values of each character. The for-loop processes each element.
The top part of the loop converts the ASCII value to a string of zeros and ones. That's done with the Format Into String function. VERY handy function. The output of this is a 1D array of strings. The Concatenate Strings function just "flattens" it into one single string.
The bottom part converts it to an array of numeric zeros and ones. This needs to be done in a sequence of steps. First, convert the numeric into an array of Booleans (Number to Boolean Array). Then, convert the Boolean array into an array of zeros and ones (Boolean to (0,1)). Then, reverse the array since LabVIEW orders things in reverse. Since the output is a 2D array I just reshape it into a 1D array using Reshape Array. The Array Size and Multiply Array Elements tell me the size of the 1D array.
06-10-2011 02:33 AM
i have to convert the text file into the stream of binary value in matlab ...so how can i convert it ? can i have source code for this conversion???
06-10-2011 08:56 AM
What doesn't the code shown do that you need it to do? The source code is right there, so I don't understand what you're asking here.