Sign in to follow this  
Followers 0
Ahmed Ibrahim Osman

String to bytes of array in unity pro

13 posts in this topic

you dont convert string to byte

Byte is a size in length of bits.

The byte can be on type string or int or whatever. Please use a translator and ask a full question. We cannot help on the above post....or lack there of

Share this post


Link to post
Share on other sites

I am sorry sir but i try to say That i have tag  data type is String consist of 22 characters, i want to extract character and convert to Byte or to do some calculation. 

Is there any function block can i use it ? 

Thanks

 

Share this post


Link to post
Share on other sites

I hope it will help you:

a1.png.9020539b3547c64267697ad063ba55a2.a2.png.6310a533e43c386b9cf22ca2b761c83d.

Share this post


Link to post
Share on other sites
2 hours ago, Quant said:

I hope it will help you:

a1.png.9020539b3547c64267697ad063ba55a2.a2.png.6310a533e43c386b9cf22ca2b761c83d.

Nice example hahaha

Share this post


Link to post
Share on other sites

I have tag  data type is String consist of 22 characters, i want to extract one  character and convert into Int to do some calculations, i have used( MID_INT) Function Block extracts a sub-string of characters starting from a certain rank. The result is a character string but I want to put in Array of strings or Array of Bytes and then  take every Byte or character  to do some calculations.
Summarization:
 how I can extract one character from string[n] composed of set of characters (n)  is number of characters TO DO SOME CALCULATIONS 

LOOK

Is  There any function Block can i use it?
Thanks

s.png

SS.png

Share this post


Link to post
Share on other sites

I'm not sure if it something complex or is it to easy :(

Your calculation looks like this:some_calc.thumb.png.07f562b74a83668872a9

 

Share this post


Link to post
Share on other sites

I used standard blocks in my example and call all variables with their names.

1) ok, first set values to zero

count:=0;
DO_SOME_CALCULATION := 0;

2)  do a loop for number of elements/characters in your STRING. In your case you have every time 22 characters, so you can just use LEN_ORIGINAL_STRING:=22.

3) you separate every character from STRING - I call it ELEMENT_OF_STRING      as INT

4) you split INT in to 2  Bytes: ELEMENT_BYTE1 and ELEMENT_BYTE2

5) you calculate something that you need with both bytes - I call it DO_SOME_CALCULATION

6) finish :)

 

1 person likes this

Share this post


Link to post
Share on other sites

MR.QUANT i have some problems with write code it's showed me that and i don't understand what is function( INT_AS_BYTE) 

Quant

sssss.png

123.png

Share this post


Link to post
Share on other sites

you are missing INT_AS_BYTE block. But it was only example from me, it was not exactly 100% what you need.

Share this post


Link to post
Share on other sites

Hi there!

I have a question with AB PLC. My problem: 

I have some raw data...distance for example.When the machine starts,the sensor begins to send the information with the distance values. When data is received it is moved into an array. After the first 5 values the program calculates an average and the result is moved into another array.Currently after receiving the fifth value,thus filling the first array,making the calculation and sending the average to the other array,the program empties the entire first array instead of just always discarding the oldest value of the five,and recalculating the average with the newly arrived value every time.

I tried to made this with ladder diagram using an an fifo load and unload but isnt working. Please help me if anybody can. Thank You.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0