Jump to content

C# code examples Drive.NET DataTables


zivk

Recommended Posts

Hi, since I don't know your Data tables structure, I can't search for the problem.

I have tested the code using the instructions you wrote (upgradring the project to VS 2010 and changing the framework to 4.0) and it still works.

However, the version on the website is kinda old. We have since then updated our .Net communication driver and also fixed several bugs in the Data Tables DLLs.

I'm attaching the newest versions of those dlls.

Please try them with your example and PLC Project and see if it makes any difference. If that doesn't help, then please send me your VLP (it can be attached to the forum).

Unitronics.DataTables.zip

Link to comment
Share on other sites

Hello Saragani,

I had no more space left for uploads so I deleted my previous uploads. I hope that's OK.

I tried the new dll's you sent me and sadly they did not work.

After you brought up the vlp issue I decided it might be a good idea to download the program to the PLC once again (From the Visilogic program).

What I got was an error (attached screen).

I added the code also.

Thank you,

Izhar

my_main_1_19.vlp

post-1292-096783300 1300276530_thumb.jpg

Link to comment
Share on other sites

I can't reproduce the download error you got, but try setting the timeout to a higher value.

Furthermore, I do see that values that I write to the data tables disappear... but it is not a bug with the data tables DLL.

Your Ladder code has "DT Write Row", "DT Clear Row", "DT Clear Col" etc...

Your Ladder code keeps altering the data on the cells, so after you change it by the DataTables.DLL, it keeps getting back to the old value because of the ladder code.

If you put your PLC in Stop-Mode then the .Net example should work fine.

Link to comment
Share on other sites

I can't reproduce the download error you got, but try setting the timeout to a higher value.

Furthermore, I do see that values that I write to the data tables disappear... but it is not a bug with the data tables DLL.

Your Ladder code has "DT Write Row", "DT Clear Row", "DT Clear Col" etc...

Your Ladder code keeps altering the data on the cells, so after you change it by the DataTables.DLL, it keeps getting back to the old value because of the ladder code.

If you put your PLC in Stop-Mode then the .Net example should work fine.

Hi,

I put the PLC in stop mode and the code works fine now.

What exactly does that mean?

when the PLC is in stop mode, is the ladder code neutralized?

Thanks,

Happy Purim,

Izhar

Link to comment
Share on other sites

Hi,

The Stop-Mode works for the data writing, I simply added "plc.Stop();" whenever I attempt to write something to the PLC.

The problem is that when I run the debugger again, the updated cell returns to the original value, so that's not very useful.

What can I do to actually keep the new data in the PLC dataTable?

Another issue I have is with saving table rows as strings.

When I access a table, I run through the columns in each row and try to save the values as one string separated by commas.

I keep getting stuck with returning the string.

could you please write a few lines of code to do that?

Thanks in advance,

Izhar

Link to comment
Share on other sites

Yes, when you put your PLC in stop, both HMI and Ladder doesn't run.

If your ladder code clears or overwrite the content of the Data tables (and it keeps doing it while the ladder is running).

Here is an example of showing the values of a row in a messagebox

           StringBuilder sb = new StringBuilder();
           foreach (var cell in dataTables.Tables[0].Rows[0].Cells)
           {
               sb.Append(cell.Fields[0].Value.ToString());
               sb.Append(",");
           }
           MessageBox.Show(sb.ToString());

this code will show only the first value of each cell (Which is good in most cases... but sometimes you have an array of values in some cells).

This code will show the values of all the cells in the row:

           StringBuilder sb = new StringBuilder();
           foreach (var cell in dataTables.Tables[0].Rows[5].Cells)
           {
               foreach (var field in cell.Fields)
               {
                   sb.Append(field.Value.ToString());
                   sb.Append(",");
               }
           }
           MessageBox.Show(sb.ToString());

Link to comment
Share on other sites

  • 3 months later...

Question for Saragani:

We are using v530 for our project, data table is large (1000 rows * 29 bytes). When I use your primer Data Tables DLL example, function for reading table structures and values works fine (acquire structure and data within 2 sec), but when I try to change anything and write back, application hang. Writing to data table succeed, but we have to end application and restart it again. Communication is trough Ethernet. I have latest dll versions (comm driver and datatables). Functions ReadRange, WriteRange, ReadTable, WriteTable, UpdateTable works all in same unacceptable manner. Any idea?

Thnx

Marijan

Link to comment
Share on other sites

As much as I remember, that example is not using thread for reading/writing the data table in background so until it finishes with the write, the application hangs.

The write itself should finish sometime, but if it doesn't then it means that there is a bug that causes it to stuck in an infinite loop.

