12-09-2015 09:46 AM
Hi Folks.
I am trying to read an image data from the serial port. It is in binary format. I have tried using the draw pixmap with bundle but this does not like the format which is read from the serial port. Is there a simple way to convert it or does it need to be handled differently?
Thanks,
Mark.
Solved! Go to Solution.
12-09-2015 10:38 AM
Are you sure you are receivng complete data from serial port?
Open Draw Unflatten pixmap.vi and its subVI Flatten pixmap. It shows how to convert raw data into pixmap format.
I can not open your vi (I am 2011), if you post a snippet it would help.
12-09-2015 10:40 AM
The sample VI you posted had a large constant array on the block diagram and when I wire that into the pixmap function it works and I get an image of a ceiling somewhere, so it looks like that portion works.
However what does look wrong is in the serial read code. Two things:
1. Instead of using "Decimal string to number" you should probably be using "String to byte array". Also, you were wiring to the "offset past number" output, not the actual number outputs, so you were discarding your input in any case.
2. When you collect a bunch of data in an array like this in a loop, remember to put the current data on the top input of the "build array" function and the new data on the bottom. The way you are doing it now it's reversing all of your inputs by always putting the newest read item at the start of the array.
12-09-2015 11:07 AM
The ceiling pic is only a test from an example I had. I want the info from the for loop to go in. I removed the array circled in red and replaced it with whats in the for loop. I am confused as to what that array was doing and whay is it so big - 993,040 elements. The vi shown below and attached only works with 1 iteration. I would ideally like to repeat for every byte in the image. The values going into the bundle were originally all numbers. Will it accept binary data like this?
12-09-2015 11:34 AM
Your FOR loop is redundant at this point, as you're hard-wired a "1" to the N input. It should probably be either a much larger number (probably the width times the height of the image) or the FOR loop should be a WHILE loop instead.
I think at this point you need to tell us a bit more about what the device in question is supposed to send back. It should either be something that's a fixed length (i.e. you know the image will be 640x480 pixels or whatever), or the return data itself will contain information about how long the return block will be (i.e. the first 4 digits returned convert to the width, the next 4 convert to the height, and the rest is the data, something like that) or it should be some data that has a termination character or sequence on the end (which is unlikely for a binary stream like you seem to be using as there's no guarantee that the termination sequence won't accidentally be inside of the binary data).
Also, your build array functions are still backwards, and you should switch the one using the U8 array to be concatenating instead so it outputs a 1D array, then use the final 1D array from that as the input to the picture function.
12-10-2015 06:29 AM
I was over complicating things I think. I have revised it to be a bit simpler. It does capture the data and display some of it in the picture box, except its only the first row. i though using 2 nested for loops would create the 2d array but all I can get is one long row. I have tried usinh Insert into array but would not work.
I am happy with the data coming in its just displaying it is the issue. I have only used 10x10 to control the loops initially to get it working but this would more than likely be 640x640. The write command is only to get the device to write the image data.
Also no data shows in the 8-bit pixmap even though it is in the picture box, why is this?
What is the best way to sort the data into seperate columns instead of one long one?
12-10-2015 07:55 AM
MarkGreally wrote: What is the best way to sort the data into seperate columns instead of one long one?
Do you know how large the image is supposed to be (width and height)?
12-10-2015 08:04 AM - edited 12-10-2015 08:04 AM
@MarkGreally wrote:
I was over complicating things I think. I have revised it to be a bit simpler. It does capture the data and display some of it in the picture box, except its only the first row. i though using 2 nested for loops would create the 2d array but all I can get is one long row. I have tried usinh Insert into array but would not work.
Here is an even more simplified version. You only need 1 FOR loop (for number of rows) and just have your VISA Read get the number of bytes in a row. Then you just use autoindexing to get your 2D array.
12-10-2015 09:47 AM
Thanks for this but I am still having no luck with that. To make things easier I have programmed my device to just send a load of "a0" to represent a basic colour over the serial port. This is what it looks like in the terminal window. Its a 1000 of each in total.
I cannot get labview to read this data in. Is is something to do with the formatting???
12-10-2015 10:08 AM
Forget that. I was having a connection problem. The code works perfectly now.
Thanks a mill for the tips.