tx198835
級(jí)別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 140 個(gè)
工控威望: 282 點(diǎn)
下載積分: 557 分
在線時(shí)間: 220(小時(shí))
注冊(cè)時(shí)間: 2010-06-26
最后登錄: 2024-12-22
查看tx198835的 主題 / 回貼
樓主  發(fā)表于: 2019-09-13 04:15
圖片:
有做過上位機(jī)的朋友嗎,請(qǐng)教SQL批量獲取M0 256點(diǎn)  D0 256點(diǎn),該如何做,關(guān)鍵是刷新時(shí)間問題
下面我是剛寫的思路往各位大神指正:

    /// <summary>
        /// Act控件初始化
       /// </summary>
        public Form1()
        {
            InitializeComponent();
            axActUtlType1.ActLogicalStationNumber = 10;
            axActUtlType1.ActPassword = "";
        }

// 按鈕獲取值
    private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            short[] M_Memory = new short[16];
            axActUtlType1.Open();
            axActUtlType1.ReadDeviceBlock2("m0", 256, out M_Memory[0]);
            for (int i = 0; i < 256; i++)
            {

                if (Mitsubishi.Mitsubishi_M_Memory(M_Memory) == true)
                {
                    textBox1.AppendText("M" + i + "= 1  ");
                }
                else
                {
                    textBox1.AppendText("M" + i + "= 0  ");
                }
            }
        }



        /// <summary>
        /// mx compoment讀取的值轉(zhuǎn)換成
        /// </summary>
        /// <param name="M_Ararry">要轉(zhuǎn)換的byte數(shù)組</param>
        /// <returns>B00L數(shù)組</returns>
        public static bool[] Mitsubishi_M_Memory(short[] M_Memory)
        {          
            int a = 0;
            bool[] b = new bool[256];
            for (int j = 0; j < M_Memory.Length; j++)
            {
                for (int i = 0; i < 16; i++)
                {
                    if ((0x01 & M_Memory[j] >> i) == 1)
                    {
                        b[a] = true;
                        a++;
                    }
                    else
                    {
                        b[a] = false;
                        a++;
                    }
                }
            }
            return b;
        }
[ 此帖被tx198835在2019-09-13 04:23重新編輯 ]
天語愿
級(jí)別: 家園?
精華主題: 0
發(fā)帖數(shù)量: 58 個(gè)
工控威望: 525 點(diǎn)
下載積分: 744 分
在線時(shí)間: 56(小時(shí))
注冊(cè)時(shí)間: 2016-02-22
最后登錄: 2024-09-10
查看天語愿的 主題 / 回貼
1樓  發(fā)表于: 2019-10-25 17:06
不停讀取刷新,建議添加計(jì)時(shí)控件