引用
引用第8樓flyfeky于2021-01-12 15:13發(fā)表的  :
你好。 我目前也在做此項(xiàng)目。  倍福的ADS通信  .  批量的讀寫數(shù)據(jù)(幾千個(gè)變量),有什么思路嗎   盼回。
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using TwinCAT.Ads;//twincat安裝目錄中有 
using System.IO; 
namespace HmiAdsTest 
{ 
    public partial class MainForm : Form 
    { 
        public MainForm() 
        { 
            InitializeComponent(); 
        } 
        public static TcAdsClient tcAdsClient;//建立通訊 
        private int handle; 
        private void button1_Click(object sender, EventArgs e) 
        { 
            tcAdsClient = new TcAdsClient();//實(shí)例化 
            //tcAdsClient.Connect(851);//同一臺(tái)機(jī)器上使用 
            tcAdsClient.Connect("169.254.71.120.1.1", 851);//amsNetID  851是twincat3 端口號(hào) 
            try 
            { 
                //handle = tcAdsClient.CreateVariableHandle("IOs.ConnectSucceed"); 
                handle = tcAdsClient.CreateVariableHandle("IOs.Dog"); 
                MainForm.VariableAssignment.ConnectSucceed = (bool)(tcAdsClient.ReadAny(handle, typeof(bool))); 
                tcAdsClient.DeleteVariableHandle(handle); 
            } 
            catch 
            { 
                MainForm.VariableAssignment.ConnectSucceed = false; 
                MessageBox.Show("未能連接網(wǎng)絡(luò)"); 
            } 
            if (MainForm.VariableAssignment.ConnectSucceed) 
            {               
                MessageBox.Show("成功連接網(wǎng)絡(luò)"); 
                button1.BackColor = Color.Green; 
            } 
            else { timerReadPeriod.Enabled = false; }           
        }           
        public class VariableAssignment 
        { 
            public static bool ConnectSucceed; 
            public static int AO_ProportionalValve2Dint; 
        } 
        private void numericUpDown1_ValueChanged(object sender, EventArgs e) 
        { 
            handle = tcAdsClient.CreateVariableHandle("IOs.AO_ProportionalValve2Dint"); 
            tcAdsClient.WriteAny(handle, (int)numericUpDown1.Value); 
            tcAdsClient.DeleteVariableHandle(handle);              
        } 
} 
}
這個(gè)答案你滿意嗎