News:

  • October 29, 2025, 04:05:28 PM

Login with username, password and session length

Author Topic: C# program for Direct Logic PLC(DL 250 by Koyo)  (Read 35479 times)

raj_789

  • Jr. Member
  • **
  • Posts: 15
C# program for Direct Logic PLC(DL 250 by Koyo)
« 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.

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #1 on: January 09, 2013, 12:03:24 PM »
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.
An output is a PLC's way of getting its inputs to change.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3762
    • Host Engineering
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #2 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???

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3601
  • Darth Ladder
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #3 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.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3762
    • Host Engineering
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #4 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).

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3762
    • Host Engineering
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #5 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)
« Last Edit: January 09, 2013, 01:21:12 PM by franji1 »

raj_789

  • Jr. Member
  • **
  • Posts: 15
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #6 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.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3762
    • Host Engineering
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #7 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

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #8 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
An output is a PLC's way of getting its inputs to change.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3601
  • Darth Ladder
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #9 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

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)
« Last Edit: January 09, 2013, 06:01:10 PM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

raj_789

  • Jr. Member
  • **
  • Posts: 15
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #10 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!


franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3762
    • Host Engineering
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #11 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.

raj_789

  • Jr. Member
  • **
  • Posts: 15
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #12 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

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3762
    • Host Engineering
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #13 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.

raj_789

  • Jr. Member
  • **
  • Posts: 15
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #14 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!
« Last Edit: January 15, 2013, 08:47:17 PM by raj_789 »