Announcement

Collapse
No announcement yet.

Implementing RS 232 communication

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts


  • Implementing RS 232 communication

    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?


  • #2
    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.

    Comment



    • #3
      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.
      Last edited by techme; 12-10-2018, 09:58 AM.

      Comment



      • #4
        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.

        Comment



        • #5
          This is what I have and every second it sends a message as seen in the screenshot when in a run every scan.

          Click image for larger version

Name:	1secASCII.JPG
Views:	1
Size:	78.7 KB
ID:	119483

          Comment



          • #6
            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?

            Comment



            • #7
              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

              Comment



              • #8
                I have the flasher on the run every scan that sets Trigger every second and the rung after that is following:

                Click image for larger version

Name:	ladderDiagram.png
Views:	1
Size:	2.3 KB
ID:	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.

                Click image for larger version

Name:	ModifiedLadderDiagram.png
Views:	1
Size:	4.3 KB
ID:	119527

                Comment



                • #9
                  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.

                  Comment



                  • #10
                    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.

                    Comment



                    • #11
                      The rung before each of these is the flasher
                      Click image for larger version

Name:	Flasher.png
Views:	1
Size:	1.2 KB
ID:	119534
                      that sets Trigger to 1 every 500 ms and sets to 0 every 500 ms. Put your ASCII OUT instruction into a Run When Called task and replace your ASCII OUT instruction in your logic to Call that task and let me know if you get a message sent every second.

                      Comment



                      • #12
                        No....it will not work. I have been trying to explain why it will not work. So I guess I should just say use your ASCII instructions in the run every scan task.

                        Comment



                        • #13
                          I was cautioned years ago (by ad tech) about having comms instructions in a run when called task.
                          If the task disabled WHILE the comms instruction is operating you may leave the instruction in an unknown and probably unrecoverable state.
                          Since I do not want deal with determining if a comms instruction IS operating, I just put the comms instructions in a task that is run every scan, and have enabling logic for the comms instruction.

                          Comment



                          • #14
                            That's what I see I will have to do. Not like C programming where I call a function to do this.

                            Comment



                            • #15
                              OK, my next question. I have messages I send to the PLC and I am using Custom Protocol In to receive these messages. I am only seeing the first message to be received. If I send a second message, the PLC isn't detecting it.

                              I have the Custom Protocol In set to variable length with 2 characters as the termination code for the message. The max length is set larger than either message being sent in. I am monitoring the communication Booleans and see InProcess is set initially but then is unset after the first message is received. Complete and Success are set after receiving this message. I clear both of these flags after processing the received message and still not getting the second message. I alos tried setting InProcess again once the message was processed but still not getting the second message.

                              So what am I missing to enable the RS232 to receive another message?

                              Comment

                              Working...
                              X