public static void RGS_Test_Task() { Protocol protocol=new Protocol(); protocol.Parse(System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory+"protocol.txt")); Comm.TC.RGSTC tc = new Comm.TC.RGSTC(protocol, "RGSTest", "59.120.20.153", 4660,0xffff, new byte[] { 0, 0, 0, 0 },0,0,0); // Comm.TC.RGSTC tc = (Comm.TC.RGSTC)this.manager["RGS232"]; while (!tc.IsConnected) ; tc.m_device.OnAck += new OnAckEventHandler(m_device_OnAck); tc.m_device.OnSendingPackage += new OnSendPackgaeHandler(m_device_OnSendingPackage); tc.m_device.OnReceiveText += new OnTextPackageEventHandler(m_device_OnReceiveText); while (true) { System.Drawing.Color[][] color; color = new System.Drawing.Color[1][]; color[0] = new System.Drawing.Color[4] { System.Drawing.Color.Red, System.Drawing.Color.Red, System.Drawing.Color.Red, System.Drawing.Color.Red }; try { if (tc.IsConnected) tc.SetTravelDisplay(new byte[0], new string[] { "系統測試" }, color); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
static void Main(string[] args) { Protocol protocol; string ip; int port; V2DLE dle; System.Net.Sockets.TcpClient tcp; protocol = new Protocol(); protocol.Parse(System.IO.File.ReadAllText(Protocol.CPath(AppDomain.CurrentDomain.BaseDirectory+"TIME.txt")),false); ip = protocol.ip; port = protocol.port; while (true) { try { bool isCommErr = false; tcp = new System.Net.Sockets.TcpClient(); tcp = ConnectTask(ip, port); dle = new V2DLE("DigitTimer", tcp.GetStream()); dle.OnCommError+=(s,a)=> { isCommErr = true; dle.Close(); }; while (!isCommErr) { System.Data.DataSet ds = protocol.GetSendDataSet("report_system_time"); SendPackage pkg = protocol.GetSendPackage(ds, 0xffff); pkg.cls = CmdClass.A; dle.Send(pkg); if (pkg.result == CmdResult.ACK) { System.Data.DataSet retDs = protocol.GetReturnDsByTextPackage(pkg.ReturnTextPackage); int yr,mon,dy,hr,min,sec; yr=System.Convert.ToInt32(retDs.Tables[0].Rows[0]["year"]); mon = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["month"]); dy = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["day"]); hr = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["hour"]); min = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["minute"]); sec = System.Convert.ToInt32(retDs.Tables[0].Rows[0]["second"]); DateTime dt = new DateTime(yr, mon, dy, hr, min, sec); Console.WriteLine(dt.ToString()); RemoteInterface.Util.SetSysTime(dt); } else { Console.WriteLine(pkg.result.ToString()); } System.Threading.Thread.Sleep(1000 * 60 ); } } catch (Exception ex) { ; } } }
public void VD_Test() { string src = System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "protocol.txt"); Comm.Protocol protocol = new Comm.Protocol(); protocol.Parse(src); Comm.TC.VDTC vdtc = new Comm.TC.VDTC(protocol, "vd231", "192.168.22.231", 1001, 0xffff, new byte[] { 0, 0, 0, 0 },0,0,0); while (!vdtc.IsConnected) System.Threading.Thread.Sleep(1000); vdtc.m_device.OnTextSending += new Comm.OnSendingAckNakHandler(m_device_OnTextSending); vdtc.m_device.OnSendingPackage += new Comm.OnSendPackgaeHandler(m_device_OnSendingPackage); vdtc.m_device.OnReceiveText += new Comm.OnTextPackageEventHandler(m_device_OnReceiveText); vdtc.m_device.OnBeforeAck += new Comm.OnSendingAckNakHandler(m_device_OnBeforeAck); vdtc.m_device.OnAck += new Comm.OnAckEventHandler(m_device_OnAck); // vdtc.m_device. while (true) { Console.ReadKey(); vdtc.SetRealData(3, 0, 1); Console.ReadKey(); vdtc.SetRealData(0, 0, 1); } }
static void SCM_Test() { Protocol protocol=new Protocol(); protocol.Parse(System.IO.File.ReadAllText("SCM-20100226.txt"),false); Comm.TC.SCMTC scm=new Comm.TC.SCMTC(protocol,"SCM","10.21.50.221",1001,0xffff,new byte[]{0,0,0,0},0,0,0); Console.ReadKey(); }
static void RMSTCTest() { Protocol protocol=new Protocol(); protocol.Parse(getProtocolStr("RMS")); // Comm.TC.RMSTC tc = new Comm.TC.RMSTC(protocol, "test", "10.21.63.130", 1001, 0xffff, new byte[] { 0, 0, 0, 0 }, 0, 0); }
static void AVITCTest() { Protocol protocol = new Protocol(); protocol.Parse(getProtocolStr("AVI")); // Comm.TC.AVITC tc = new Comm.TC.AVITC(protocol, "test", "192.168.90.227", 1001, 0xffff, new byte[] { 0, 0, 0, 0 }, 0, 0); }
static void set_pilt_level_degree() { Protocol protocol = new Protocol(); protocol.Parse(System.IO.File.ReadAllText("PILT.txt"),false); System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(); client.Connect("127.0.0.1", 1002); DeviceV2DLE dev = new DeviceV2DLE("PILT", client.GetStream()); System.Data.DataSet ds= protocol.GetSendDataSet("set_level_degree"); ds.Tables[0].Rows[0]["sensor_cnt"] = 1; System.Data.DataRow row = ds.Tables[1].NewRow(); row["id"] = 0; row["init_value1"] = V2DLE.DoubleTouLong(1.1111); row["value1_factor"] = V2DLE.DoubleTouLong(1.1); row["value1_offset"] = V2DLE.DoubleTouLong(0.1); row["value1_level1"] =V2DLE.DoubleTouLong(1.1); row["value1_level2"] = V2DLE.DoubleTouLong(1.2); row["value1_level3"] = V2DLE.DoubleTouLong(1.3); row["init_value2"] = V2DLE.DoubleTouLong(2.2222); row["value2_factor"] =V2DLE.DoubleTouLong( 2.1); row["value2_offset"] =V2DLE.DoubleTouLong( 0.2); row["value2_level1"] = V2DLE.DoubleTouLong(2.1); row["value2_level2"] = V2DLE.DoubleTouLong(2.2); row["value2_level3"] =V2DLE.DoubleTouLong( 2.3); ds.Tables[1].Rows.Add(row); ds.AcceptChanges(); SendPackage pkg= protocol.GetSendPackage(ds, 0xffff); dev.Send(pkg); }
static void get_pilt_level_degree() { Protocol protocol = new Protocol(); protocol.Parse(System.IO.File.ReadAllText("PILT.txt"), false); System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(); client.Connect("127.0.0.1", 1002); DeviceV2DLE dev = new DeviceV2DLE("PILT", client.GetStream()); dev.OnReceiveText += new OnTextPackageEventHandler(dev_OnReceiveText); //while (true) //{ SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, 0xffff, new byte[] { 0x04, 0x21 }); dev.Send(pkg); Console.WriteLine(V2DLE.ToHexString(pkg.ReturnTextPackage.Text)); //} }
//static void TiltConfig() //{ // ControllerConfigBase config = new ControllerConfigBase() // { // build_date = DateTime.Now, // controller_id = 0x0000, // device_type = "Tilt", // listen_port = 1002, // version_no = 1 , // sensors = new TiltSensorConfig[] // { // new TiltSensorConfig() // { // com_type="COM", // device_name="TILE1", // id=0, // execution_mode=0, // port_baud=115200, // ip_comport="COM7", // sensor_values=new SensorValueConfigBase[]{ // new SensorValueConfigBase() // { // coefficient=1, // offset=0, // desc="X", // id=0, // rules=new SensorValueRuleConfigBase[] // { // new SensorValueRuleConfigBase() // { // level=1, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // }, // new SensorValueRuleConfigBase() // { // level=2, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // }, // new SensorValueRuleConfigBase() // { // level=3, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // } // } // }, // new SensorValueConfigBase() // { // coefficient=1, // offset=0, // desc="Y", // id=1, // rules=new SensorValueRuleConfigBase[] // { // new SensorValueRuleConfigBase() // { // level=1, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // }, // new SensorValueRuleConfigBase() // { // level=2, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // }, // new SensorValueRuleConfigBase() // { // level=3, // lower_limit=0, // upper_limit=0, // hour_ma=0, // left_hour_ma1=0, // left_hour_ma2 =0, // right_hour_ma1=0, // right_hour_ma2=0 // } // } // } // } // } // } // }; // System.Xml.Serialization.XmlSerializer ser = new XmlSerializer(typeof(ControllerConfigBase)); // System.IO.MemoryStream ms=new System.IO.MemoryStream(); // ser.Serialize(ms, config); // byte[] data =new byte[ms.Length+3]; // data[0]=0x20; // data[1]=(byte)(ms.Length/256); // data[2]=(byte)(ms.Length%256); // System.Array.Copy(ms.GetBuffer(),0,data,3,ms.Length); // Comm.SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A,0xffff, data); // System.Net.Sockets.TcpClient client=new System.Net.Sockets.TcpClient(); // client.Connect("127.0.0.1",1002); // DeviceV2DLE dle = new DeviceV2DLE("tile", client.GetStream()); // dle.Send(pkg); //} static void GetPeriodData() { Protocol protocol = new Protocol(); protocol.Parse(System.IO.File.ReadAllText("PILT.txt"), false); System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(); client.Connect("127.0.0.1", 1001); DeviceV2DLE dev = new DeviceV2DLE("PILT", client.GetStream()); dev.OnReceiveText += new OnTextPackageEventHandler(dev_OnReceiveText); //while (true) //{ for (byte hour = 0; hour < 23; hour++) { for (byte min = 0; min < 60; min++) { SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, 0xffff, new byte[] { 0x28, 12, hour, min }); dev.Send(pkg); if (pkg.ReturnTextPackage != null) { System.Data.DataSet ds = protocol.GetReturnDsByTextPackage(pkg.ReturnTextPackage); if (Convert.ToInt32(ds.Tables[0].Rows[0]["sensor_cnt"]) == 0) { Console.WriteLine("Not Found"); } else Console.WriteLine(V2DLE.ToHexString(pkg.ReturnTextPackage.Text)); } } } }