Announcement

Collapse
No announcement yet.

Implementing RS 232 communication

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

  • FEContractor
    started a topic Implementing RS 232 communication

    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?

  • FEContractor
    replied
    Can you post your diagram? Maybe someone could see where the issue is.

    Leave a comment:


  • grace
    replied
    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.

    Leave a comment:


  • FEContractor
    replied
    Yes everything is working. Thanks for all the information provided.

    Leave a comment:


  • MikeN
    replied
    Originally posted by FEContractor View Post
    Thank you for the above example. Now I see that I have been setting/resetting my Boolean variables the wrong way.
    Been a couple days, so Im guessing it is all working now?

    Leave a comment:


  • Adisharr
    replied
    Another reason I avoid conditionally calling tasks or subroutines. There's always a hang up somewhere.

    Leave a comment:


  • FEContractor
    replied
    Thank you for the above example. Now I see that I have been setting/resetting my Boolean variables the wrong way.

    Leave a comment:


  • MikeN
    replied
    Originally posted by FEContractor View Post
    I looked at the video, I don't understand the question about the instruction to receive in on at all times. I have the Custom Protocol In on the Run every scan task. So I am assuming this is the instruction to receive in is on. Is there another way to make sure the instruction to receive in is on?
    In ladder logic, all the contacts have to be true for the coil/box instruction at the end of the rung to function. If you dont have any contacts in the rung, then it will be on (or, true) all the time. Productivity works likle this, but Do-More automatically places "always on" contacts at the start of a rung if you left it blank. Same thing, just different ways PLCs do it.

    If your custom protocol in does not bring any other messages in other than the first one, it likely needs to be turned off between messages and then cycled back on. Try something like this:
    Click image for larger version

Name:	custom.png
Views:	62
Size:	15.0 KB
ID:	119566

    Leave a comment:


  • techme
    replied
    Look at the timing charts at the bottom of the help file. Once you get a complete ( whether a success or a timeout) you must disable the instruction and re enable to reset the bits and put in progress again.

    Leave a comment:


  • FEContractor
    replied
    I looked at the video, I don't understand the question about the instruction to receive in on at all times. I have the Custom Protocol In on the Run every scan task. So I am assuming this is the instruction to receive in is on. Is there another way to make sure the instruction to receive in is on?

    Leave a comment:


  • MikeN
    replied
    Originally posted by FEContractor View Post
    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?
    Is the instruction to receive in on at all times?

    Watch this video:
    https://www.automationdirect.com/vid...cat2=7&cat3=10

    It will be slightly different because you are doing custom protocol instead of straight ascii, but much of it will be similar
    Last edited by MikeN; 12-11-2018, 09:45 AM.

    Leave a comment:


  • FEContractor
    replied
    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?

    Leave a comment:


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

    Leave a comment:


  • kewakl
    replied
    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.

    Leave a comment:


  • techme
    replied
    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.

    Leave a comment:

Working...
X