Beispiel #1
0
        internal void GetBlockValue(ref Dictionary <string, Bit> adrList, string mark, int length, bool isHex = false)
        {
            int index = 0;

            int[] buf = new int[length / 16];

            if (length > 0)
            {
                Err = plc.ReadDeviceBlock(mark + "0", length / 16, out buf[0]);
                foreach (int hexBit in buf)
                {
                    string hexBitStr = Convert.ToString(hexBit, 2).PadLeft(16, '0');
                    for (int i = 15; 0 <= i; i--)
                    {
                        string adr = (isHex == false ? index.ToString() : Convert.ToString(index, 16).ToUpper());

                        if (hexBitStr.Substring(i, 1) == "1")
                        {
                            adrList[adr].Value2 = true;
                        }

                        else
                        {
                            adrList[adr].Value2 = false;
                        }

                        index++;
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 软元件的批量读取->连续 (4 字节数据 )
 /// </summary>
 public bool ReadDeviceBlock(string blockName, int size, out int[] lData)
 {
     lock (this)
     {
         lData = new int[size];
         try
         {
             int result = actUtlType.ReadDeviceBlock(blockName, size, out lData[0]);
             if (0 == result)
             {
                 message = "从PLC地址" + blockName + "开始读取" + size + "位成功";
                 return(true);
             }
             else
             {
                 message = "从PLC地址" + blockName + "开始读取" + size + "失败,错误代码:\n" + (uint)result;
                 return(false);
             }
         }
         catch (Exception ex)
         {
             _isOpen = false;
             message = "error:\n" + ex.Message;
             return(false);
         }
         finally
         {
             Console.WriteLine(message);
         }
     }
 }
Beispiel #3
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = " ";
            int output;

            output = 0;
            for (int i = 0; i < 101; i++)
            {
                _PLC.ReadDeviceBlock("D" + i, 1, out output);
                richTextBox1.AppendText(output + "\r\n");
            }
        }