ChrisKozanecki

What am I doing wrong?

11 posts in this topic

Ok, so this is my first time using RS232 communications, I have a CJ1G-CPU42H and I am trying to learn from the "CS/CJ series Instructions Reference Manual" how to use them before I throw them into a program. What I am having problems with though is getting it to do anything. I am starting with a basic program that is only 2 lines:                      _______ ----| |-------------| TXD   |     0.00            | D0001 |   (474F in memory twice. ASCII for GO GO)                     | D0000 |   (0000 in memory for No ES & No RS... MSB first)                     |  &4   |                     |_______|                      _______ ----| |-------------| RXD   |     P_On            | D0101 |                     | D0100 |                     |  &4   |                     |_______| I am trying to talk to a program written in VB that is used to verify communictaions with other things in the facility, and its set on COM2 9600,E,7,2 because I have the dip switch #5 set to ON (which if I understand correctly makes the PLC talk at this pattern) The cable I am using to go between the PC and the PLC is one made based on the drawing in a manual downloaded from oeiweb.omron.com. Hopefully I have given enough information and its just a simple mistake that I am missing. Edited by ChrisKozanecki

Share this post


Link to post
Share on other sites
I think I would use #4 instead of &4. #4 tells you got 4 bits to send. D0001 is your send word. and d0000 should have either #0000 or #1000 depedningon whether you are sending it from peripheral port or the other port. Try using #. My $0.02.

Share this post


Link to post
Share on other sites
Hi, You will need to set the host link (RS232) port settings to RS232 mode in the PLC settings Dialog (using CX Progammer) and download the settings. DIP switch 5 should be off. This will allow your settings to operate. (DIP Sw 5 ON = standard Omron SYSWAY protocol and the TXD function will not operate) It is best to use the 'RS232 Port Ready bit' A392.05 as a condition to executing TXD. If this bit is not true, fire (one shot) the 'RS232 Port Reset Bit' A511.01 to reset the port. (this bit will flush the receive buffers and reset the port ready to go) Do not use the 'P_On' bit for RXD, instead use the 'Reception complete Flag' A392.06 as the condition to execute RXD. This flag is set when the correct completion code or number of bytes have been received at the port. (This can be set in the PLC settings under the host link tab) I usually use the the 'number of bytes received' word A393 in the RXD (thus I read the entire reception buffer). General - normally as a first step it is easier to test your code using a program such as hyperterminal. Set it up with the correct port settings etc and you can see the data transmitted from the PLC. You can also send data to the plc (by typing it) etc. This method allows you to 'see' the data traffic, confirm that your cable is ok etc. If you need more information, please ask... perhaps if you posted your code we could help you further. Nibroc

Share this post


Link to post
Share on other sites
Oh my god Nimroc! that is exactly what was wrong! Now my PLC and My Computer are talking with no problem. My next step will be to try and integrate RS-232 into a full program. I appreciate your help as I have been pulling my hair out all day. Hopefully I will be able to get it on my own from here, but if not then I will surely take you up on this: <-- doing the happy dance now

Share this post


Link to post
Share on other sites
Ok so I have my program workign to send and recieve. It interprets things just fine. Unfortunately now people are adding extra requirements in that they want to have the PC and the PLC respond to each other so we can do error checking and/or have the devices error out if there is no response in X timeframe. I think that the Protocol macros will allow me to do what I want, but my question is whether I would be able to use it in the integrated RS232 port of the PLC, or do I need to get a serial module? What I need is: -->PLC tells PC: 'message' -->PC tells PLC: 'OK' or 'Resend' (or some way of allowing PLC to know to resend/error out) -->PLC waits until PC is done. -->PC tells PLC: 'done and p/f info' -->PLC performs error check -->PLC continues program Perhaps there is a better way? Right now I am not sure how to setup a procedure for this other than to possibly do a jump to a loop that runs until X condition or Y timeframe.

Share this post


