圖片:
有做過(guò)上位機(jī)的朋友嗎,請(qǐng)教SQL批量獲取M0 256點(diǎn) D0 256點(diǎn),該如何做,關(guān)鍵是刷新時(shí)間問(wèn)題
下面我是剛寫的思路往各位大神指正:
/// <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重新編輯 ]