Jump to content

.net ReadWrite - help!


Marko_marus

Recommended Posts

Hi,

I am new to Unitronics, and I am supposed to write a SCADA application that communicates to Vision 1040 and reads some values.

I need to read 20 float values. Using Ethernet connection, TCP.

The target PC runs Win7 64-bit, I am using VisualStudio 2010, .Net Framework 4.0 Client Profile.

I read "Using the Unitronics Communication Driver for .Net", and examined examples on Unitronics Download section.

I can establish communication with PLC, code:

Ethernet eth;

try

{

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

PLC nasaBeba = PLCFactory.GetPLC(eth, 0);

//nasaBeba.ReadWrite(

}

catch (Exception ex)

{

MessageBox.Show("error: " + ex.Message);

}

What I don't understand is how the PLC.ReadWriteRequest() works.

I am trying to read one float value from address (hex)7000, this is starting value of "float" registers in vision1040 PLC (found this in documentation).

My code:

ReadWriteRequest[] rw = new ReadWriteRequest[1];

rw[0] = new ReadOperands()

{

OperandType = OperandTypes.MF,

NumberOfOperands = 1,

StartAddress = 7001

};

try

{

nasaBeba.ReadWrite(ref rw);

object[] values = (object[])(rw[0].ResponseValues);

label1.Text = values[0].ToString();

}

catch

{

System.Windows.Forms.MessageBox.Show("error");

}

Anyway, I woud like to have some explanation how does PLC.ReadWrite() works, and expecialy how to prepare ReadWriteRequest:

- how to set address? Do I set it in hex values, or do I need to convert to decade value?

- does OperandType determine size of data I am reading?

If I put "OperandType = OperandTypes.MF" doeas it mean that I automatically read size of float with one read?

Any help with ReadWrite() and ReadWriteRequest would be greatly appreciated.

Or if you could just point me to documentation that I need to examine...

Thank you in advance,

Marko

Link to comment
Share on other sites

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

A ReadWrite request can read/write operands, Data Tables, and more.

Basically, when writing or reading the opearand, the start address represents the start address of the first operand you want to read/write. This address is off course in decimal (The StartAddress is an ushort so it can only contain numbers).

If you set the number of operands to be for example 5, then in your example, you will read the values of MF 7000 to 7004

Link to comment
Share on other sites

Thank you for reply, but I do not completely understand plc.ReadWrite()...

If I state:

...

OperandType = OperandTypes.MF,

...

do I automatically start reading Memory Float registers?

In my PLC (Vision 1040), adresses from (hex)7000 ared designated for float variables, so if I state that I want to read MF operand type, do I automatically start reading from (hex)7000?

Or do I need to state:

....

StartAddress = 28672

....

(hex 7000 = dec 28672)

?

Is there no other documentation other than "Unitronics_Communication_Driver_for_Dot_Net.pdf"?

Link to comment
Share on other sites

Hi,

I have another problem. When I read values from PLC, there is some mistake when I try to access value in [0]

My code:

rw[0] = new ReadOperands()

{

OperandType = OperandTypes.MI,

NumberOfOperands = 20,

StartAddress = 1

};

try

{

_plc.ReadWrite(ref rw);

object[] values = (object[])(rw[0].ResponseValues);

Y = Convert.ToDouble(values[0]) / 100.0;

When reading other values (values[1], values[2]...) everything is OK.

What am I doing wrong?

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