Host Engineering Forum

General Category => DirectSOFT => Topic started by: raj_789 on January 09, 2013, 11:50:44 AM

Title: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 09, 2013, 11:50:44 AM
Hello Everyone,
             I need to communicate with DL250 PLC using C# but I am unable to communicate as I don't have it's libraries. Also, is there a list of string commands for this PLC(not Ladder logic commands) which I can send and get response.

This is want I need to do: I only have serial communication access.I already have Ladder Logic Program for PLC which I will write to PLC using Direct Soft.Using C# ,I need to communicate with PLC(DL-250)and change Delay, Number of Cycles,Baud Rate etc. through a GUI which I am designing.I should be able to communicate and change registors values.

Thank You in advance.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: b_carlton on January 09, 2013, 12:03:24 PM
http://www.automationdirect.com/static/manuals/dadnet/dadnet.html (http://www.automationdirect.com/static/manuals/dadnet/dadnet.html)

The above is a link to a manual for the Directnet communication protocol. There may also be specific C libraries.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 09, 2013, 12:44:40 PM
Do you prefer using DirectNET vs. Modbus/RTU?  (you can definitely answer "don't know" or "why do I care" if you do not have a preference).  I think there are some existing C# implementations out there for Modbus/RTU???  Does anybody have any links to any good ones???
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: Controls Guy on January 09, 2013, 12:49:41 PM
Hello Everyone,
             I need to communicate with DL250 PLC using C# but I am unable to communicate as I don't have it's libraries. Also, is there a list of string commands for this PLC(not Ladder logic commands) which I can send and get response.

This is want I need to do: I only have serial communication access.I already have Ladder Logic Program for PLC which I will write to PLC using Direct Soft.Using C# ,I need to communicate with PLC(DL-250)and change Delay, Number of Cycles,Baud Rate etc. through a GUI which I am designing.I should be able to communicate and change registors values.

Thank You in advance.

