Jump to content

Cannot communicate with the PLC with the specified UnitID!


hoseman

Recommended Posts

I am using the demo ComDriver code as follows:

using System;
using Unitronics.ComDriver;

namespace Com_Drive_Net___Example
{
	class AccessClass
	{
		static PLC plc;

		public static void Test (){

			Ethernet eth = new Ethernet ("192.168.1.152", 20256, EthProtocol.TCP, 3, 3000);

			try{
				plc = PLCFactory.GetPLC(eth, 0);
				plc.EventAbortCompleted+=new PLC.AbortCompletedDelegate(plc_EventAbortCompleted);
			}catch(Exception e){
				eth.Disconnect();
				Console.WriteLine ("Error1:"+e.Message+"-->("+e.TargetSite+")"+e.StackTrace+"-->"+e.Source);
			}
			try{
				Console.WriteLine(plc.Version.OPLCModel);
				Console.WriteLine (plc.PlcName);
				Console.WriteLine(eth.Connected);
				Console.WriteLine(plc.UnitId);
			}catch(Exception e){
				eth.Disconnect();
				Console.WriteLine ("Error2:"+e.Message+"-->("+e.TargetSite+")"+e.StackTrace);
			}
	
			Console.Read ();
		} 
		public static void plc_EventAbortCompleted(){
			Console.WriteLine ("dunno");
		}
	}
}

It is pretty much straight out of the book.  

 

I continue to get the following error:

Unhandled Exception:
Unitronics.ComDriver.ComDriveExceptions: Cannot communicate with the PLC with the specified UnitID!
  at Unitronics.ComDriver.PLC..ctor (Int32 unitId, Unitronics.ComDriver.Channel channel, Boolean suppressEthernetHeader) [0x00000] in <filename unknown>:0 
  at Unitronics.ComDriver.PLCFactory.getPLC (Unitronics.ComDriver.Channel& channel, Int32 unitId, System.Boolean& isConnected, Boolean suppressEthernetHeader) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: Unitronics.ComDriver.ComDriveExceptions: Cannot communicate with the PLC with the specified UnitID!
  at Unitronics.ComDriver.PLC..ctor (Int32 unitId, Unitronics.ComDriver.Channel channel, Boolean suppressEthernetHeader) [0x00000] in <filename unknown>:0 
  at Unitronics.ComDriver.PLCFactory.getPLC (Unitronics.ComDriver.Channel& channel, Int32 unitId, System.Boolean& isConnected, Boolean suppressEthernetHeader) [0x00000] in <filename unknown>:0 

I have tried three different versions of Unitronics.ComDriver.dll, dated 7/26/15, 7/29/15 and compiled myself yesterday, 3/2/16.  Same error on everyone.  I am not a C# expert by no means, but I can't see what I might be doing wrong.

 

We set the the PLC to TCP/slave and set its Socket 0 Port to 20256 (mostly in desperation)

 

I'm not sure what to try next?

 

Thanks

Link to comment
Share on other sites

Hi, this could also be a UAC / Permission issues, since the communication dll is trying to extract an xml file.

You could make the dll not extract the dll, and use it in RAM, by:

 

PLCFactory.WorkWithXmlInternally = true;

 

(Do this just once, when the application starts).

 

 

