private void button_read_long_Click(object sender, EventArgs e) { // 读取long变量 if (textBox1.Text == "1") { DemoUtils.ReadResultRender(siemensPPI.ReadInt64(textBox3.Text), textBox3.Text, textBox4); } else { DemoUtils.ReadResultRender(siemensPPI.ReadInt64(textBox3.Text, ushort.Parse(textBox1.Text)), textBox3.Text, textBox4); } }
private void Test3() { // 读取操作,这里的M100可以替换成I100,Q100,DB20.100效果时一样的 bool M100_7 = siemensPPI.ReadBool("M100.7").Content; // 读取M100.7是否通断,注意M100.0等同于M100 byte byte_M100 = siemensPPI.ReadByte("M100").Content; // 读取M100的值 short short_M100 = siemensPPI.ReadInt16("M100").Content; // 读取M100-M101组成的字 ushort ushort_M100 = siemensPPI.ReadUInt16("M100").Content; // 读取M100-M101组成的无符号的值 int int_M100 = siemensPPI.ReadInt32("M100").Content; // 读取M100-M103组成的有符号的数据 uint uint_M100 = siemensPPI.ReadUInt32("M100").Content; // 读取M100-M103组成的无符号的值 float float_M100 = siemensPPI.ReadFloat("M100").Content; // 读取M100-M103组成的单精度值 long long_M100 = siemensPPI.ReadInt64("M100").Content; // 读取M100-M107组成的大数据值 ulong ulong_M100 = siemensPPI.ReadUInt64("M100").Content; // 读取M100-M107组成的无符号大数据 double double_M100 = siemensPPI.ReadDouble("M100").Content; // 读取M100-M107组成的双精度值 string str_M100 = siemensPPI.ReadString("M100", 10).Content; // 读取M100-M109组成的ASCII字符串数据 // 写入操作,这里的M100可以替换成I100,Q100,DB20.100效果时一样的 siemensPPI.Write("M100.7", true); // 写位,注意M100.0等同于M100 siemensPPI.Write("M100", (short)(byte)0x33); // 写单个字节 siemensPPI.Write("M100", (short)12345); // 写双字节有符号 siemensPPI.Write("M100", (ushort)45678); // 写双字节无符号 siemensPPI.Write("M100", 123456789); // 写双字有符号 siemensPPI.Write("M100", (uint)3456789123); // 写双字无符号 siemensPPI.Write("M100", 123.456f); // 写单精度 siemensPPI.Write("M100", 1234556434534545L); // 写大整数有符号 siemensPPI.Write("M100", 523434234234343UL); // 写大整数无符号 siemensPPI.Write("M100", 123.456d); // 写双精度 siemensPPI.Write("M100", "K123456789"); // 写ASCII字符串 OperateResult <byte[]> read = siemensPPI.Read("M100", 10); { if (read.IsSuccess) { byte m100 = read.Content[0]; byte m101 = read.Content[1]; byte m102 = read.Content[2]; byte m103 = read.Content[3]; byte m104 = read.Content[4]; byte m105 = read.Content[5]; byte m106 = read.Content[6]; byte m107 = read.Content[7]; byte m108 = read.Content[8]; byte m109 = read.Content[9]; } else { // 发生了异常 } } }
private void button_read_long_Click(object sender, EventArgs e) { // 读取long变量 DemoUtils.ReadResultRender(siemensPPI.ReadInt64(textBox3.Text), textBox3.Text, textBox4); }
public override IEnumerable <IOTData> GetData() { List <IOTData> iOTs = new List <IOTData>(); foreach (SiemensMPIResult result in DriveConfig.Results) { try { string sResult; switch (result.DataType.ToUpper()) { case "BOOL": sResult = siemensPPI.ReadBool(result.DB).Content.ToString(); break; case "STRING": sResult = siemensPPI.ReadString(result.DB, Convert.ToUInt16(result.Len)).Content; break; case "INT": sResult = siemensPPI.ReadInt32(result.DB).Content.ToString(); break; case "FLOAT": sResult = siemensPPI.ReadFloat(result.DB).Content.ToString(result.Format); break; case "DOUBLE": sResult = siemensPPI.ReadDouble(result.DB).Content.ToString(result.Format); break; case "BYTE": sResult = siemensPPI.ReadByte(result.DB).Content.ToString(); break; case "SHORT": sResult = siemensPPI.ReadInt16(result.DB).Content.ToString(); break; case "USHORT": sResult = siemensPPI.ReadUInt16(result.DB).Content.ToString(); break; case "UINT": sResult = siemensPPI.ReadUInt32(result.DB).Content.ToString(); break; case "LONG": sResult = siemensPPI.ReadInt64(result.DB).Content.ToString(); break; case "ULONG": sResult = siemensPPI.ReadUInt64(result.DB).Content.ToString(); break; default: sResult = siemensPPI.ReadString(result.DB, 1).Content; break; } iOTs.Add(new IOTData { DataCode = result.Address, DataValue = sResult, DataName = result.Name, DriveCode = DriveConfig.DriveCode, DriveType = DriveConfig.DriveType, GTime = DateTime.Now, Unit = result.Unit }); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } return(iOTs); }