There are existing commercial and free libraries for Modbus comms and the 250 will act as a Modbus RTU slave on Port 2 (Modbus/TCP as well if you put in an ECOM Ethernet card).  Even if you have to write your protocol from scratch, doing so in Modbus is very easy and probably makes more sense than doing so in a DL-specific protocol.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 09, 2013, 12:58:34 PM
I can't find the answer to this, but when Port 2 of a 250 CPU is configured as a Modbus Slave, what Modbus Function Codes does it support as a slave?  I know it can't be all of them (I don't think so).  I also don't assume that it's the same ones it supports as a Master (trust me, it's two completely different sections of the CPU firmware).
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 09, 2013, 01:19:30 PM
I can't find the answer to this, but when Port 2 of a 250 CPU is configured as a Modbus Slave, what Modbus Function Codes does it support as a slave?  I know it can't be all of them (I don't think so).  I also don't assume that it's the same ones it supports as a Master (trust me, it's two completely different sections of the CPU firmware).
Found it on page 4-35 of the 205 manual (this was one case where it was easier to find in the manual than using google or search on ADC's website)
Function Code
01 - read group of coils: Y, C, T, CT bits
02 - read group of inputs: X, SP bits
05 - set/reset a single coil: Y, C, T, CT bits
15 - set/reset a group of coils: Y, C, T, CT

03, 04 - read a value from one or more registers: V
06 - write a value into a single register: V
16 - write a value into a group of registers: V

Note that this requires a bunch of hacking from Modbus ID to 250 DirectLogic address (and there's a spreadsheet somewhere for that, along with a table in the 205 manual on page 4-36)
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 09, 2013, 01:41:23 PM
Hi Franji1,
           I would prefer Modbus/RTU. Can you send me links? I can use VB libraries for serial communication and then edit registers? If you have any library for VB it will work? Please let me know. Also, can you be more specific about "Note that this requires a bunch of hacking from Modbus ID to 250 DirectLogic address". As this is my first project of communicating with PLC.

Sir, I really appreciate your help.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 09, 2013, 01:46:57 PM
Found this link in StackOverflow (search for Modbus in C# group)
http://code.google.com/p/nmodbus/

Here's a link to chapter 4 of the 205 manual.  Start looking around page 4-35 and beyond for the tables for X, Y, C (bits), and V (registers)
http://www.automationdirect.com/static/manuals/d2user/ch4.pdf

The rest of the 205 manual can be referenced from this web page
http://www.automationdirect.com/static/manuals/d2user/d2user.html
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: b_carlton on January 09, 2013, 02:17:08 PM
Quote
Note that this requires a bunch of hacking from Modbus ID to 250 DirectLogic address


The relationship of the DirectLogic named registers to the equivalent Modbus address is not obvious. An Excel spreadsheet is available at the AD site to suplement the information from the manual.

http://support.automationdirect.com/docs/modbus_conversion.xls (http://support.automationdirect.com/docs/modbus_conversion.xls)
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: Controls Guy on January 09, 2013, 02:30:57 PM
The relationship of the DirectLogic named registers to the equivalent Modbus address is not obvious. An Excel spreadsheet is available at the AD site to suplement the information from the manual.

http://support.automationdirect.com/docs/modbus_conversion.xls (http://support.automationdirect.com/docs/modbus_conversion.xls)

Actually, for V-Memory the address is exactly the same; you just have to convert the address from octal to decimal or vice versa.  ADC's spreadsheet IMHO isn't worth the trouble, just use DEC2OCT() and OCT2DEC() in Excel's Analysis Toolkit and you can put it in your normal memory map spreadsheet, or use a base conversion calculator.  Win 7's calculator has conversion for example, and there's a good one for Android that I can't remember the name of.  Will post the name later.

Coils are [slightly] harder.  That also involves a decimal to octal conversion, but there's also an offset of 3072 decimal.

OK, the Android app is called Hex Plus.  It has simultaneous display in Decimal, Octal, Hex, and binary, entry in any of those bases, and a four function and bit logic calculator (the bit logic does NOT's, AND's, OR's, XOR's, and left and right shifts on words)
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 09, 2013, 07:08:08 PM
Hi All,
       Thank you for your responses.I have already added DLL from http://code.google.com/p/nmodbus/. Now as mentioned in DL205 manual 4-37
 I sent command as string  _serialPort.WriteLine("1089"); and when I read serialPort.ReadExisting(); I don't get any response. I also converted into Dec to oct still no response. Can you tell me what command can I send so that I get response back? I would appreciate if you can any send me example.

Thanks!

Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 09, 2013, 08:03:58 PM
I think you need to look at the nmodbus DLL's exported classes and learn how to utilize those.  Minimally, your code will need to provide
1. Unit ID or Slave ID (Modbus/RTU supports multiple slaves); DirectSOFT lets you configure this Slave ID in the Setup Secondary Comm Port dialog
2. Function Code (see my previous post)
3. Modbus Address
4. Possibly the number of elements to read/write (if it is a read/write multiple function code)

What is the name of the class that the nmodbus DLL exports that implements the protocol?  How do you bind a PC's serial port to an instance of that protocol object?  How are errors reported? does the DLL throw exceptions? return error codes?  We do not know this DLL (nor C#), so you will have to do research on THAT end to figure how YOUR code needs to interface to that DLL's objects.

Note that you must use Modbus/RTU, not Modbus/ASCII or Modbus/TCP any other Modbus flavor that the nmodbus DLL also supports.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 15, 2013, 06:57:28 PM
Hello Everyone,
               I really appreciate your help. I have got all the parameters below:
1.Slave ID (Modbus/RTU supports multiple slaves);
2. Function Code (see my previous post)
3. Possibly the number of elements to read/write (if it is a read/write multiple function code)

But when I run C# code:
 ushort[] registers = master.ReadHoldingRegisters(1,41140,16); where 1=slave ID,41140- Modbus Address and number of points
               master.WriteSingleRegister(1,41100,150);
                 
              ushort[] registers = master.ReadHoldingRegisters(1, 41140,16);
                  string vOut = registers.ToString();


The application gets hanged.I still haven't figured out the address right? I have tried all possible address you can think off.

Today is the last day I am gonna spend time on this. I would appreciate solution ASAP.
As far as DLL goes I got all the dllunder: http://code.google.com/p/nmodbus/downloads/list
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 15, 2013, 08:17:10 PM
Where does it "hang"?  Can you step into the C# method .readHoldingRegisters?  Does it work?  Can you step into WriteSingleRegister?  Does IT work?  Can you step into the 2nd ReadHolding Registers.  Does it work?

It might also be best to post ALL the code (especially where you construct/create/set up the "master" object).

Single step using the VS IDE so that you can what's going on.  If you don't have the IDE, just dump the results after each call to stdout or a window or messgagebox or whatever.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 15, 2013, 08:35:56 PM
It gets Hanged:
ushort[] registers = master.ReadHoldingRegisters(1,41140,16); where 1=slave ID,41140- Modbus Address and number of points
Here is my code:
ing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using Microsoft.VisualBasic;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using FtdAdapter;
using Modbus.Data;
using Modbus.Device;


 try
             {
                 
                 Combo1.Text = _serialPort.PortName;
                 Combo2.Text = _serialPort.BaudRate.ToString();
                 Combo3.Text = _serialPort.Parity.ToString();
                 Combo4.Text = _serialPort.DataBits.ToString();
                 Combo5.Text = _serialPort.Handshake.ToString();
                 
                 _serialPort.Open();
                 richTextBox1.AppendText("Serial Port Opened\n");
             }
             catch (Exception err)
             {
                 string errormsg = "Could not open the port: " + err;
                 MessageBox.Show(errormsg);
             }
                       
             IModbusSerialMaster master = ModbusSerialMaster.CreateRtu(_serialPort);
byte slaveId = 1;
                ushort[] registers = master.ReadHoldingRegisters(1,41140,16); where 1=slave ID,41140- Modbus Address and number of points
               master.WriteSingleRegister(1,41100,150);
                 
              ushort[] registers = master.ReadHoldingRegisters(1, 41140,16);
                  string vOut = registers.ToString();


Here is one link I found:
http://nmodbus.googlecode.com/svn-history/r313/branches/NModbus_net-2.0/src/Modbus.IntegrationTests/ModbusMasterFixture.cs
Thanks!
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 15, 2013, 09:10:56 PM
Please dump the PortName, BaudRate, Parity, DataBits, and Handshake to make sure they match the 250's secondary com port (PLC->Setup->Setup Secondary Comm Port or something like that - I don't have DirectSOFT on this PC).  Make sure the 250's secondary comm port is configured for Modbus.

As an aside, it may not actually be "hanging", but actually timing out and retrying.  Most protocols have that mechanism, and I bet the IModbusSerialMaster interface has a way to see what those settings are.  For example, the timeout may be set to 1 second, with a retry count of 3, so it may take 3 seconds to actually "fail".
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 15, 2013, 09:26:57 PM
Actually, the PortName needs to match the serial port on your PC (look in Device Manager), and it should be COM1, COM2, et. al.  Also, look at the 205 manual to make sure your serial port cable matches Port 2 on the 250-1.  Look on page 8 of this chapter http://www.automationdirect.com/static/manuals/d2user/ch3.pdf for the pin out.  You'll need to make sure your cable matches your PC end.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 16, 2013, 11:50:22 AM
Hi Franji,
          I think for PLC DL250 port2 is configured for MOdBus. Let me check is there a way to configure Modbus.Cable also mataches PC end and port values are been entered by me during run time.
As far as Time is concerned: I am using
_serialPort.ReadTimeout = 2000;                           
               _serialPort.WriteTimeout = 2000;

I know it is trying to communicate but I am still not understanding why does it take so long to respond? Can I use C or C++ instead of C# to communicate with DL-250? Do we have Libraries for serial port Modbus?I am ready to code using any platform but libraries must be available.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 16, 2013, 12:06:54 PM
Patience.  You are dealing with two independent computers.  Switching programming languages won't help.  If you have a communication analyzer that lets you see the data on the cable, that will be a huge step to diagnosing any issues.

In lieu of that, you may also try hooking up your PC to another PC running Hyperterminal (although the data is binary) or some other kind of comm port tool to see if your PC is sending the proper data.  You could actually loop back to your same PC if it has two COM ports.

You never mentioned which baud rate/data bits/parity bits you were using on each end.  If these are inconsistent, you won't get any response either.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 16, 2013, 12:30:14 PM
Baud Rate=9600, Parity Bit=None, Data Bit=8 and Stop Bit=1. I don't see any option for MOdbus in Direct Soft. They only have following Protocol : DirectNET,ECOM,K Sequence. I work on multiple products everyday and able to communicate using the same port :)
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 16, 2013, 01:02:34 PM
That is for DirectSOFT's using of the PC's port.  You want to connect to your 250 PLC using DirectSOFT using an ECOM or Port 1.  Once connected to the PLC, look at the PLC->Setup->Setup Secondary Comm Port, which is the configuration of the 250's Port 2 (the 15 pin connector).  This must be configured poperly.  See the attached screen shot on how it should be configured (based off what you told me your C# code is configured as).

Your cable for Modbus must go from your PC's serial port (probably a 9 pin) to a 15 pin (something that looks like a VGA cable).  This is not a standard cable.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 16, 2013, 04:23:34 PM
Hi Franji,
          After implementing belkow screenshot:the application never hanged and did change the value of register. Now,when I connect back to Directsoft where can I see the value changed. for example: I am changing Timer T2 value but when I log back in using DirectSoft32 where can I get the updated value? I am reading Directsoft 32 manual but if you know it can you please let me know the steps how to read values or updated registers inj PLC. If we can do this then we are good.

Thanks!
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 16, 2013, 04:56:47 PM
Congratulations!   ;D

To monitor values via DirectSOFT, bring up a Data View, which can be done by doing Debug->Data View->New.  It should open up a docked window on the left side labeled Data1.

Next enter V2 in Row 1 Element column (or TA2, which is an alias for V2, Timer Accumulator for timer 2).  The value format is in BCD, which you need to enter as Hexadecimal in C# (every 4 bits is a digit, so 0x9999 is the numerical value 9999 in the PLC - don't ask, that's just what it is, accept it)  ::)  (look here for details http://en.wikipedia.org/wiki/Binary-coded_decimal)

So the Status will reflect the value that you write to the PLC from your C# programming (assuming you have no Timer instructions accumulating timer for timer T2)

Normally, you don't tweak timer accmulator values externally (those are typically read-only by an HMI).  However, User V in a 250 starts at V1400 (octal address - don't forget to convert to Modbus decimal), where you control what is an input from the HMI (i.e. HMI writes to V1400) vs. what is an output from the PLC (i.e. HMI reads V2 or reads V1401).  You will need to convert C# values to/from BCD to 2's complement integer values.  BCD is always unsigned, typically 16 bit (so range of 0-9999).
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 16, 2013, 05:43:17 PM
I write the value  of register value to 1226 in C#.I disconnect and When I connect to PLC (Port) 1 using Direct Soft 32 and Open Data View and and enter V2: I get '0' value. Now,if I go back to my C# program and query Read Holding Ressisters it shows memory 6414 has changed its value to 1226 . Now, my question is how will S/w come to know the edited values? Am I missing any step? I need to get one right and I am sure I can manage rest ;D
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 16, 2013, 08:10:42 PM
Doh!  You can't write to V0 because it is mapped as a Modbus Input Register (you can't write to Input Registers, only Holding Registers)

