Jump to content

string converstion functions


Recommended Posts

What display setting do you have for the 40 constant?

If it is in Hex mode, then 40 = @ which will make that VI return a 0. If it is in normal mode, then I don't see anything wrong.

I have a problem that the given vi converts given hex value to ascii character but in my code before i am directly concatenate the character "@" with another string and I am writing that to serial device. In that case it is working fine.

But after some days I want to write just 40(hex) to serial device which menas ascii character is "@". I am just doing this in my gui for user friendly behaviour. User can not undestand characters. so that why i am displaying 40 to user in frontpanel and converting that to ascii character in inside labview and after concatenate it with another string. In this case my serial device is not replying back like before, though both are writing same. I don't know why?

But i found one difference that, In normal case i.e. in my first case(red)it is writing "@+some other concatenated command"

in second case "Some space+@+ concatenated command"

I hope you are understand my problem and please help me.

Link to comment

I think you are going to need to post some code because I am not understanding your issue. Some code context could help.

Yes, you can see the attched code ...timeout case(read visa is reading Characters @ and A) and monitoring options case.

Also, i would like to on(it should glow) the button until the specific case completes and then off.

Problem is the dropdown list is showing these characters before thats the reason i changed that to display values with ascii to hex and another case hex to ascii conversion(not working now)..

saras.vi

Link to comment

The error you are experiencing appears to occur in that you are taking a regular string output (using the "Number to Hexadecimal String") and assuming that it is a Hexadecimal string (it's not, it's a regular string but displays numbers in hexadecimal notation).

You also seem to be doing this in very complex manner. To simplify it you could make a string indicator which displays Hex output. You could also create a control which switches between views (normal, \ codes, etc). This should simplify the debugging.

Link to comment

I'm with DaveC. The simplest way to handle this is to set the drop down box to display in Hex. Then you don't have to worry about the conversions yourself. I would also recommend making a switch to go between ASCII and Hex display. I do this a lot when I have to deal with serial port displays.

post-11268-0-90367900-1301402806_thumb.p

Link to comment

Hi,

I am new to labview and learning in slow phase. I have a doubt regarding String to number converstion vi's. why it is not converting hex string to number and it is giving zero as result. Can nay one help what is reason.

I think the source of your problem might be the type cast: you take your string containing a hexadecimal number and convert it to a number. This number is a signed 4 byte integer that happens to contain a number between 0 and 255 - i.e. the first three bytes of the int are zero and only the last byte has real data. You then convert that to a unsigned byte integer array with the type cast - so now you have a four elelement array [0,0,0,64] - hence you have some leading spaces ahead of the @ ASCII character. If you feed it 4 byte string of hex numbers then the intermediate signed 4 byte int won't contain any leading 0 bytes and so you don't get leadin \0 in the output string.

Moral of the story is that the type cast operator is almost always the wrong thing to use unless you are sure that it isn't.

If you want to display a string as a series of hex values representing bytes for e.g. a user to edit or inspect, consider using an array of U8s with the display format set to display in hex and then just use the [u8]->string primitive that you already used.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.