
adccommunitymod (AutomationDirect) asked a question.
Created Date: November 10,2010
Created By: bgirouard
**** 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.****
Does anyone know how to convert to/from hexadecimal format using the Click?:confused: I'm still working on trying to perform BCC on outgoing data to a Miyachi Unitek LW70AC laser system via RS-485. The general format is {STX}{Data}{ETX}{BCC}, where the {BCC} is performed on everything within the {Data}section. I believe running a XOR command with all of the characters will do it, but I need the data to be in HEX format first. I know people have suggested going to the DL line, but I'll be blunt: it's a little daunting with all of the available commands, subroutines, stages as well as working with an accumulator:eek:, especially for someone who does NOT have a programming background. Besides, the Click's interface seems much more streamlined and less intimidating, and I 've been starting to get some basic programming there under my belt:D, so hopefully it will be less daunting if I still need to go over to DirectSoft for this project. - Brian
Created Date: November 10,2010
Created by: Do-more PE
Have you tried copying the data to a DH register, doing the XOR then copying back to a text register?
Created Date: November 10,2010
Created by: bgirouard
It looks like that would work, thanks! :D
Another question: is there a way to loop this conversion? For example, I have a data string filling TXT100 through TXT133, and I want it to be converted into DH100 through DH133. Can I automate this conversion, or do I need to manually convert each element? I know there are loop commands (FOR and NEXT), but I'm a newcomer to all of this, and I simply do not know how to increment addresses within this loop function.
- Brian
Created Date: November 10,2010
Created by: Do-more PE
Do a search in the Help file for the work 'pointer '. This should pull up a page on memory addressing using the pointer method (indirect addressing) to allow you to loop through your memory addresses.
Created Date: November 10,2010
Created by: bgirouard
I see that help page, but I can't make the connection on how to setup the loop. I'm sure this makes perfect sense to a programmer, but I just don't see it. The FOR loop simply asks you for a number of loops. What I don't know is how to increment this pointer and have it show up where you want it.
If someone can clarify this further, I would very much appreciate it!
Created Date: November 10,2010
Created by: Do-more PE
Initialize your DSx memory location to zero.
Start your FOR loop.
Do what you need to do with DHy and TXTy as the argument.
Increment DSx by 1
NEXT
Note: 'y ' is the memory location your data is in. 'x ' is an arbitrary memory location that you are not using for anything else.
Edit: Be very careful using For/Next loops in a PLC. It is quite easy to get your scan time to exceed the maximum and trip the watchdog timer.
Created Date: February 15,2011
Created by: bgirouard
Something's wrong
I seem to be having trouble in converting text into hexadecimal equivalents in Click. When I use the copy command, it only copies numbers, and not the way I was anticipating (i.e. if TXTn = 2, DHn = 0002h, and not 0032h). If there is a letter to convert, then the DH value comes back as 0000h.
Has anyone else performed these kinds of HEX conversions within the CLICK plc? I don't see anything enlightening in the help files. If someone could at least confirm that this is happening, it would be most appreciated. Thanks in advance!
Created Date: February 15,2011
Created by: Do-more PE
It appears that you can only copy one text variable at a time to a Hex register. I tested it with version 1.2 and it appears to work properly. Case does not seem to matter. My test program is a single copy instruction from TXT1 to DH1 and an END instruction.
If the value is out of range then you will get a zero as the result. For example if I try to convert the letter "t " to Hex the result is zero and SC43 (out of range) comes on.
Just to confirm, the Copy instruction does take the actual number that the ASCII code represents and puts it in the DHx register. IE if the ASCII code is 0h32, then a number 2 is copied to the DHx register.
Created Date: February 15,2011
Created by: bgirouard
Thank you for the clarification on that. From what you described, the instruction is working the way it is supposed to, but it is not working the way I need it to. Specifically, the copy command only recognizes numbers, and not all ASCII characters. Apologizing for repeating what I may have said previously in this post, this is what I am trying to do:
I have a data string (with letters, numbers, and other characters such as ": ") that I need to generate a BCC checksum value to place at the end of the data string when sending it to my laser system in the form of data . In order to calculate the BCC, I need to take the hex equivalent of each character and perform a XOR with the next character. If my data string is "10RS ", then I need to perform a calculation of:
02h XOR 31h XOR 30h XOR 52h XOR 53h XOR 03h = 01h.
Can this be done with a Click using straightforward copy and math commands, or do I need a more robust instruction set from a DL06 (which I have in-house)?
Created Date: February 15,2011
Created by: bcarlton
Did you come to the conclusion that the STX should be included in the BCC?
I don't envy you this task. It isn't until the P3000 where any kind of checksum generation facility is provided.
Using the DL06 I would lay out the codes in individual V memory registers, perform the checksum calculation, then pack the ASCII values, two at a time, into target V memory registers. Remember, low byte is the first character.
Created Date: February 15,2011
Created by: Do-more PE
After some discussion with the PLC Engineer, we concluded that there really isn't much way of doing this at the moment other than doing a bunch of compare statements which would severely impact the scan time.
We will look at adding a method of accessing the raw ASCII data for checksumming at some future time. I don't have any time frame as to when this might happen however.