tworst Posted November 20, 2016 Report Posted November 20, 2016 I am already writing string data (symbols) values to a text file on the memory card of a CJ2M. I just want to add the PLC date and time to each text record. The PLC date time is in the area of A351 and I can see the year, month, day , hours, min, sec in the memory viewer when BCD is selected as the interpretation. So, 32 sec is 0011 0010. I want to move this into a symbol I have defined as a string so the bits need to be the ascii codes for "3" and "2". Then I just want to write this string to the text file which is no problem. But I can't figure out how to convert the bits in the A35X words to their ascii string equivalent bits. Anybody done this?
Mendon Systems Posted November 20, 2016 Report Posted November 20, 2016 Take a look at the ASC(086) instruction. It converts BCD digits into a string. 1
Willy65 Posted November 28, 2016 Report Posted November 28, 2016 Hi! Try this... Helps me al the time.. DateTime_to_String.cxf
tworst Posted December 3, 2016 Author Report Posted December 3, 2016 (edited) OK, got my date/time figured out. But now I also want to write a 16 bit numeric value, 0-65535, as a string to the text file as well. ASC only lets you pick out up to the 4th character. Not sure if there is another function that lets you do larger numbers. I have been playing around with ASC, BCD, STR, etc, but still can't find a way to do it. All I want to do is write a 16 bit numeric value as a string to a text file. The value is in D354. Suppose it is 45322. Just write it as "45322" to the text file. I have been using a combination of LL and ST to do this with smaller numbers like 12 with common functions like ACS, but after 4 digits, nothing works. Edited December 3, 2016 by tworst
BITS N BYTES Posted December 3, 2016 Report Posted December 3, 2016 You should consider using a Structured Text program for what you are doing. Far simpler and far more powerful than messing around with ladder based instructions. My 2 Cents.
Mendon Systems Posted December 3, 2016 Report Posted December 3, 2016 There IS another way to do it, but it is cumbersome at best. Convert the decimal value to floating point with the FLT instruction. Add 0.5 with the +F instruction. Convert the floating point number to a string with the FSTR instruction. The reason for adding 0.5 is that the FSTR instruction will truncate rather than round up so 0.9999 will result in 0 rather than 1. You will need to set the FSTR control words to 0 (decimal format), 5 (total # of digits), and 0 (# of decimal digits).
Jay Anthony Posted December 3, 2016 Report Posted December 3, 2016 Quote The reason for adding 0.5 is that the FSTR instruction will truncate rather than round up so 0.9999 will result in 0 rather than 1 Awesome!
tworst Posted December 3, 2016 Author Report Posted December 3, 2016 OK, this is getting maddening. Just want to convert 60,000 decimal to "60,000" text. I have spent hours now. How hard can this be? I am pretty new to OMRON, mostly program in AB, so I am learning how OMRON does things and have a reasonable handle on it. But this is getting ridiculous. I tried the FLT function but only works up to 32,766 and then goes negative. Somebody mentioned using ST but how? Has anybody actually converted 60000 to "60000"? Can you provide specific programming in ST and/or LL? Sorry about my frustration but I could do this faster with relays and and LCD display.......................................
Jay Anthony Posted December 4, 2016 Report Posted December 4, 2016 With CS1-H/CJ1-H CPU Units with unit version 4.0 or later and CJ2(M) CPU Units, there are instructions to convert 4, 8, and 16 digits of numeric data to ASCII (STR4(524), STR8(527), and STR16(528)). Sorry I didn't see it sooner... EIGHT-DIGIT NUMBER TO ASCII.pdf
Mendon Systems Posted December 4, 2016 Report Posted December 4, 2016 If the number is >32767 you can move the value into a Dword and use the FLTL instruction to convert it. That handles numbers up to 2,147,483,647. 1
tworst Posted December 4, 2016 Author Report Posted December 4, 2016 OK, making progress. First tried using STR type functions but those operate on HEX digits, not a numeric value like 65535. Couldn't find a way to convert 65535 to HEX digits first and then use STR. So then tried the float conversion. Had to make a symbol of type DWORD and store 65535 in it first using FLTL. Then used the FLTS on this value, with proper control words, to convert it to ascii characters and that works. I did notice I got a warning during the compile as it didn't like data type of DWORD used as an operand in the FLTL instruction so changed it to DINT and warning went away. Also, since my value will always be an integer, I think I can drop the +0.5 that accounted for rounding. Thanks for all the help. Doing this simple task in OMRON is like one step removed from programming in machine language I did 30 years ago. But I am kind of new to OMRON so I guess I will have to learn.
Mendon Systems Posted December 4, 2016 Report Posted December 4, 2016 There are a few things that are a bit difficult with Omron, and you happened to pick a great example of that. For almost everything else they are quite easy to work with. Consider those data type warnings to be just advisory. It is possible to write a program that does not include any warnings, but generally not worth the effort.
Jay Anthony Posted December 4, 2016 Report Posted December 4, 2016 Quote Consider those data type warnings to be just advisory. It is possible to write a program that does not include any warnings Go back and consider using STR8 and ignore the data type warnings.
Mendon Systems Posted December 5, 2016 Report Posted December 5, 2016 2 hours ago, Jay Anthony said: Go back and consider using STR8 and ignore the data type warnings. Jay, I'm inclined to agree with you after reading his last post. All he would need to do is convert his INT to BCD and then convert it to ASCII with the STR8. Since he's apparently looking for a fixed length string of 5 digits a MID$ instruction would get rid of the leading zeroes for him.
BITS N BYTES Posted December 5, 2016 Report Posted December 5, 2016 (edited) Structured text file to convert A351 thru A354 to text. You can expand upon this by adding the additional text you require. You could expand this ST file to include the additional text you require using CONCAT as well as writing to the memory card using ST command WRITE_TEXT. ST Text Example.cxp Note that this example will NOT work in CX Simulator because the A351-354 words are unique to the hardware. Edited December 5, 2016 by BITS N BYTES App. note
Jay Anthony Posted December 5, 2016 Report Posted December 5, 2016 And who said that there aren't ten ways to skin a cat at Omron.
BITS N BYTES Posted December 5, 2016 Report Posted December 5, 2016 Corrected program. Had text results in D0 then D2. Should be D0 and D4. Apologies for any confusion caused! . ST Text Example 2.cxp 1
BITS N BYTES Posted December 5, 2016 Report Posted December 5, 2016 (edited) ST Example with STRING extract using LEFT/RIGHT ST Instructions. PLC Clock data converted to ASCII starting at DM0. ST Text Example 3.cxp Edited December 5, 2016 by BITS N BYTES
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now