
adccommunitymod (AutomationDirect) asked a question.
Created Date: December 07,2018
Created By: FEContractor
**** 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 new to PLC programming, my normal work is as a firmware engineer programming in C for embedded systems. I am writing logic on a Productivity 2000 (P2-550) for RS 232 communications. I have written a task to be called every second to send out an alive message over the RS 232 connection. I am seeing the data sent out with a terminal program on my PC but it is only sent once. I have a basic task, load the data into an array and send out the RS232 port. I am sending the data out with ASCII Out. I have logic in the task to indicate this task is being called every second and the ASCII Out instruction is being called. I also have InProcess and Complete bits defined for ASCII Out. I see these bits only set one time. I am clearing out the Complete bit before issuing the ASCII Out and I never see this bit get set again. I have looked for any app notes for RS 232 communications at Automation Direct but haven't found any that I'm aware of. I expect that the RS 232 has to have something reset or set before another message can be sent out. I 've dealt with RS 232 ports on embedded system and know that something has to be done before another one can be sent out. So what needs to be done here?
Created Date: December 07,2018
Created by: FEContractor
I'm new to PLC programming, my normal work is as a firmware engineer programming in C for embedded systems.
I am writing logic on a Productivity 2000 (P2-550) for RS 232 communications. I have written a task to be called every second to send out an alive message over the RS 232 connection. I am seeing the data sent out with a terminal program on my PC but it is only sent once.
I have a basic task, load the data into an array and send out the RS232 port. I am sending the data out with ASCII Out. I have logic in the task to indicate this task is being called every second and the ASCII Out instruction is being called. I also have InProcess and Complete bits defined for ASCII Out. I see these bits only set one time. I am clearing out the Complete bit before issuing the ASCII Out and I never see this bit get set again.
I have looked for any app notes for RS 232 communications at Automation Direct but haven't found any that I'm aware of.
I expect that the RS 232 has to have something reset or set before another message can be sent out. I 've dealt with RS 232 ports on embedded system and know that something has to be done before another one can be sent out. So what needs to be done here?
Created Date: December 07,2018
Created by: Alexandru
you ca use ascii over rs232. that will allow you to connect like you already did, from pc to plc. you know to configure the serial, has to be the same at both ends.
you can also use modbus over rs232. plc supports it, question is if the the other end does.
either way, the send block controls the transfer.
I have a click plc so can help out this way, which I assume is similar to your plc.
on my plc, if I needed a text sent out every two seconds, I would do this:
1. I would set up a timer to trigger my transfer every two seconds
2. I would setup the send block for dynamic message, with start address at txt1 and length given by ds1. alternatively, if I could work out with fixed length I would choose that.
3. I would also setup the send block indicators: sending bit to c1 and success bit to c2.
programming:
1. the timer should go around the clock: always enabled.
2. before the timer is done, ensure the message is ready to send
3. when the timer is done, trigger the send on the rising edge of timer done. you need to trigger the send once, not repeatedly with each scan cycle.
4. soon as sending bit is up:
4.1. restart the timer
4.2. prepare new message
problem I see is that your communication could be slower than your timer. so you could have messages skipped, if they update dynamically. you need to figure out what happens then.
Created Date: December 07,2018
Created by: techme
Do you call the task every second or do you have it in the "Run Every Second " task group?
I would suggest putting the logic in a Run every Scan task and using a contact from the flasher set to 500msec ( on for half a second and off for half a second) to get a 1 second bit. Use this bit to trigger your loading of data with a NOE contact to load the data and the ASCII out on the next rung with a NO contact from the flasher to initiate the AOUT.
Seems to work fine in the called every second task, but these task know they are going to be scanned every second. Instructions in Run when called tasks may not get complete in one scan so they will not act the same as they do in a run every scan or a run every second task. Also status bits in the run when called may not get updated if the task is not being called. For this reason I try and keep all my coms instruction in a run every scan task.
Created Date: December 07,2018
Created by: FEContractor
I did try the timer but I wasn't haven't any success getting it implemented.
I implemented the second suggestion. I have the data set up in the rung with the NOE. I made a task that calls ASCII Out and have it on the next rung behind a NO contact. I have this contact set to close when the flasher sets the bit high. All of this is being done on the Run Every Scan section but I still only see the first message sent out. Nothing after this one.
Created Date: December 07,2018
Created by: techme
This is what I have and every second it sends a message as seen in the screenshot when in a run every scan.
{ "data-align ": "none ", "data-size ": "full ", "title ": "1secASCII.JPG ", "data-attachmentid ":119483}
Created Date: December 10,2018
Created by: FEContractor
I found out why my set up only sends out once, but I need an explanation as to why my set up doesn't work. I have the ASCII out in a task that's called every second. If I move the ASCII out to the main scan then it sends every second. So does this mean I can't put the ASCII Out in a task?
Created Date: December 10,2018
Created by: techme
I have no idea what your logic looks like. However if you are controlling the bit that triggers the ASCII instruction in run every scan logic the run when called will see the transition required by the ASCII on the first scan. If the run when called logic never sees an on to off transition and the bit is true the next time you call the run when called logic the logic in this task will not work since it never saw the bit turn off. The ASCII instruction requires an edge trigger it will not see this again until a first scan of the logic in this case.
So as I stated in my previous post it is best to use the coms instructions in a run every scan task
Created Date: December 10,2018
Created by: FEContractor
I have the flasher on the run every scan that sets Trigger every second and the rung after that is following:
{ "data-align ": "none ", "data-size ": "full ", "data-attachmentid ":119526}
I have the ASCII OUT in the RS232 Message Out task. The only way I could get ASCII OUT to send every second was to move it into the run every scan task.
{ "data-align ": "none ", "data-size ": "full ", "data-attachmentid ":119527}
Created Date: December 10,2018
Created by: techme
So the trigger bit will be on every time the "Run When Called ' is called. On the first program scan it will work because the "Trigger " bit will see the off to on transition needed by the ASCII instruction. Every time the task is called after that the trigger bit will true when it is called so it will never see the transition in the run when called logic. So this is working as expected.
Created Date: December 10,2018
Created by: Alexandru
In first example, you set up the message in a subroutine and then you sent the message in the next subroutine. I guess you need a rising edge to trigger the send.
in second example, you still set the message the same, but then return and actually use a rising edge to send.
i guess you’ve missed the rising edge in the first example.