News:

  • October 30, 2025, 10:58:56 AM

Login with username, password and session length

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

franji1

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

franji1

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

raj_789

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

franji1

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

raj_789

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

franji1

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

raj_789

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

franji1

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

raj_789

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

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3764
    • Host Engineering
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #24 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.
« Last Edit: January 16, 2013, 08:18:28 PM by franji1 »

raj_789

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

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3764
    • Host Engineering
Re: C# program for Direct Logic PLC(DL 250 by Koyo)
« Reply #26 on: January 17, 2013, 08:07:51 AM »
V1400 in the first column, the Element column

franji1

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

raj_789

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

b_carlton

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