public void TestMethod() { var deviceHdl = new SNetDvcSensorHandler(); deviceHdl.Config = new SNetDvcSensorCfg() { RemoteUri = "tcp://192.168.123.201:5000", TxInterval = 0, //IsActivelyTx = true, TimeoutResponse = 5000, ProtoConnect = SNetEnumProtoConnect.Rs232, ProtoFormat = SNetEnumProtoFormat.SNetCmd, ProtoSession = SNetEnumProtoSession.SNetCmd, }; deviceHdl.Config.SignalCfgList.Add(new SNetSignalTransCfg() { Svid = 0, }); deviceHdl.EhSignalCapture += (sender, ea) => { fs.Write(ea); }; using (deviceHdl) { deviceHdl.CfInit(); deviceHdl.CfLoad(); deviceHdl.CfRunLoop(); deviceHdl.CfUnLoad(); deviceHdl.CfFree(); System.Threading.Thread.Sleep(100); } }
public void TestMethod() { CtkLog.RegisterEveryLogWrite((ss, ee) => { System.Diagnostics.Debug.WriteLine(ee.Message); }); var deviceHdl = new SNetDvcSensorHandler(); deviceHdl.Config = new SNetDvcSensorCfg() { RemoteUri = "tcp://192.168.123.201:5000", TxInterval = 0, TimeoutResponse = 5000, ProtoConnect = SNetEnumProtoConnect.Tcp, ProtoFormat = SNetEnumProtoFormat.SNetCmd, ProtoSession = SNetEnumProtoSession.SNetCmd, SignalTran = SNetEnumSignalTrans.SNetCmd, }; for (var idx = 0; idx < 8; idx++) { deviceHdl.Config.SignalCfgList.Add(new SNetSignalTransCfg() { Svid = 0x00010000 + 0x0100 * (ulong)idx, //Svid = 0x00000000, }); } for (var idx = 0; idx < 8; idx++) { deviceHdl.Config.SignalCfgList.Add(new SNetSignalTransCfg() { Svid = 0x00020000 + 0x0100 * (ulong)idx, //Svid = 0x00000000, }); } deviceHdl.EhSignalCapture += (sender, ea) => { fs.Write(ea); //if (ea.Data.Count > 0) //System.Diagnostics.Debug.WriteLine("{0}={1}", ea.Svid, ea.Data[0]); }; using (deviceHdl) { deviceHdl.CfInit(); deviceHdl.CfLoad(); deviceHdl.CfRunLoop(); deviceHdl.CfUnLoad(); deviceHdl.CfFree(); System.Threading.Thread.Sleep(100); } }
public void TestMethod() { //設定旗標 var startDt = DateTime.Now; var isFinishDevice = false; var deviceHdl = new SNetDvcSensorHandler(); deviceHdl.Config = new SNetDvcSensorCfg() { RemoteUri = "tcp://127.0.0.1:5003", IsActivelyTx = true, TxInterval = 0, TimeoutResponse = 5000, ProtoFormat = SNetEnumProtoFormat.SNetCmd, IsActivelyConnect = false, }; deviceHdl.Config.SignalCfgList.Add(new SNetSignalTransCfg() { Svid = 0, }); deviceHdl.EhSignalCapture += (sender, ea) => { fs.Write(ea); }; Task.Run(() => { using (deviceHdl) { deviceHdl.CfInit(); deviceHdl.CfLoad(); deviceHdl.CfRunLoop(); deviceHdl.CfUnLoad(); deviceHdl.CfFree(); } isFinishDevice = true; }); var deviceListener = new CtkTcpListener("127.0.0.1", 5003); var seqval = 0.000000001; deviceListener.EhDataReceive += (sender, ea) => { var state = ea as CtkNonStopTcpStateEventArgs; var rnd = new Random((int)DateTime.Now.Ticks); //System.Threading.Thread.Sleep(1); //記得加換行, cmd 結構以換行為分界 state.WriteMsg(string.Format("cmd -respData -svid 0 -data {0} {1}\n" , seqval += 0.000000001 , rnd.NextDouble() )); }; deviceListener.NonStopRunAsyn(); SpinWait.SpinUntil(() => (DateTime.Now - startDt).TotalSeconds >= 3); deviceHdl.CfIsRunning = false; SpinWait.SpinUntil(() => isFinishDevice); }