Sign in to follow this  
Followers 0
neildobson

MC Protocol VB Sample Code

18 posts in this topic

I've been looking for some decent sample code using the Mitsubishi MC protocol for an embedded application i'm working on. I couldn't find anything suitable so I wrote a VB test app which I am due to port across to my target device (which runs a dialect of basic). Anyone looking for some VB code to communicate with a Mitsubishi PLC is welcome to use any of this code. The attached code is supplied with a sample ladder project saved in GX Developer 8 (used to set-up the comms D8120 and provide some sample data). The example is ready to run on an FX1N PLC fitted with FX1N-232-BD interface. The PC end is fitted with a USB-serial converter using COM4. The serial cable should be wired as follows: 2-3 3-2 5-5 I haven't implemented event driven comms or anything fancy, but all the configuration parameters are adjustable so you should be able to get it running with most Mitsi PLCs. Let me know if it works (or not), and feel free to modify the code yourself if it's broken. Cheers, Neil VB_MC_Protocol_Test.zip
1 person likes this

Share this post


Link to post
Share on other sites
Hi Neil, I had tried to open your PLC program but cannot be opened by my software (MELSEC Version40E). Anyway, I will try to test your VB code into my machine and will inform you later...

Share this post


Link to post
Share on other sites
hi neildobson Good job decoding the MC protocol, it look's a great VB application. Unfortunately i wasn't able to put it working I tried with a A1S PLC (communication Port), result: "RCV: Error no response from PLC!!" With a FX2N (communication Port),: "RCV: Unknown response from PLC!!" Unfortunately i don't have a 232-BD interface, but i think that the MC protocol also work on the Communication port. Can you tell if this is the protocol used by Mistubishi aplications to comunicate with the PLC, like GX developer??

Share this post


Link to post
Share on other sites
Well I'm no expert on Mitsubishi comms by any means but I wondered myself whether the programming port was configured to receive protocol requests but alas it didn't work for me. I was however intrigued so I used a serial port monitor to look at the comms traffic with GX Developer loaded (with data monitor window open). The messages sent to/from GX look different to the MC protocol (as far as I could tell), so I guess there is an additional undocumented protocol that Mitsubishi uses for programming access. Having said that, perhaps you can configure the programming port to switch to protocol mode using D8120. Haven't tried that yet. I'm unsure why the program doesn't work with A1S (and I don't know your switch settings) but might they differ from those set in the test prog? I've noticed if you have anything set differently such as checksum, protocol format etc. the PLC doesn't reply at all!! I posted a GX config so that those with identical set-up to me (FX1N-40MR-ES + FX1N-232BD) could run the software without guessing the protocol configuration (D8120). For those who don't have GX, i'll post the ladder tomorrow.

Share this post


Link to post
Share on other sites
hi Neil, I also tried to communicate this with my FX2N PLC via 232BD port, but same experience with Calvin "RCV: Unknown response from PLC".

Share this post


Link to post
Share on other sites
Well what seemed to work fine yesterday now appears to be broken. It is of course important that D8120 is set-up correctly in order for this to work. Yesterday I had the port set-up as 9600,N,8,1. The PLC no longer replies when I run the test for whatever reason and I get the no response message. I have no idea why this is the case so I have modified D8120 which should be set to H4880 for the example to work as set-up in the enclosed screenshot. The PLC contains the following ladder M8002 -[ ]---------[MOV H4880 D8120] I have also been unable to connect directly to the programming port. I wonder if MC protocol is available on this port? Interestingly when you plug in Mitsi or 3rd party HMI panels into the programming port these work fine without having to adjust D8120 so I guess these use some other protocol? Edited by neildobson

Share this post


Link to post
Share on other sites
If anyone knows the basic FX CPU protocol please let me know? I am going to write a simple class or perhaps an ActiveX which embeds the mscomm control and allows simple batch read/writes. This combined with the simple programming cable will make a low-cost option to enable VB comms direct to the CPU port. A quick look on the internet shows that a number of HMI companies such as Beijer, Proface etc. already have the FX CPU protocol drivers as well as the 1:N computer link drivers but the FX CPU protocol appears undocumented so perhaps this was reverse engineered?

Share this post


Link to post
Share on other sites
OK I have details of the FX CPU programming port protocol. You need to open your COM port with the following: 9600 baud,even parity,7 data bits,1 stop bit. The protocol format is as follows:- <STX><CMD><Address 4 hex bytes><Qty 2 hex bytes><ETX><Checksum> Where: CMD is 0 for read, 1 for write Address is absolute memory address (need to work on this) Checksum is lower 2 hex bytes from total of all chars including ETX, but excluding STX. I'm working on updating the test app which is currently working with device reads. Once completed this will allow direct connection from VB to FX CPU port using SC-09 or the basic cable mentioned elsewhere on the forum.

Share this post


Link to post
Share on other sites
This is the response if the setting of the comm is "9600, 8, N, 1" if you select "PC" command:

Share this post


Link to post
Share on other sites

