Jump to content

Recommended Posts

Posted

Hi,

We are using datatables in V570.

Trying to write to the first column in the first table in V570, address 0 – which is a Integer column.

I’m not able to write to it, I Just get an UserInputException (Invalid write values).

I’m able to read the same column, using the same addressing.

What’s wrong with my code?

Public Function WriteTableFeedPlan(ByVal FeedPlanId As Integer)

Dim rw() As ReadWriteRequest = New ReadWriteRequest(0) {}

Dim StartAddress As UInteger = 0

Dim NumberOfBytesToWriteInRow As UShort = 2

Dim NumberOfRowsToWrite As UShort = 1

Dim RowSizeInBytes As UShort = 2

Dim ValueList As New List(Of Byte)

Dim byte1 As Byte = 4

Dim byte2 As Byte = 5

ValueList.Add(byte1)

ValueList.Add(byte2)

rw(0) = New WriteDataTables(StartAddress, NumberOfBytesToWriteInRow, NumberOfBytesToWriteInRow, RowSizeInBytes, ValueList)

Try

plc.ReadWrite(rw)

ethernet.Disconnect()

Catch

ethernet.Disconnect()

Return False

End Try

Return True

End Function

Posted

Dear Fre_ZZe,

Ok, your code has a small bug. Instead of sending the number of rows to write, you send the number of bytes to write in row.

Therefore, you request to write 2 bytes * 2 rows, but supply only 2 bytes. Your code is:

rw(0) = New WriteDataTables(StartAddress, NumberOfBytesToWriteInRow,
NumberOfBytesToWriteInRow
, RowSizeInBytes, ValueList)

while it should have been:

rw(0) = New WriteDataTables(StartAddress, NumberOfBytesToWriteInRow,
NumberOfRowsToWrite
, RowSizeInBytes, ValueList)

On the other hand, why working so hard and failing with such bugs. Why converting the integer value into 2 bytes? What would he do with strings and floats? Why not knowing the structure of the Data Tables and guessing its address?

I can suggest you to use our Unitronics.DataTables.dll, which makes things much easier.

You can read the structure and values of the data tables from the PLC, and also read and write specific cells.

http://www.unitronics.com/Data/Uploads/Dot_NET/Unitronics%20Data%20Table.rar

The rar file contains both DLL and example.

The DLL uses the communication driver, but does all the hard work for you.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.