LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Quotient e Rest

Hello , im in trouble with a task..  given a number from 0 to 4095 i have to divide it for 256 and calculate the rest and the quozient. After this i have to turn those result into two strings and let  to communicate with an instrument. 

In the end i have to reconvert the values through "VISA read" and perform the operation " 256 x quozient + rest"  and obtain the value in input . Can someone help please?

  

0 Kudos
Message 1 of 10
(3,274 Views)

1. There is a very simple function called Quotient & Remainder that will do all of your math for you.

2. Do not use local variables here.  They will cause race conditions and you likely will not be sending what you want.  Use data flow (ie WIRES) to pass your data around.

3. What instrument are you talking to?  What is the exact protocol of the data to be sent back and forth (format of the data, termination characters, delimiters, etc)?

 

Here is a quick update to your code that I would set it up if I had full control over the communications protocol.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 10
(3,254 Views)

I have to send a couple of bytes to microcontroller via a serial port (9600 8N1) without termination char.

0 Kudos
Message 3 of 10
(3,204 Views)

Ok, now I see what you are trying to do.

 

1. Change your dial to be a U16.  This will actually limit your values to 0 to 4095.

2. Use Flatten To String to change your value into a string.  This will allow you to send the raw binary value of your dial through the serial port.  Note that you will not be able to tell what the data is in a normal text editor.

3.  Assuming the microcontroller is just going to spit the same thing back, just read 2 bytes and use Unflatten From String to get a U16 value.

4. Turn the Termination Character OFF on the VISA Configure Serial Port.  If one of the bytes happened to match the termination character, you could be missing data if it is turned on.  This is only an issue if you are sending binary data like you are doing here.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 10
(3,198 Views)

Hi crossrulz,

 

1. Change your dial to be a U16.  This will actually limit your values to 0 to 4095.

You forgot the AND 0xFFF operation! (U16 will go up to 65535, 4095 = 0x1000 - 1 :D)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 10
(3,190 Views)

@GerdW wrote:

Hi crossrulz,

 

1. Change your dial to be a U16.  This will actually limit your values to 0 to 4095.

You forgot the AND 0xFFF operation! (U16 will go up to 65535, 4095 = 0x1000 - 1 :D)


Or just set the data limit on the dial.  Still waking up...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 10
(3,183 Views)

Thanks for the answers ,  is it right? i think that the last part ( unflatten to .. ) is wrong.

0 Kudos
Message 7 of 10
(3,174 Views)

It is the Flatten part that I would say you have wrong.  You do not need the Quotient & Remainder at all.  Just wire your control straight to a Flatten Into String and that output goes straight into the VISA Write.  If the bytes are backwards, there is an input on the Flatten Into String (and the Unflatten From String as well) for Byte Order (also called Endianess).  The default is Big Endian, meaning your upper byte (quotient if you will) is written first.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 10
(3,166 Views)

i try to decompose the terms but give me error 74 at Unflatten from string " memory or data structure corrupt". how i can solve?

0 Kudos
Message 9 of 10
(3,146 Views)

2 bytes makes a single U16, not two of them (that would be 4 bytes).  You just need the single U16 wired to the Unflatten From String.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 10
(3,138 Views)