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(); }
/// <summary> /// Read Position register according Table 7-22 /// </summary> private void ReadWritePositionRegister() { byte[] xPosBytes = new byte[4]; byte[] response = _client.GetAttributeSingle(0x7c, 1, 1); Array.Copy(response, 4, xPosBytes, 0, 4); Array.Reverse(xPosBytes); float posX = BitConverter.ToSingle(xPosBytes, 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; } }
/// <summary> /// Explicit Massaging サービスを使ってPLCからデータを呼び出します。 /// </summary> /// <param name="dataareaID">更新するデータエリア番号</param> /// <param name="instanceid">インスタンスID</param> /// <param name="dataType">データ型</param> /// <param name="isString">入力データが文字列の場合true</param> /// <param name="tcpport">TCPポート</param> /// <param name="destination">宛先IPアドレス番号</param> /// <return>EIP_Status構造体を返します</return> public virtual EIP_Status ReadInstance(byte instanceid, DataType dataType, bool isString, bool isBCD, ushort tcpport = 44818, int destination = 0) { EIP_Status status = new EIP_Status { code = 0, message = "" }; try { //IPアドレスはフォームで選択したものを使用 //TCPポートは特に変更していない場合はこれで固定 EEIP.dll内の既定値 eEIPClient.TCPPort = tcpport; eEIPClient.IPAddress = Encapsulation.CIPIdentityItem.getIPAddress(IpAddressList[destination]); eEIPClient.RegisterSession(); //CIPメッセージ Assembly(0x04)を使って引数のInstanceIDのIOの値を読み出す //戻り値のバッファサイズはPLC側で設定したタグのサイズとなっているので一定ではない byte[] response = eEIPClient.GetAttributeSingle(0x04, instanceid, 0x03); string responseString = ""; //送られてきたデータが数値の場合 //HEX→DEC変換して格納 if ((dataType == DataType.DM || dataType == DataType.EM) && !isString && !isBCD) { int n = 0; int tmpvalue = 0; foreach (byte resAddress in response) { tmpvalue += resAddress * (int)Math.Pow(16, 2 * n); n++; } responseString = tmpvalue.ToString(); status.value = responseString; } else if (isBCD) { string tmpvalue = ""; foreach (byte resAddress in response) { if (resAddress > 0) { tmpvalue = (resAddress / 16).ToString() + (resAddress % 16).ToString(); } } responseString = tmpvalue.ToString(); status.value = responseString; } //送られてきたデータが文字列の場合 //リトルエンディアンのため上位バイトは i + 1 に格納されている if ((dataType == DataType.DM || dataType == DataType.EM) && isString) { for (int i = 0; i < response.Length - 1; i++) { if (response[i] != 0x32) { responseString += (char)response[i + 1]; responseString += (char)response[i]; i++; } else { break; } } status.value = responseString; } //ビット形式はとりあえず何もしない if (dataType == DataType.R || dataType == DataType.L || dataType == DataType.X || dataType == DataType.Y) { } //戻り値を作る status.code = 0; status.response = response; } catch (Exception e) { status.code = -1; status.message = e.Message; status.response = null; } return(status); }
/// <summary> /// Reads the Instance of the Assembly Object (Instance 101 returns the bytes of the class ID 101) /// </summary> /// <param name="instanceNo"> Instance number to be returned</param> /// <returns>bytes of the Instance</returns> public byte[] getInstance(int instanceNo) { byte[] byteArray = eeipClient.GetAttributeSingle(4, instanceNo, 3); return(byteArray); }