コード例 #1
0
        private void Test1( )
        {
            OperateResult <bool> read = siemensPPI.ReadBool("M100.4");

            if (read.IsSuccess)
            {
                bool m100_4 = read.Content;
            }
            else
            {
                // failed
                string err = read.Message;
            }

            OperateResult write = siemensPPI.Write("M100.4", true);

            if (write.IsSuccess)
            {
                // success
            }
            else
            {
                // failed
                string err = write.Message;
            }
        }
コード例 #2
0
 private void button_read_bool_Click(object sender, EventArgs e)
 {
     // Clipboard.SetText( HslCommunication.BasicFramework.SoftBasic.ByteToHexString( SiemensPPI.BuildReadCommand( 2, textBox3.Text, 1, true ).Content, ' ' ) );
     // 读取bool变量
     if (textBox11.Text == "1")
     {
         DemoUtils.ReadResultRender(siemensPPI.ReadBool(textBox3.Text), textBox3.Text, textBox4);
     }
     else
     {
         DemoUtils.ReadResultRender(siemensPPI.ReadBool(textBox3.Text, ushort.Parse(textBox11.Text)), textBox3.Text, textBox4);
     }
 }
コード例 #3
0
        public override IEnumerable <IOTData> GetData()
        {
            List <IOTData> iOTs = new List <IOTData>();

            foreach (SiemensPPIOverTcpResult 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);
        }