Please post your Communication Driver and Data Tables DLLs version so I will at least know which versions you have (I'm not sure that the versions on the website are not the latest ones even though I've asked to upload them several times.

There is a chance that the versions you have, have a bug that was already fixed which might cause the problem you describe.

So:

1) Please post your current DLLs versions

2) Please download the latest SD Card Suite (this is indeed the latest version) from out website and take the Communication Driver and the Data Tables DLLs from it (Which are currently the latest) and try again with the example you have... Then report back if it works (Make sure that the example is actually working with the new dlls)

3) If it still doesn't work, then Post your VLP. It might be the only way for us to figure out why it fails for you.

Thanks.

Link to comment
Share on other sites

As much as I remember, that example is not using thread for reading/writing the data table in background so until it finishes with the write, the application hangs.

The write itself should finish sometime, but if it doesn't then it means that there is a bug that causes it to stuck in an infinite loop.

Please post your Communication Driver and Data Tables DLLs version so I will at least know which versions you have (I'm not sure that the versions on the website are not the latest ones even though I've asked to upload them several times.

There is a chance that the versions you have, have a bug that was already fixed which might cause the problem you describe.

So:

1) Please post your current DLLs versions

2) Please download the latest SD Card Suite (this is indeed the latest version) from out website and take the Communication Driver and the Data Tables DLLs from it (Which are currently the latest) and try again with the example you have... Then report back if it works (Make sure that the example is actually working with the new dlls)

3) If it still doesn't work, then Post your VLP. It might be the only way for us to figure out why it fails for you.

Thanks.

Thank you for fast response!

I use this file versions: (attached below)

New version of SD Cards suite is already installed on my PC. I have to add something to my previous post. Application finished writing after all successful, but after approx. 10 minutes which is unacceptable to us. PLC program is writing to data table at same time as PC program, as we are using data table as interface for exchange data between PC - v530 (v530 is leading process dynamically following changes from PC), and between v530 and v1040 over modbus (v1040 is HMI in this application).

If it is not possible to use code from your example in our application, please suggest us the way to do the exchange. We are thinking of exchange row by row through MI i MB sync. (only v530 approach data table in that way).

Thnx

post-367-026658600 1308911378_thumb.jpg

Link to comment
Share on other sites

10 minutes??!

That's an average of like 50 bytes per second.

If you are writing the whole table (and assuming you have only 1 table) then the time to read structure and values should be similar to the time to write the whole table data...

Since you did not complain about reading from the table, then I assume that it is fast. How much time it takes to read the whole structure and values?

What connection you use for connecting the PLC? (Not GPRS, right?)

With Serial Connection at 115,200 it should take about 6 seconds.

With Ethernet it should take less (Maybe a half of the time it takes on Serial port).

Is there any chance of attaching your VLP?

If you are afraid of posting it public, can you at least send it to our Support while asking to forward it to me?

Then I'll be able to check it first thing on Sunday morning when I get back to work. (So it is best if you attach it, since then I don't need to wait for our support to forward the mail).

10x

Link to comment
Share on other sites

mskoda,

Please help me to help you... I need that VLP

Be patient, please, we are commissioning right now, so I'm unable to send you vlp file. Answer to your previous questions: we are using Ethernet connection, and reading complete structure and data from data table works fine, within 2-3 seconds, which is acceptable. We choose to write to data table from PC program trough MI and MB sync. I even tried to write to data table from your application with plc stopped, but no change, still 10 minutes to update or write, so we quit on that approach. Problem doesn't appear on smaller data tables, only on large one. (1000 records, string(20), string(10), string(10), int,int,int,int, string(4)).

Regards

Marijan

Link to comment
Share on other sites

Hi, there is nothing wrong in the Communication Driver, nor in the Unitronics Data Tables.

The example we supply is just an example for showing how to use the APIs on the Communication Driver and the Data Tables DLLs. It is definitely should not be used as an example of good .Net programming practice and certainly not as a software you use in production.

The actual problem is with in the reloadCellsData function, which refreshes the DataGridView after each time you read or write the table again. Since the DataGrid is already bound do a .Net DataTable, then updating cells in that DataTable costs time (since it is also causing the UI to update).

Changing that function to the following (adding the bold lines) will solve your problem:

private void reloadCellsData(Table table)

{

int colIndex;

int rowIndex;

int colsCount = table.Columns.Count();

dataGridView1.SuspendLayout();

dataGridView1.DataSource = null;

for (int i = 0; i < table.Cells.Count(); i++)

{

colIndex = i % colsCount;

rowIndex = i / colsCount;

Cell cell = table.Cells[rowIndex, colIndex];

string cellText = getStringValueFromField(cell.Fields[0], table, colIndex);

for (int j = 1; j < cell.Fields.Count(); j++)

{

cellText += ";" + getStringValueFromField(cell.Fields[j], table, colIndex);

}

m_DataTable.Rows[rowIndex][colIndex] = cellText;

}

dataGridView1.DataSource = m_DataTable;

dataGridView1.ResumeLayout();

}

