Marko_marus Posted March 7, 2013 Report Share Posted March 7, 2013 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 Quote Link to comment Share on other sites More sharing options...
Saragani Posted March 7, 2013 Report Share Posted March 7, 2013 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 Quote Link to comment Share on other sites More sharing options...
Marko_marus Posted March 11, 2013 Author Report Share Posted March 11, 2013 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"? Quote Link to comment Share on other sites More sharing options...
Saragani Posted March 11, 2013 Report Share Posted March 11, 2013 You need to give the address in decimal (meaning 28672), but the Memory Float operands in Visilogic/ V1040 are MF0 to MF63 (there isn't any MF7000), So you need to give it a number from 0 to 63. I think that the 7000 hex address that you are talking about it for ModBUS. Quote Link to comment Share on other sites More sharing options...
Marko_marus Posted March 11, 2013 Author Report Share Posted March 11, 2013 Thank you for reply, it is much appreciated. Quote Link to comment Share on other sites More sharing options...
Marko_marus Posted March 12, 2013 Author Report Share Posted March 12, 2013 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? Quote Link to comment Share on other sites More sharing options...
Saragani Posted March 13, 2013 Report Share Posted March 13, 2013 It is working fine here. What do you mean by mistake? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.