tx198835
级别: 略有小成
精华主题: 0
发帖数量: 139 个
工控威望: 281 点
下载积分: 555 分
在线时间: 220(小时)
注册时间: 2010-06-26
最后登录: 2024-09-23
查看tx198835的 主题 / 回贴
楼主  发表于: 2019-09-13 04:15
图片:
有做过上位机的朋友吗,请教SQL批量获取M0 256点  D0 256点,该如何做,关键是刷新时间问题
下面我是刚写的思路往各位大神指正:

    /// <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读取的值转换成
        /// </summary>
        /// <param name="M_Ararry">要转换的byte数组</param>
        /// <returns>B00L数组</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重新编辑 ]
yiluzoulaia
级别: 探索解密
精华主题: 0
发帖数量: 20 个
工控威望: 116 点
下载积分: 486 分
在线时间: 164(小时)
注册时间: 2010-10-08
最后登录: 2024-08-20
查看yiluzoulaia的 主题 / 回贴
1楼  发表于: 2021-10-15 13:48
三菱MC协议用C#实现的源码,有需求可以联系我15006163692  微信同号