Btw, instead of using a crappy Data Grid from Microsoft, you can use a 3rd party Grid with much better performance (like we use in the Data Tables Editor) like Infragistics, Xceed, SyncFusion etc...

Obviously we can't supply this 3rd party grid in our examples, since it will require us to supply the License... which we can't.

10x for your feedback.

Link to comment
Share on other sites

Hi, there is nothing wrong in the Communication Driver, nor in the Unitronics Data Tables.

The example we supply is just an example for showing how to use the APIs on the Communication Driver and the Data Tables DLLs. It is definitely should not be used as an example of good .Net programming practice and certainly not as a software you use in production.

The actual problem is with in the reloadCellsData function, which refreshes the DataGridView after each time you read or write the table again. Since the DataGrid is already bound do a .Net DataTable, then updating cells in that DataTable costs time (since it is also causing the UI to update).

Changing that function to the following (adding the bold lines) will solve your problem:

private void reloadCellsData(Table table)

{

int colIndex;

int rowIndex;

int colsCount = table.Columns.Count();

dataGridView1.SuspendLayout();

dataGridView1.DataSource = null;

for (int i = 0; i < table.Cells.Count(); i++)

{

colIndex = i % colsCount;

rowIndex = i / colsCount;

Cell cell = table.Cells[rowIndex, colIndex];

string cellText = getStringValueFromField(cell.Fields[0], table, colIndex);

for (int j = 1; j < cell.Fields.Count(); j++)

{

cellText += ";" + getStringValueFromField(cell.Fields[j], table, colIndex);

}

m_DataTable.Rows[rowIndex][colIndex] = cellText;

}

dataGridView1.DataSource = m_DataTable;

dataGridView1.ResumeLayout();

}

Btw, instead of using a crappy Data Grid from Microsoft, you can use a 3rd party Grid with much better performance (like we use in the Data Tables Editor) like Infragistics, Xceed, SyncFusion etc...

Obviously we can't supply this 3rd party grid in our examples, since it will require us to supply the License... which we can't.

10x for your feedback.

Thank you for helping me with this solution, I'll try to check if this solve my problem later in the afternoon, we are on site now, and have some other problems... :-) Yes, I agree about DataGrid from Msoft, we use DevExpress components for our development. I will send you vlp and upd when I return to the office, that should be on Friday, so until then I will only check if solution that you found works for me and post it here!

Good day & thanks once more

Marijan

EDIT

It works! Thanks a lot! Is there any documentation regarding Unitronics.Comdriver and Unitronics.DataTable assemblies? It would be helpful to have that.

Link to comment
Share on other sites

http://www.unitronics.com/Data/Uploads/communication/Unitronics_Communication_Driver_for_Dot_Net.pdf

(It was not updated for a long time, but it still valid).

About the Data Tables DLL, the example shows most of the APIs. There is a PDF somewhere (I think in the CD).

It is also located at:

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

In there, there is a file called: Unitronics Data Tables DLL.doc

Link to comment
Share on other sites

http://www.unitronic...for_Dot_Net.pdf

(It was not updated for a long time, but it still valid).

About the Data Tables DLL, the example shows most of the APIs. There is a PDF somewhere (I think in the CD).

It is also located at:

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

In there, there is a file called: Unitronics Data Tables DLL.doc

Thank you, I have this files already, i thought there are some more detail documentation, but we have to accept it as is.. :-)

One question for you or other staff: any plans for development KNX or EIB protocol, your v1040 & v1210 seem to be very suitable for home automation systems.

Marijan

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

I've been using the DotNet DataTables interface successfully for a couple of months in a C# application. Recently I upgraded from Visual Studio 2008 to VS2010. The DataTables interface works fine in development mode but when I build and run an executable the connection to the PLC (Vision570) fails because of the Xceed.Compression.dll Licence Key. Reverting to VS2008 solves the problem.

Will you be updating the Xceed components to support VS2010?

Link to comment
Share on other sites

Wow, it's old...

I see that the latest version isn't posted on the Download section, but you can get it from the SD Card Suite:

http://www.unitronics.com/Data/Uploads/software%20utilities/Unitronics%20SD%20Card%20Suite%202.0.43.zip

The SD Card Suite contains the most recent version of both Unitronics.ComDriver.dll and Unitronics.DataTables.dll (the xceed dlls remained untouched).

Link to comment
Share on other sites

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