LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Float Data from Serial Device

Solved!
Go to solution

Hello Ravensfan,

 

Okay so here is what is happening. When I run the VI, it will hang on VISA read until I reset the micocontroller. Upon reset of the microcontroller, my firmware transmits "Hello World!\n" In high execution mode, I can see the word "Hell" followed by "o Wo", "rld!" passed through the buffer. These string values change to 1.14314E+27, 6.65785E+28, 7.73929E-19 which are written to the text file attached. This makes sense as it's passing through the unflatten from string function. This of course is not what I would like. The issue I think at hand is that the unflatten from string function doesn't like the input "\n" from the VISA read.

0 Kudos
Message 11 of 19
(1,254 Views)

You are reading the strings as you expect, and then you try to convert them to single precision floats? Can you explain why?

0 Kudos
Message 12 of 19
(1,249 Views)

Hello gregoryj,

 

so currently, I would like to start my firmware off by sending a string "Hello World\n" Upon receiving the character 'g' from labVIEW, I have my microcontroller output the numbers 0 to 255. Is there a way to read a string first then switch to reading numbers?

0 Kudos
Message 13 of 19
(1,239 Views)

I don't do much with visa serial communication, but I think it would be up to you to know what kind of data you're expecting. If you send your "g" command, then read back your data as a string. If you send a command where you expect a SGL numeric back, unflatten it to a SGL. If you send a command where you expect a boolean back, unflatten to boolean, etc.

0 Kudos
Message 14 of 19
(1,231 Views)

Ahh this makes sense, I think I will try this. I was wondering for the write to text file, is there a way to have a it "\n" each write so I can have my numeric data in a single vertical column? Also, so far, when I am passing 0 to 255, labVIEW outputs out of the unflatten string function values very close to 0 each time. I feel like I must have wired something incorrectly.

0 Kudos
Message 15 of 19
(1,228 Views)

Update on what I have so far. So I was able to implement a simple true/false case structure where if the character I wrote to the buffer was a 'g' it would attempt to VISA read data in the float32 format and if the value was anything (excluding nothing in write buffer) the labview program would VISA read the string directly.

 

The LabVIEW program will also hang if there is nothing written the write buffer. My only issue now is in my firmware, I have a case where if I write a k, it will change a flag in the firmware program; however, it will not write anything to the VISA read. This is causing my program to time out at VISA read as it doesn't read any values. Is there a way that instead timing out, have it loop back to the VISA write loop?

0 Kudos
Message 16 of 19
(1,214 Views)

Just make the VISA read conditional.  Put a case structure around it and only execute the case when you need to.

 

Alternatively, you can send a response to every command so you can be sure it executed.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 17 of 19
(1,203 Views)

Hi everyone,

 

I'm still having issues converting my float data into the proper values to be written to my textfile. I have a simple program where I am using the flatten to string function to simulate a visa read. The issue seem to be appearing at the unflattent to string function saying that there is a memory or data corruption.

0 Kudos
Message 18 of 19
(1,176 Views)
Solution
Accepted by BMoneySpice

Pay attention to the data types you wire into the Unflatten from String.

 

You can't flatten a single precision number and expect it to unflatten without error if you say you are unflattening a double precision number.  Refer back to message #2

0 Kudos
Message 19 of 19
(1,167 Views)