Jump to content

C# code examples Drive.NET DataTables


zivk

Recommended Posts

Hi,

The .Net communication driver exposes the same parameters of reading data tables just like the old ActiveX DLL (Num of bytes per row, num of rows to read, start address etc).

However, it becomes difficult if the structure of the data tables in the PLC is unknown to you.

We have another DLL that uses the Communication driver and does all the dirty work for you.

You can find the DLL + an example at:

http://ftp.unitronics.com/Downloads/Tools%20For%20.NET%20Developers/Unitronics%20Data%20Table%20DLL%201.0.0.4.zip

However... the DLLs versions are old so I suggest you to take the latest communication driver and data tables DLL from the SD Card Suite installation.

Link to comment
Share on other sites

Helo

The software on my computer running good but, Why when I run on another computer it gives the error message : "Cannect Comunicatioate with the PLC with the specifide UnitID"

or sometimesI get the error message (I do not know when): Message an attachment

 
       	try
       	{
           	if (plc == null)
           	{
               	Ethernet ethernet = new Ethernet("10.0.0.123", 20256, EthProtocol.TCP, 3, 3000);
               	plc = PLCFactory.GetPLC(ethernet, 0);             		
        		//   Serial serial = new Serial(SerialPortNames.COM1, BaudRate.BR115200, 3, 3000, DataBits.DB8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One);
        		//   plc = PLCFactory.GetPLC(serial, 0);
           	}

           	dataTables = new DataTables(plc, DataTablesReadOptions.StructureAndValues);

           	dataGridView1.DataSource = null;

           	updateTablesListAndGrid();

           	ReadRange.Enabled = true;
           	WriteRange.Enabled = true;
           	ReadTable.Enabled = true;
           	WriteTable.Enabled = true;
           	UpdateTable.Enabled = true;
       	}
       	catch (Exception ex)
       	{
           	MessageBox.Show(ex.Message);
       	}

Files:

Data Tables DLL Example.exe

Unitronics.ComDriver.DLL v1.0.0.33

Unitronics.DataTables.DLL v1.0.0.9

Xceed.Compression.dll

Xceed.Compression.Formats.dll

post-218-060767200 1287407788_thumb.png

Link to comment
Share on other sites

hi

I use a combination of two examples:

1. Unitronics SD Card Explorer Lite User Control 1.0.0.6

2. Unitronics Data Table (Image attachment with DLL files)

Part of the "Unitronics SD Card Explorer" Works correctly

Part of the "Unitronics Data Table" Fails on this line:

dataTables = new DataTables(plc, DataTablesReadOptions.StructureOnly);

Computer working properly with: VisiLogic and Z-View(HMI)

???????

What I'm trying to do is a program that performs automatic backup of tables (from PLC tables or SD-CARD)

Are there any other tools that make the backup?

post-218-034602300 1287601969_thumb.png

Link to comment
Share on other sites

The Xceed DLLs version that unitronics is working with (and have a license to) is 3.7

It seems that you are using xceed version 4.2 which is much newer. The Data Tables DLL is applying the license for version 3.7 so it fails on some computers.

Please use the Xceed DLLs that were supplied by unitronics.

Link to comment
Share on other sites

  • 4 months later...

Hi,

I'm trying to access a Vision 230 PLC using "Reading MIs using Serial Port - C# Example"

I am using Visual Studio 2010 Ultimate" which asked me to update the files when I first opened them, and returned a successful message.

However, when trying to run the example I get the following error when attempting to "Connect to PLC" via the form. (Attached).

You should also know that I'm quite new to C#.

Can you help?

Thanks in advance,

Izhar

Link to comment
Share on other sites

What OS are you working with on your PC?

(Windows XP, Vista, 7?)

Is it 32 Bit or 64 Bit?

Hi,

Thanks for the quick response.

I'm using a 64 bit windows 7 OS.

After playing around with the example I got it to work (I have no idea how...)

Today I'm trying to write my own project using the example.

I created a project (.NET Framework 3.5) and a simple form which attempts to connect to the PLC.

I added the Unitronics dll to the solution explorer -> References -> Browse -> Relevant library and file.

and when I tried to use the plc class, the compiler didn't recognize it.

