AlexPLC

ASCII Communication, How to clear out the TX Buffer of unwanted characters

10 posts in this topic

Hi again gurus!

I am using CompactLogix, 5069-SERIAL card. I am sending a variable length of comma delimited data to the buffer. For the string that contains my data, I send move the length of that string to the "DataLength" parameter of the ASCII module instruction so it only sends out the exact length, so here I have 16 , which happens to be the smallest length for my data

abb.PNG.baced92d9957277b69ab0f24e43ad658

and it's working fine, but one thing I notice is that say if the data goes from a high length to a lower length for example from 123.45,12234.45,123.45 to 1.2,3.4,5.6 then I notice the left over characters in the TX buffer, so even though I have 16 , I still have "garbage" left over up to element number 21

txdata.PNG.8efd39cba21d4173d0f455722d5d3

Is there an easy way to clear out these unused elements? I have done something similar in Siemens using a FOR loop, but have not worked with this system before and just got to the point where it is working "good enough", but I want to clear this data out.

Any help or hint is greatly appreciated

 

 

abb.PNG

abb.PNG

Share this post


Link to post
Share on other sites

I often use a StringNull or StringEmpty variable of type string and length 82 which is the normal max string length.  And then copy that into the stringfinal or Transmit Buffer before I put the real data into it.

1 person likes this

Share this post


Link to post
Share on other sites

yes! makes sense, I made a "state machine" Serial_Send AOI that cycles through and clears the stringfinal and transmit buffer every cycle.

serial_send.PNG.4ce8e5775de13bdd67f0112a

The syntax on clearing the final string was straightforward using cps, but it was tricky getting to work with the Tx buffer since it is a SINT[256] and not a string

state_machine.PNG.2e5bc9846ec2c6d0c8ca0b

 

so now the Tx buffer only has what is being sent.

Thank you so much for your time, responding to my question and passing the knowledge, greatly appreciated BobLfoot!

Share this post


Link to post
Share on other sites

For clearing SintArray which an array of 256 SINT try this;  

CLR SintArray[0]

COP SintArray[0] SintArray[1] 255 - be careful here if you get the length of the copy wrong you'll overflow the SintArray and either Crash the PLC CPU "Major Error"  or erase the next sequential memory location which is part of whatever tag happens to occupy that memory register.

Share this post


Link to post
Share on other sites

hmmm, definitely good point about possible overflow, but since the Tx buffer is fixed at 0-255, shouldn't the 256 always be safe or is it still risky?

 it does not appear that CLR is an option in ST language.  I am trying to find an equivalent instruction.....

Share this post


Link to post
Share on other sites

MOV 0 SintArray[0]

1 person likes this

Share this post


Link to post
Share on other sites

thanks for the help again BobLfoot,I think it will probably be easier to re-write in ladder so I can possibly use the CLR also.

 

Share this post


Link to post
Share on other sites

I took a look at the CLR instruction in ladder. All it does is write all of the bits in the register to "0". How is that different from using a MOV to write the value "0" to the first element of the array?

Share this post


Link to post
Share on other sites

Joe E the CLR Instruction can be used on Timer and Counter elements and when it is it affects the Acc. and DN registers.

Also when CLR is used on a DINT,SINT,REAL etc it consumes 1 less memory register than MOV.  

I also believe CLR may execute slightly faster than MOV.

In space and time critical applications with tons of instructions those small fractions can add up.

Share this post


Link to post
Share on other sites

Gotcha, that makes sense. Thanks for clarifying. In this setting, since OP's using ST and there isn't a CLR in ST, it may make sense to just use a MOV instead of re-doing it in LAD.

Do you know if ST is generally more efficient (processor memory & cycles) than LAD for similar functionality?

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