예제 #1
0
파일: Program.cs 프로젝트: yrien30/EEIP.NET
        static void Main(string[] args)
        {
            EEIPClient eeipClient = new EEIPClient();

            eeipClient.IPAddress = "192.168.0.123";
            eeipClient.RegisterSession();
            byte[] response = eeipClient.GetAttributeSingle(0x66, 1, 0x325);
            Console.WriteLine("Current Value Sensor 1: " + (response[1] * 255 + response[0]).ToString());
            response = eeipClient.GetAttributeSingle(0x66, 2, 0x325);
            Console.WriteLine("Current Value Sensor 2: " + (response[1] * 255 + response[0]).ToString());
            Console.WriteLine();
            Console.Write("Enter intensity for Sensor 1 [1..100]");
            int value = int.Parse(Console.ReadLine());

            Console.WriteLine("Set Light intensity Sensor 1 to " + value + "%");
            eeipClient.SetAttributeSingle(0x66, 1, 0x389, new byte [] { (byte)value, 0 });
            Console.Write("Enter intensity for Sensor 2 [1..100]");
            value = int.Parse(Console.ReadLine());
            Console.WriteLine("Set Light intensity Sensor 2 to " + value + "%");
            eeipClient.SetAttributeSingle(0x66, 2, 0x389, new byte[] { (byte)value, 0 });
            Console.WriteLine();
            Console.WriteLine("Read Values from device to approve the value");
            response = eeipClient.GetAttributeSingle(0x66, 1, 0x389);
            Console.WriteLine("Current light Intensity Sensor 1 in %: " + (response[1] * 255 + response[0]).ToString());
            response = eeipClient.GetAttributeSingle(0x66, 2, 0x389);
            Console.WriteLine("Current light Intensity Sensor 2 in %: " + (response[1] * 255 + response[0]).ToString());
            eeipClient.UnRegisterSession();
            Console.ReadKey();
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            EEIPClient eeipClient = new EEIPClient();

            eeipClient.IPAddress = "192.168.255.1";
            eeipClient.RegisterSession();
            int B = 1;

            while (B == 1)
            {
                double value = 0;
                int[]  V2    = { 9876543, 0 };
                byte[] bb    = BitConverter.GetBytes(V2[0]);
                eeipClient.SetAttributeSingle(0x78, 2701, 1, new byte[] { 255 });
                eeipClient.SetAttributeSingle(0x7F, 2, 1, new byte[] { 16, 0, 0, 0 });// set P002 to base type
                //eipClient.SetAttributeSingle(0x7F(P-var), Var no. 2, arrtibute 1, data send new byte[] { 16, 0, 0, 0 });
                // X,Y,Z 0.000
                byte[] A = eeipClient.SetAttributeSingle(0x7F, 2, 6, new byte[] { bb[0], bb[1], bb[2], bb[3] }); // 1st axis IN{BYTE SEND}SEPARATE DOUBLE DATA TO BINARY}
                eeipClient.SetAttributeSingle(0x7F, 2, 7, new byte[] { 15, 39, (byte)value, 0 });                // 2nd axis
                eeipClient.SetAttributeSingle(0x7F, 2, 8, new byte[] { 15, 39, (byte)value, 0 });                // 3rd axis
                // degree is 0.0000
                eeipClient.SetAttributeSingle(0x7F, 2, 9, new byte[] { 15, 39, (byte)value, 0 });                // 4th axis
                eeipClient.SetAttributeSingle(0x7F, 2, 10, new byte[] { 15, 39, (byte)value, 0 });               // 5th axis
                eeipClient.SetAttributeSingle(0x7F, 2, 11, new byte[] { 15, 39, (byte)value, 0 });               // 6th axis
                eeipClient.SetAttributeSingle(0x7A, 2, 1, new byte[] { 255 });                                   //
                byte[] response = eeipClient.GetAttributeSingle(0x78, 2701, 1);
                //byte[] response = eeipClient.GetAttributeSingle(0x78, 1001, 1);
                eeipClient.UnRegisterSession();
                //if (response[0] <= 1)
                //    Environment.Exit(0);
                B = 0;
            }
        }
예제 #3
0
        public virtual void WriteInstance(byte instanceid, DataType dataType, byte[] sendData, bool isString, ushort tcpport = 44818)
        {
            try
            {
                //IPアドレスはフォームで選択したものを使用
                //TCPポートは特に変更していない場合はこれで固定 EEIP.dll内の既定値
                eEIPClient.TCPPort   = tcpport;
                eEIPClient.IPAddress = Encapsulation.CIPIdentityItem.getIPAddress(IpAddressList[0]);
                eEIPClient.RegisterSession();

                //CIPメッセージ Assembly(0x04)を使って引数のInstanceIDのIOの値を読み出す
                //戻り値のバッファサイズはPLC側で設定したタグのサイズとなっているので一定ではない

                byte[] code = eEIPClient.SetAttributeSingle(0x04, instanceid, 0xFFFF, sendData);
                if (code != null)
                {
                    MessageBox.Show(code.ToString());
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                eEIPClient.UnRegisterSession();
            }
        }
예제 #4
0
파일: Host.cs 프로젝트: tonsluis/IPAL
        /// <summary>
        /// Read / Write a string to the string registers.
        /// </summary>
        /// <remarks>
        /// See figure 7-12
        /// </remarks>
        private void ReadWriteStringRegister()
        {
            string writeSting = "Whohoo hihaa";

            byte[] writeReg = new byte[88];

            // Copy the string
            Array.Copy(Encoding.ASCII.GetBytes(writeSting), 0, writeReg, 4, writeSting.Length);
            // Add the length
            Array.Copy(BitConverter.GetBytes(writeSting.Length), writeReg, 4);
            // Write a string.
            _client.SetAttributeSingle(CLASS_REGISTER_STRING, 1, 1, writeReg);

            // Read the string.
            byte[] responseStruct = _client.GetAttributeSingle(CLASS_REGISTER_STRING, 1, 1);
            if (responseStruct.GetUpperBound(0) > 4)
            {
                int    responceLength = BitConverter.ToInt32(responseStruct.Chunk(0, 4), 0);
                string responce       = Encoding.UTF8.GetString(responseStruct, 4, responceLength);
            }
        }
예제 #5
0
 /// <summary>
 /// Sets an Instance of the Assembly Object
 /// </summary>
 /// <param name="instanceNo"> Instance number to be returned</param>
 /// <returns>bytes of the Instance</returns>
 public void setInstance(int instanceNo, byte[] value)
 {
     eeipClient.SetAttributeSingle(4, instanceNo, 3, value);
 }