I assume the problem is with the adding of the dll.

what can I do?

Thanks in advance,

Izhar

Link to comment
Share on other sites

Hi again,

The code now recognizes the plc (after playing with the plc declaration in the beginning.

Now my problem is that the project doesn't build, because the program can't find the output file.

I checked that the path and assembly names are correct (clearly they are correct, they had been defined by automatically),

but it gives an error saying it doesn't exist...

Thanks again for your help,

Izhar

Link to comment
Share on other sites

Hi, the Sourcecode / DLL might be compiled as 32Bit and your program as "Any CPU" which might cause problems, so please check that both of them are compiled to the same CPU type (Any CPU is usually the best)

Without seeing your project I can't actually guess what the problem can be.

Can you post a screenshot?

Link to comment
Share on other sites

Hi Saragani,

When I open the Unitronics.ComDriver.dll it shows that it's compiled as 32 bit but I can't figure out how to build it as an "any CPU" type.

My program is indeed compiled as "any CPU".

I also added the error I get when trying to build what I had written so far and the screen-shot with the error description in the bottom.

Thanks again for all your help,

Izhar

Link to comment
Share on other sites

Hi,

I was finally able to solve the problem.

Turns out it wasn't connected to the dll at all.

The problem was a bug with the resgen.exe file for windows 7 x64 OS.

I "solved" it by changing my program to .NET 4.

Other solutions may be found in

http://social.msdn.microsoft.com/Forums/en/msbuild/thread/e5900710-9849-4d10-aa28-48b734d06bf2

Thanks again for all your help Saragani,

Izhar

Link to comment
Share on other sites

Hello again,

I continued writing my program, using "Unitronics Data Tables" as a guideline.

I came to the part where I wanted to update an existing cell in my PLC.

I tried both the "update" function and the "write" function, from the original Unitronics program but for some reason, the function finishes it's run successfully but the data is not updated when I try to "read" it afterwards - what I get is the unchanged data from before the writing attempt.

I added the original code for a general write:

private void WriteTable_Click(object sender, EventArgs e)
       {
           try
           {
               dataTables.Tables[listTables.Text].Write();
               reloadCellsData(dataTables.Tables[listTables.Text]);
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

What am I doing wrong?

Thanks in advance,

Izhar

Link to comment
Share on other sites

Hi, your code is right, either using Write or Update will update the content on the PLC.

However, what about updating the cells values on the PC?

You are using reloadCellsData to load the cells data into the UI (Probably a grid)... Are you sure that editing the UI makes the changes back to the cells in the Data Tables DLL?

(Maybe you are just changing the UI?)

Link to comment
Share on other sites

Hi, your code is right, either using Write or Update will update the content on the PLC.

However, what about updating the cells values on the PC?

You are using reloadCellsData to load the cells data into the UI (Probably a grid)... Are you sure that editing the UI makes the changes back to the cells in the Data Tables DLL?

(Maybe you are just changing the UI?)

Hi,

What I did before attempting to write my own code, was play around with the code I downloaded from this forum (Unitronics Data Tables)

That's the code I added in the previous response, just as a reference.

Bottom line, when I change some arbitrary data in the EditCell screen, I can save the changed table to a file, see it changed in the UI etc.

Even when I try to update it to the PLC, the compiler goes through the process OK.

How can I see whether I'm actually changing anything or just saving data to the UI?

Thanks,

Izhar

Link to comment
Share on other sites

Hi,

Here is the original code I have been working on (downloaded from this forum)

http://ftp.unitronic...L%201.0.0.4.zip

Actions I had taken so the code would run:

1. convert the project to be compatible with Visual Studio 2010

2. Change project to be .NET Framework 4 (otherwise it doesn't work)

3. Change UnitID of the Form1 file to be 11 (my UnitID), in both read structure and read structure and values commands.

4. F5

5. Press on "Read Structures & Values from PLC" (the data appears in the grid)

6. double click an arbitrary value (the update popup appears)

7. Change the value -> OK

8. update changes / write tables to PLC

9. read range

The updated changes do not appear no matter what...

Thanks in advance,

Izhar

Link to comment
Share on other sites

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...