Tell me if it helps. If not, when you can debug the code (the exception you see hides the actual error. I don't know if it fails dues to timeout or some other issues).

Link to comment
Share on other sites

  • 8 months later...
  • 3 months later...
32 minutes ago, Joe Tauser said:

I got a call today from a customer having this problem after moving his program to Windows 10.  He is using 1.0.0.67 of the .NET driver.

What shall we try?

Joe T.

Run the program as administrator. There is also a property called PLCFactory.WorkWithXMLInternally (or something similar), which if set to true, the .net driver will not try to extract the xml to the drive (which results an access denied, and an error which makes the driver think that there is a communication problem).

 

 

7 minutes ago, bwdavis said:

Hi, I'm trying to communicate with a unitronics plc and am using the C# sample code provided by an email from Unitronics, Boston Support as below:

I have not seen your code. Try running your code as administrator.

Link to comment
Share on other sites

2 minutes ago, Saragani said:

Run the program as administrator. There is also a property called PLCFactory.WorkWithXMLInternally (or something similar), which if set to true, the .net driver will not try to extract the xml to the drive (which results an access denied, and an error which makes the driver think that there is a communication problem).

Sorry, I posted that prematurely.  New on the forum and all that.  I did try PLCFactory.WorkWithXMLInternally = true;  I placed the code directly above the commented line at the top of the try block below.  It made no difference.  I will try your suggestions.

 

Hi, I'm trying to communicate with a unitronics plc and am using the C# sample code provided by an email from Unitronics, Boston Support as below:

        private void Connect_Click(object sender, EventArgs e)
        {
            Ethernet ethernet = new Ethernet("10.10.11.25", 20256, EthProtocol.TCP, 3, 3000);

            try
            {
                // plc = PLCFactory.GetPLC(ethernet, 0); // <-- No overload for method 'GetPLC' takes '2' arguments

                plc = PLCFactory.GetPLC(ethernet, 0, true); // <-- Add boolean so it will build
                plc.EventAbortCompleted += new PLC.AbortCompletedDelegate(plc_EventAbortCompleted);
                setButtonsEnableState(true);
                PlcVersion version = plc.Version;
                txtModel.Text = version.OPLCModel;
                txtHW.Text = version.HWVersion;
                txtOS.Text = version.OSVersion;
                txtBoot.Text = version.Boot;
                txtBinLib.Text = version.BinLib;
                txtFactoryBoot.Text = version.FactoryBoot;
                try
                {
                    txtPlcName.Text = plc.PlcName;
                }
                catch
                {
                }
            }
            catch (Exception m)
            {
                MessageBox.Show(m.Message);
                setButtonsEnableState(false);
                ethernet.Disconnect();
                System.Windows.Forms.MessageBox.Show("Could not establish a connection to the PLC");
            }
        }

This code is straight from the sample code provided with latest Unicom.CommDriver.dll.  Trying to build this on VS 2008 C#, I first get:

No overload for method 'GetPLC' takes 2 arguments

Editing that, and adding a boolean, true or false so that it will build, and then running it,  I get: Cannot communicate with the PLC with the specified UnitID!

Tried running in compatibility mode as administrator for Windows XP SP3, same result.

Application code broke with upgrade to windows 10.

Environment

Windows 10 build 1607

Visual Studio 9.0 (2008)

C#.NET

Bruce D

 

I have not seen your code. Try running your code as administrator.

 

Link to comment
Share on other sites

Well, if you have a newer version of Visual Studio, then you can pass only 2 arguments to the PLCFactory.GetPLC (due to the added support of optional parameters)

 

For having this code work on Windows 10, you will need to add PLCFactory.WorkWithXmlInternally = true;

For example:

 

 private void Connect_Click(object sender, EventArgs e)
        {

             PLCFactory.WorkWithXmlInternally = true;
            Ethernet ethernet = new Ethernet("10.10.11.25", 20256, EthProtocol.TCP, 3, 3000);

            try
            {
                // plc = PLCFactory.GetPLC(ethernet, 0); // <-- No overload for method 'GetPLC' takes '2' arguments

                plc = PLCFactory.GetPLC(ethernet, 0, true); // <-- Add boolean so it will build
                plc.EventAbortCompleted += new PLC.AbortCompletedDelegate(plc_EventAbortCompleted);
                setButtonsEnableState(true);
                PlcVersion version = plc.Version;
                txtModel.Text = version.OPLCModel;
                txtHW.Text = version.HWVersion;
                txtOS.Text = version.OSVersion;
                txtBoot.Text = version.Boot;
                txtBinLib.Text = version.BinLib;
                txtFactoryBoot.Text = version.FactoryBoot;
                try
                {
                    txtPlcName.Text = plc.PlcName;
                }
                catch
                {
                }
            }
            catch (Exception m)
            {
                MessageBox.Show(m.Message);
                setButtonsEnableState(false);
                ethernet.Disconnect();
                System.Windows.Forms.MessageBox.Show("Could not establish a connection to the PLC");
            }
        }

 

This property can be set only once (so you can set it on the program load, instead of setting true on every button click, but I wrote it here just for the example).

Link to comment
Share on other sites

Saragani,

The suggestion you gave worked perfectly.  It is important to note that the setting of PLCFactory.WorkWithXmlInternally = true MUST happen prior to the call to GetPLC.  I had tried setting it inside the try block with no success, but as it appears below, it works perfectly on Windows 10 build 1607.

Many thanks for your attention.

Kind Regards

Bruce

 

 private void Connect_Click(object sender, EventArgs e)
        {

            PLCFactory.WorkWithXmlInternally = true;
            Ethernet ethernet = new Ethernet("10.10.11.25", 20256, EthProtocol.TCP, 3, 3000);

            try
            {
                plc = PLCFactory.GetPLC(ethernet, 0); // <-- Add boolean so it will build
                plc.EventAbortCompleted += new PLC.AbortCompletedDelegate(plc_EventAbortCompleted);
                setButtonsEnableState(true);
                PlcVersion version = plc.Version;
                txtModel.Text = version.OPLCModel;
                txtHW.Text = version.HWVersion;
                txtOS.Text = version.OSVersion;
                txtBoot.Text = version.Boot;
                txtBinLib.Text = version.BinLib;
                txtFactoryBoot.Text = version.FactoryBoot;
                try
                {
                    txtPlcName.Text = plc.PlcName;
                }
                catch
                {
                }
            }
            catch (Exception m)
            {
                MessageBox.Show(m.Message);
                setButtonsEnableState(false);
                ethernet.Disconnect();
                System.Windows.Forms.MessageBox.Show("Could not establish a connection to the PLC");
            }
        }

 

Link to comment
Share on other sites

  • 1 year later...
On 3/6/2016 at 7:18 AM, Saragani said:

Hi, this could also be a UAC / Permission issues, since the communication dll is trying to extract an xml file.

You could make the dll not extract the dll, and use it in RAM, by:

 

PLCFactory.WorkWithXmlInternally = true;

 

(Do this just once, when the application starts).

 

 

Tell me if it helps. If not, when you can debug the code (the exception you see hides the actual error. I don't know if it fails dues to timeout or some other issues).

I have this problem.

i show that my problem is a timeout. 

In this case what i do?

thanks

 

Link to comment
Share on other sites

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...