Try Modbus Holding Register address 769 and see if V1400 or V1401 changed to the value you wrote.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 16, 2013, 09:06:07 PM
But I can edit Timer and CT0 values using Direct Soft 32? Double clicking the element and change it's value.
For 6400 (modbus address) when I run the command in C#,I can see that value has been changed but when I open Data View in DirectSoft I cannot see that change. Also what should I type in Data View in order to get the value for V1400?

Thanks!
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 17, 2013, 08:07:51 AM
V1400 in the first column, the Element column
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: franji1 on January 17, 2013, 08:12:14 AM
Try WriteSingleRegister to Modbus Address 1 and see if V0 (or possibly V1) changes.  Put both V0 and V1 in a Data View, then run your C# code to see if either change.

Note that your PLC ladder logic may actually be using a Timer instruction for Timer T0 and will OVERWRITE what the protocol writes (the PLC has instructions that OUTPUT to those registers).
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 17, 2013, 01:50:19 PM
Hey Franji,
          I am able to edit registers in PLC now ;D ;D. Please check the snapshot attached. I want to change value of K for Timer and Counter. I am trying to check what are there address? Also,is it possible using C# I can change from Run Mode to Program mode?What command makes it work or which register value I need to change?

Thanks!
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: b_carlton on January 17, 2013, 02:00:56 PM
You cannot edit the 'K' value. it is a programmed constant. To change it you must use Directsoft to modify the project then re-download.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 17, 2013, 02:44:53 PM
Is there any other way I can set Counter and Timer to a definate value. When I set it from program mode to run mode why does it start from 0 even though the current value is 200. Can I make it start from 200?
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: plcnut on January 17, 2013, 03:01:45 PM
You need to replace the "k" value in the timer with v1400 (or any handy v-mem) and then use modbus to change v1400.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: b_carlton on January 17, 2013, 03:18:06 PM
Counter 'current' values are retentive. Timer 'current' values - default - are not. Use 'PLC' - 'Setup' - 'Retentive Ranges' to modify this. (Though it may be possible that the 'To Run' cycle may reset TMR type timers anyway. it may preserve TMRA timer values. Check it out. I've never tried it.)
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 17, 2013, 03:54:38 PM
While I wait for a PLC Legitimate Program to test. Can I Change PLC to Program Mode or Run Mode: By editing a register Value? Or is there any other way? I am trying to find the address which can be modified using C# in order to change Mode from Program to Run and viceversa? I need to change mode using my C# program.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: BobO on January 17, 2013, 04:11:45 PM
You will need PLC specifications from ADC. I'm not sure what their policy is on distributing that information, but I doubt they just hand it out without some kind of NDA.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 18, 2013, 12:03:24 PM
I am still trying to find a way where I can switch the modes(Stop ,Program and RUN). As there software is capable of doing it I need a way where I can change modes using my program in C# through Modbus.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: Controls Guy on January 18, 2013, 04:53:37 PM
I am still trying to find a way where I can switch the modes(Stop ,Program and RUN). As there software is capable of doing it I need a way where I can change modes using my program in C# through Modbus.

BobO said that you would need to get the information on how to do so from Automation Direct, and might have to complete a non-disclosure agreement before obtaining the information.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: b_carlton on January 18, 2013, 06:34:25 PM
While Host Engineering 'knows' the method for performing this, since they are the creators of DirectSoft, they can't just 'share' it.

AutomationDirect and Koyo 'own' this proprietary information and they, unless you can show you are creating an incredibly advanced utility, probably will not release the information to you. But you can always try.
Title: Re: C# program for Direct Logic PLC(DL 250 by Koyo)
Post by: raj_789 on January 18, 2013, 07:00:26 PM
I would like to Thank all the members for their valuable answers. I think you guys do a great job.

Sincerely,
Raj