Link to post
Share on other sites
Hi, It is probably best not to develop your own serial 'protocol'. 1. Does the PLC really need to intiate the communications? If not you could program the PC to regularly poll (continuosly if required) the PLC for data (like a SCADA does). No comms programming will be required in the PLC, simply set the RS232 port to standard (sysmac way/hoslink) mode. All error checking is done at the PLC and no faulty comms will be accepted. The 'hostlink' protocol also reports an error code back to the PC - reporting if communications was OK etc. 2. If the PLC needs to intiate the communications then ... Why not pick one which is well documented such as Omron 'Hostlink' or maybe the more universally used modbus. Both of these are well documented and provide error checking etc within the standard protocols. Both of these protocols require full handshaking type communications with error response codes etc. The Omron protocol description is documented in the CS/CJ communications protocol manual (W342-E1-09) under 'C mode'. A description of Modbus can be found at Modbus.org (Modbus RTU method is the one to use). Using the standard serial port on a CJ1 you can implement either of these protocols. If you chose Omron 'Hostlink' (also called sysmac way, c mode) there is a ladder function (FCS) to calculate the required check sums. If you chose Modbus, you will need to calculate the CRC-16 type checksum using ladder code - there are examples of this ladder code about (maybe on this website?). Note that the CJ1 has For-Next loops and function blocks (structured text) etc so this should not be difficult (i have done it with a CPM2A in the past). (if I had the time I would like to write a modbus send and modbus receive function blocks) Alternately protocol macros would probably reduce the development time as both of these protocols are prewritten and freely available. Of course you will also need to program the PC to talk the same protocol, so I prefer option 1 (you only program the PC to talk standard Omron protocol, the PLC runs standard with not comms program) Let me know how you get on... Nibroc Edited by Nibroc

Share this post


Link to post
Share on other sites
I would also recommend to go with option 1..... Have you looked at ths download ????? Example VB Hostlink (Sysmac Way) Comms Program

Share this post


Link to post
Share on other sites

Hello...may I ask... Does this DIP switch located on the PLC itself? And does CP1E N-type have it? Cause I'm having problem with my TXD program. The A392.05 is at ON state after powering up. But the moment i hit 0.01 switch to initiate TXD command, the A392.05 goes OFF, and I need to power off my PLC to get A392.05 turn back ON. Can I know what's causing it? Thank You

Edited by umar9876

Share this post


Link to post
Share on other sites

A392.05 Built-in RS-232C Port Send
Ready Flag
(No-protocol mode)
ON when the built-in RS-232C port is able to send data in no-protocol
mode.

I think DIP switches here are related to RS422/485 conversion unit / option board (CP1W-CIF11/12). Probably you continously send data to rs232 port, that's why it is allways busy. try to send it once, on diffup condition, and do not send another one until you get port is ready flag A392.05.

Share this post


Link to post
Share on other sites

Hi, thank you for replying tashinz...

Below is the code i use for my TXD program, which i got from here  http://forums.mrplc.com/index.php?/files/file/288-txd-rxd-quickstart-programs/  By continously, did you mean i try to send 3 bytes at once? Switch 0.01 is connected to a push ON switch.

Ladder Diagram

|----| 0.01|--------| A392.05 |----------------------------------| @TXD(236) |

                                                                                  |      D10          |      S: First Source word

                                                                                  |      #100        |      C: Control word

                                                                                  |       &3           |       N: Number of bytes

For my convinience, i connected a switch to A526.00 bit so I could restart the built-in RS232 port without powering off the PLC it self.

|----|0.00|-------------------------(A526.00)----|

And how to apply diffup condition? Is this the right way?

|----|0.02|--------------------------------|  DIFU   |

                                                   |   0.01   |

|----|0.01------|A392.05------------| @TXD  |

 

EDIT:Tried this configuration, still the same, A392.05 goes off as soon as i switch on 0.02

EDIT: I uploaded the ladder diagram for my program below. I notice A392.04 bit turn on as soon as i run the PLC. When switch on 0.02, A392.04 turn off, and after i reset port (A526.00), A392.04 remains off.

 

Thank You.

 

 

cxone.PNG

Edited by umar9876

Share this post


Link to post
Share on other sites

using '@' in the instruction executes instruction only once when input condistions true, until they are true again etc. So no need to use difu.

I am not very familiar with TXD RXD instructions, but there is a preety comprehensive help (right click on instruction select Instruction Help) in cx-programmer, you shoud set up a port in settings, there is an example also. Tried to use built in tag P_ER after instruction and immediately set some bit e.g. W10.0 to remember P_ER since it is used by other instructions.

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