LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

1D array of string to 1D array of numeric

Hi,

I am using NI CAN to send and receive data.

 

The ncWriteNet.vi accepts 1D array of unusigned byte. 

 

I have got 1D array of string. I converted decimal values to hex using number to hex decimal converter. 

 

I need to know how i can convert 1D array of unusigned byte to D array of string.

 

I used the following methods

 

1. String to byte array. 

I get a random value as 48 when the sting value is 00. 

 

2. Type cast

I got a random value of 48 when the string value is 00.

 

Can I please know why do i get 48. Is there a method to convert 1D array of string to 1D array of numeric .

Download All
0 Kudos
Message 1 of 8
(3,590 Views)

Hi Vikash,

 

why do i get 48.

Please read Wikipedia.

 

1. String to byte array. 

2. Type cast

I got a random value of 48 when the string value is 00.

You don't get a random value. you get exactly what you supply as input data!

 

Hint1: switch your string inputs to hex display…

Hint2: Learn about the basics of data representation! (hex display vs. normal display for strings, decimal vs. hexadecimal display mode for numerics!)

Hint3: When you have problems with your VI you should attach the VI - and not just some images of the VI…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,588 Views)

@GerdW wrote:

Hi Vikash,

 

why do i get 48.

Please read Wikipedia.

 

1. String to byte array. 

2. Type cast

I got a random value of 48 when the string value is 00.

You don't get a random value. you get exactly what you supply as input data!

 

Hint1: switch your string inputs to hex display…

Hint2: Learn about the basics of data representation! (hex display vs. normal display for strings, decimal vs. hexadecimal display mode for numerics!)

Hint3: When you have problems with your VI you should attach the VI - and not just some images of the VI…


Hint4: If you display a control/indicator/constant as anything other than its default display type, always show the radix (in case of numeric) or display type (if string).



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 3 of 8
(3,564 Views)

Another thing that caught my attention.  You say you have an array of string and want to send it as an array of bytes over writing to CAN.  Well a CAN Frame is limited to 8 bytes.  That means your payload can only be at most 8 bytes.  If you attempt to send more than 8 bytes to ncWriteNet.vi I'm guessing it will just ignore the rest.  How do you intend on sending the remaining bytes?  What device are you talking to and how is it expecting to receive these strings?

0 Kudos
Message 4 of 8
(3,522 Views)

I am using CAN hardware from NI and PEAK CAN

NI - USB - 8473

PEAK CAN USB FD

I am trying to transmit the data from PEAK CAN viewer via NI USB 8473 and monitor using the LabVIEW application.

 

PEAK CAN viewer ---> PEAK CAN USB FD (hardware) ----> NI - USB - 8473 (hardware) ----> LabVIEW software

 

I am transmitting only 8 bytes and using extended ID. 

 

For example

I have 8 bytes as 1 2 3 4 5 6 7 8 

bit 0 is 1 and bit 3 is 4 I would like to vary the bit 3 and 4 to different value as the program is running. 

 

When I transmit the data from PCAN Viewer as 1 2 3 4 5 6 7 8 I receive the same message with out any issues.

 

I have attached a sample vi . Please have a look.

 

I am using a decimal input and using "number to hexadecimal string converter" to convert dec value to hex value. 

When I give 10 as dec input the string output shows A which is the equivalent hex value. 

But when I use Hex out array I get 41. 

How will I be able to convert 41 to A again as the CAN write VI will accept only the input inform of CAN INPUT array as shown in the front panel. 

 

https://en.wikipedia.org/wiki/ASCII

 

From wiki I see 41 represent Hex and the concern value on Glyph represent A. Is that the decimal 10 is converter into string A and the string value A is converter to 41 ? i don't understand. 

 

0 Kudos
Message 5 of 8
(3,481 Views)

Hi Vikash,

 

I am trying to transmit the data from PEAK CAN viewer via NI USB 8473 and monitor using the LabVIEW application.

I have 8 bytes as 1 2 3 4 5 6 7 8  - bit 0 is 1 and bit 3 is 4 I would like to vary the bit 3 and 4 to different value as the program is running. 

- When the values should change you need to change them at the sender (PeakCAN-View)!

- You are mixing bytes and bits!?

- How do you want to change those bits (or bytes)?

 

From wiki I see 41 represent Hex and the concern value on Glyph represent A. Is that the decimal 10 is converter into string A and the string value A is converter to 41 ? i don't understand. 

No, you don't understand…

You are mixing numeric values with ASCII strings - that is a problem to many programming beginners!

Replace NumberToHexString and StringToU8Array by a simple BuildArray node to reach your goal…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 8
(3,476 Views)

- When the values should change you need to change them at the sender (PeakCAN-View)!

- You are mixing bytes and bits!?

- How do you want to change those bits (or bytes)?

 

Below is my CAN message

 

$1 $2 $2 00 00 00 00 FF
Where
$1: Direction (0 - Stopped, 1 - Forwards, 2 - Backwards)
$2: Speed

For direction I can use button on the front panel and pass value of either 0,1 or 2

 

For speed I am planning to use dial on the front panel. I want to change the dial decimal value to hex as CAN accepts Hex data format . 

 

No, you don't understand…

You are mixing numeric values with ASCII strings - that is a problem to many programming beginners!

Replace NumberToHexString and StringToU8Array by a simple BuildArray node to reach your goal…

 

Did you look at my attached VI. ?

I have used Number to Hexadecimal string function and string to byte array function as you have mentioned. 

I have done for one value. If i get it right I can use array to reach my goal. 

But string to byte array function did not return what I am looking for. 

0 Kudos
Message 7 of 8
(3,473 Views)

Hi Vikash,

 

Did you look at my attached VI. ?

Yes, I did.

Did you read my suggestions?

 

But string to byte array function did not return what I am looking for. 

Wrong: NumberToHexString does NOT return what you are looking for!

 

I repeat: use BuildArray instead of all those string conversions!

check.png

Best regards,
GerdW


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