LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ASCII to decimal conversion function

"after receiving data in single byte i will check it from which sensor it is and then i will send it to front panel display of that sensor.
there i am also checking limits of this data i.e. if i need temperature to 050 only then after receiving data >50 and <101 will send a constant to serial out."

And where's your problem with this?
You have received your byte from port and converted it to an U8 number. Now you can do anything with it...


Message Edited by GerdW on 06-12-2008 03:51 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 31 of 48
(4,647 Views)
actually after U8 conversion i get an array which if i connect to some comparator (which takes number as input) gives me error.
 
here is VI which i am currently using, but for this VI, i can receive only 10 numbers at output.
 
like if i send 48 number then labview converts it to ASCII character and i get 1 at output.
 
i am attaching my VI. and now the problem for me is just that place where string to decimal number converter is connected. i need this string to decimal number converter to be replaced with some ASCII to decimal converter. how i can do that. ( ASCII to byte array conversion is not working at this location)
 
thanks
0 Kudos
Message 32 of 48
(4,643 Views)

Your are not reading the answers given to you. If you choose to use the String to Byte Array, you merely have to use the Index Array function to get the first element in the array which will give you a single number. If you use the typecast, you will get a single number.

LabVIEW is not converting anything to ASCII. You are using ASCII when you use the Normal display format of your string constants for the VISA Write. You can right click on the string constant and select Hex display. Enter the number you want. You could use the type cast with a numeric U8 input. The string output will be correct. You could use a U8 array with the values you want and use the Byte Array to String function. The output will be correct.

0 Kudos
Message 33 of 48
(4,635 Views)
Hi ehsa,

I wrote: "after U8 conversion & index array operation"!!! Then you get just a scalar value!!!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 34 of 48
(4,633 Views)
at last it is working. actually i was using only U8 conversion but GerdW  gave VI which has an extra thing index array, it solved the problem.
 
Thanks every body. My special thanks goes to GerdW  for VI which got me out of problem.
 
thanks again.
0 Kudos
Message 35 of 48
(4,627 Views)
now as my communication is working. some times i get framing error. what is that?
thanks
0 Kudos
Message 36 of 48
(4,624 Views)
Framing error implies some problem with your serial communication.  That the pattern of bits is somehow incorrect or incomplete.  It could be a problem with your serial settings not matching your device.
 
However, I think it is another problem.  In your last code posted in message 32, you open the serial port, do a bunch of stuff, then close the serial port.  There is no master while loop to keep your program running.  How are you running your program.  Please don't tell me you are using the Run continuous button and stopping it by pressing the abort button.  But I have a feeling that is what you are doing.  Don't ever do that!  If so, you are opening and closing the serial port on every execution of your program and you may be cutting off bytes going into or out of your serial port.
 
If this code is meant to execute more than once, you should have a while loop around the portion of the code that repeats.  A Stop button would be fed to the stop terminal of the while loop.  Before the loop you would place your open/configure serial port code.  After the while loop you would place your close serial port code.  Of course the VISA reference (purple wire) and Error cluster (Mustard yellow wire) would be wired up from one to the other VI's through the loop.
0 Kudos
Message 37 of 48
(4,616 Views)

i was doing same, you got me. ok i am trying to make a loop.

now another problem which i remember that if i open VI in my home  800x600 resolution, which i made in university 1024x768 resolution monitor, all the front pannel objects are misplaced.

how to fix it? 

0 Kudos
Message 38 of 48
(4,613 Views)


GerdW wrote:
when all you get from serial port is just one byte then take that one single byte you get after the U8 conversion (& index array) operation. It's all you need!

There is no reason to go to an array and the index out the single element. That's slightly Rube Golberg'ish. 😄 The clean ways is the typecast function as already mentione way above.
 

0 Kudos
Message 39 of 48
(4,611 Views)


ehsanelahimirza wrote:
after receiving data in single byte i will check it from which sensor it is and then i will send it to front panel display of that sensor.
there i am also checking limits of this data i.e. if i need temperature to 050 only then after receiving data >50 and <101 will send a constant to serial out.

So simply place each of the three indicator inside one of the three cases (see image). Now just scale the U8 value acording to some calibration curve. For example for the humidity I'll subract 101, so we have a value range of 0...99%. Adjust as needed.
 
If you also need to send something to the serial port, output unique data from each case.
 

 


Message Edited by altenbach on 06-12-2008 08:11 AM
0 Kudos
Message 40 of 48
(4,606 Views)