I've managed to spend some time (too much time actually) to write my very first class module which implements both MC & Direct FX CPU protocols. I've updated the original sample app so that you can play around with the everything and see what gets sent/received etc. and i've also included a couple of samples which demonstrate both protocols in action. Each sample reads the PLC's built in potentiometer and updates a progress bar. Have a play and let me know how you get on. I'll post some documentation when I get a minute but it's pretty easy. For those who are having problems, remember both protocols are ASCII based using only a few control codes, characters A-Z and 0-9. If the received string contains unprintable characters then there must be a comms setting or cable problem. When working with the FX CPU direct, the port should be set to 9600,E,7,1 only or it won't work!! For MC protocol this depends on how you set-up D8120. Be careful to check this and the protocol format, checksum etc. It's all detailed in the FX Comms manual. If you continue to have problems let me know your cable pin-out, D8120 setting and the sample code. Also look at both mitsi.sendstring and mitsi.receivestring which are the raw strings sent to/from PLC. If all else fails check out Kepware who sell a great range of OPC servers which include plenty of OPC sample code. Good luck. Mitsi_Comms.zip

Share this post


Link to post
Share on other sites
Hi Neil, had tried your "Comms" project and is working well... You did a great stuff!!! How about if I will have to control the M, what should I add to the "Case"? Regarding the other project, I don't know what shout I have to fill-up on the textbox field... but I tried putting a strings like "<STX>100A0020700<ETX>, "255" appears on the txtbox field.

Share this post


Link to post
Share on other sites
Hi Neil, I know you are expert in VB programming. I have attached a a sample PLC program (FX2N) and its VB form together with Mitsubishi programming protocol format. I couldnt interpret it well and i hope you can help me on how to deal by providing me a simple example VB program. I used FX2N-232BD for communication. In my conditions: * When the Command1 button is clicked, the M0 of the PLC will be active and energizing the Y0 output of the PLC. * When the Command2 button is clicked, the M1 of the PLC will be active and de-energizing the Y0 output of the PLC. * The listbox will display "Y0 is ON" if Y0 is ative and "Y0 is OFF" if Y0 is inactive. The signal to listbox should be from the PLC. If the VB program could not receive any response from the PLC, MessageBox will display "Communication Error". sample_FX2N_prog___protocol.pdf

Share this post


Link to post
Share on other sites
I have included two samples which demonstrate each of the protocols in action. Both require the Comm settings to be adjusted to your PC configuration in order for them to work. Both samples continuously read the data register D8030 which is the first potentiometer on the FX PLC. The value is displayed in the text box and also graphically represented in the progress bar. Adjusting the potentiometer with a screwdriver should quickly update the controls. This was done to show how simple it is to read some data from the PLC. Finally i'm looking for some information on the memory map of FX PLCs. The Direct FX CPU protocol doesn't use X,Y,D,T etc. but instead uses absolute memory addresses. I found some 5+ year old C code which converts the device address (D100, T50 etc) into the absolute address but I don't know if i've included everything for all PLCs. In particular there appears no way to address M data as words which I am sure you must be able to do. Is there any Mitsi or 3rd party documentation which describes the PLC memory map? I spent about 3 hours with google yesterday with no luck.

Share this post


Link to post
Share on other sites
I've included an example which provides a simple joystick controller. There are four buttons, each of which when pressed sets an M bit and when released resets the same M bit. The PLC ladder (see enclosed screenshot) then sets Y outputs depending on which M bit is set. In your application you would set/reset various data using whatever protocol you wish. You load the data into the mitsi.PLCdata() array and then execute the command with ExecuteMCCommand (if using the MC protocol). You then wait for reply from the PLC. I have implemented mitsi.CommsBusy. This is set to true when you execute the command and goes false when the PLC has replied or a timeout has occured. You then look at the mitsi.TimedOut and mitsi.ErrorCode properties to see if there is an error. Remember if you are waiting in a loop to use DoEvents. Joystick_Controller.zip

Share this post


Link to post
Share on other sites
I found this document which explains a bit more about FX CPU (Programming) Protocol. This is quite interesting as it implies that you can do single bit read/writes as well as words. However I am still unsure what are the addresses of all the PLC devices. This protocol does not use D,X,Y etc. Anyone shed any light on this? mitsufxs.doc

Share this post


Link to post
Share on other sites
Hi Neil, I have tried the latest program but it does not response to my PLC.

Share this post


Link to post
Share on other sites
Hello! I have information about the absolut memory address scheme - used by this FX protocol. I also recognized, that writing a BIT works with command 7 (set bit) and command 8 (clear bit). But I don't have the excat protocol details at the moment. Any ideas about writing just a BIT to the memory? Mitsubishi_Protocols.xls
1 person likes this

Share this post


Link to post
Share on other sites
Does this code works on the FX3U plc? Ive tried yesterday, and if i try to read Y16 i get the result 4093 if Y16 is true or 4092 if Y16 is false. Shouldnt it return 1 or 0? The raw data is; mitsi.sendstring = "000A202(L)68" mitsi.receivestring = " FD8F(L)0B" (L) = strange letter :) I connected the pc using the Direct FX CPU protocol. The connection parameters where "9600,E,7,1".

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
Sign in to follow this  
Followers 0