
adccommunitymod (AutomationDirect) asked a question.
Created Date: March 02,2005
Created By: mpiotro
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
I'm reading in an ascii string into the DL06. This string is just a number, anywhere from "1 " to "99 ". I'm trying to convert this # to a counter preset value. What I'm doing is: 1. AEX - # of bytes =4, convert to BCD, destination address V400 2. LDD V400 3. DIV V410 (V410 contains K10) 4. OUTD V420 I then set my preset counter value to V420. This works great if my ascii string is a single digit, but doesn't work when my string is 2 digits. what happens is V400 is no longer 10x the value of the ascii string, it is simply the same value as the ascii string (hence V420 becomes only the first digit of the string). For example, if the ascii string is "18 ", V420 =1; if the ascii string is "95 ", V420 = 9. I guess I could always count the # of characters in the string to determine if I divide by 10 or not, but this seems like masking the problem. Any ideas? -Mike
Created Date: March 02,2005
Created by: mpiotro
I'm reading in an ascii string into the DL06. This string is just a number, anywhere from "1 " to "99 ".
I'm trying to convert this # to a counter preset value.
What I'm doing is:
1. AEX - # of bytes =4, convert to BCD, destination address V400
2. LDD V400
3. DIV V410 (V410 contains K10)
4. OUTD V420
I then set my preset counter value to V420.
This works great if my ascii string is a single digit, but doesn't work when my string is 2 digits.
what happens is V400 is no longer 10x the value of the ascii string, it is simply the same value as the ascii string (hence V420 becomes only the first digit of the string). For example, if the ascii string is "18 ", V420 =1; if the ascii string is "95 ", V420 = 9.
I guess I could always count the # of characters in the string to determine if I divide by 10 or not, but this seems like masking the problem.
Any ideas?
-Mike
Created Date: March 04,2005
Created by: Russ
Hi Mike,
Maybe this isn't the type of solution you were after, but here's a general outline:
You can use the right/left Shift commands (SHFR K8 / SHFL K8) as well as the bitwise AND to manipulate the MSB and LSB of your ASCII word.
Once you have the individual ASCII digits broken out, you can convert from ASCII to decimal simply by subtracting hex 30 from the ASCII byte representation of that decimal digit.
Here's an example:
ASCII character "9 " is hex 39.
In Hex: 39 - 30 = 9
It's a simple way to convert from ASCII to hex and decimal.
You can reverse the MSB / LSB breakout process by using bitwise Or and Shifts to reassemble your new decimal digits.
Hopefully, this was what you were looking to do.
-Russ
Created Date: March 05,2005
Created by: RHanrahan
Also in the AEX command there is a check box to "Swap bytes ". This will swap the order of the High byte/low byte.
Created Date: March 07,2005
Created by: mpiotro
Fellas,
thanks for your help!
I got it working by simply swapping bytes in the AEX command (after spending several hours playing with shifts, ands, ors, etc but hey, this was valuable learning )
The only other thing I had to do was alter my vb code to put in a leading zero on a single digit string, otherwise the carriage return of the string would screw things up.
Why is it always that when I'm stuck in vb, I can think of an easy solution in ladder logic thinking, and vice versa.......
Thanks again,
Mike