图片:
有做过上位机的朋友吗,请教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重新编辑 ]