void ConnectClick() { try { var si = this.cbServer.SelectedItem as ServerInfo; var di = this.cbDevice.SelectedItem as DeviceInfo; if (di == null) { throw new DeviceNotSelected(); } if (this._mc != null) { this._mc.Dispose(); } this._mc = new MessagesCommunicator(si.Host, si.Port, this); this._mc.OnConnect += new MessageConnectorOperation(_mc_OnConnect); this._mc.OnDisconnect += new MessageConnectorOperation(_mc_OnDisconnect); this._mc.OnReceive += new MessageOperationDelegate(_mc_OnReceive); this._mc.OnSent += new MessageOperationDelegate(_mc_OnSent); this._mc.Connect(); } catch (DeviceNotSelected) { MessageBox.Show("Please create device first", "Cannot connect"); this.ShowConfigDevicesDialog(); } catch (Exception exc) { this.ActivateConnectControls(true); this.Log.PostHead("Exception", "Connect: " + exc); MessageBox.Show(exc.Message); } }
async static void SendDutData(string ips_params, MessagesCommunicator _mmc) { await Task.Run(() => { bool gg = true; // Тут работа кипит var l_dt = MyParseDateTime(DateTime.Now.ToUniversalTime()); string[] _ips_params = ips_params.Split(new string[] { "zuzuzu" }, StringSplitOptions.None); //string t_msg = "#D#"+ l_dt[0] + ";"+ l_dt[1] + ";;;;;;;;;;;;;;"; //string t_msg1 = "#D#" + DateTime.Now.ToUniversalTime().ToString("ddMMyy;HHmmss") + ";;;;;;;;;;;;;;"; string t_msg = "#D#" + _ips_params[1] + ";;;;;;;;;;;;;;"; t_msg += _ips_params[0]; //var text = this.tbSendRaw.Text.Trim(); //this.tbSendRaw.Focus(); //this.tbSendRaw.SelectAll(); if (gg == true) { var msg = WialonIPS.Message.Parse(t_msg); var vv = msg.GetType(); if (msg.Success) { _mmc.Send(msg); } else { // this.Log.PostHead("Emulator", "Unknown packet not sent: " + t_msg); System.Media.SystemSounds.Exclamation.Play(); } } Thread.Sleep(100); } ); }
static void ConnectClick() { try { selected_server = new ServerInfo("77.123.137.100", 20332, "Wialon Hosting", true); selected_device = new DeviceInfo(); selected_device.ID = "1000005"; //if (di == null) // throw new DeviceNotSelected(); if (_mc != null) { _mc.Dispose(); } _mc = new MessagesCommunicator(selected_server.Host, selected_server.Port); _mc.OnConnect += new MessageConnectorOperation(_mc_OnConnect); _mc.OnDisconnect += new MessageConnectorOperation(_mc_OnDisconnect); _mc.OnReceive += new MessageOperationDelegate(_mc_OnReceive); _mc.OnSent += new MessageOperationDelegate(_mc_OnSent); _mc.Connect(); } catch (DeviceNotSelected) { Console.WriteLine("Please create device first", "Cannot connect"); // this.ShowConfigDevicesDialog(); } catch (Exception exc) { // this.ActivateConnectControls(true); Console.WriteLine("(Log)Exception" + "Connect: " + exc); Console.WriteLine(exc.Message); } }
void _mc_OnDisconnect(MessagesCommunicator comm) { this.Log.PostHead("Emulator", "Disconnected from " + this._selected_server); if (!this._closed) { this.ActivateConnectControls(true); } this.tmrPing.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); }
void _mc_OnConnect(MessagesCommunicator comm) { this.ActivateConnectControls(false); this.Log.PostHead("Emulator", "Connected to " + this._selected_server); this._mc.Send(new LoginMessage(this._selected_device.ID, this._selected_device.Password)); if (this.Settings.SendPingPackets) { this.tmrPing.Change(this._ping_interval, this._ping_interval); } }
static void _mc_OnSent(MessagesCommunicator comm, WialonIPS.Message msg) { //this.Log.PostHead("<<<", msg.ToString()); //if (msg.MsgType == MessageType.Message) // this.Messages.Sent((msg as WialonIPS.MessageMessage).Text); if (Settings.SendPingPackets) { tmrPing.Change(_ping_interval, _ping_interval); } }
static void _mc_OnConnect(MessagesCommunicator comm) { //this.ActivateConnectControls(false); Console.WriteLine("Emulator: " + "Connected to " + selected_server); _mc.Send(new LoginMessage(selected_device.ID, selected_device.Password)); if (Settings.SendPingPackets) { tmrPing.Change(_ping_interval, _ping_interval); } }
void _mc_OnReceive(MessagesCommunicator comm, WialonIPS.Message msg) { this.Log.PostHead(">>>", msg.ToString()); if (msg.MsgType == MessageType.Message) { this.Messages.Received((msg as WialonIPS.MessageMessage).Text); } if (msg.MsgType == MessageType.LoginAns && !(msg as LoginAnsMessage).Success) { Disconnect(); } }
static void _mc_OnReceive(MessagesCommunicator comm, WialonIPS.Message msg) { Console.WriteLine(">>>" + msg.ToString()); if (msg.MsgType == MessageType.Message) { Console.WriteLine((msg as WialonIPS.MessageMessage).Text); } //this.Messages.Received((msg as WialonIPS.MessageMessage).Text); if (msg.MsgType == MessageType.LoginAns && !(msg as LoginAnsMessage).Success) { Disconnect(); } }
static void GoToNextDut(ref MessagesCommunicator _mmc) { Dutyara.need_a_stop = true; Dutyara.opened = true; dut_data = ""; dut_selected = (dut_selected + 1); if (dut_selected >= dut_list.Count) { // need_request = false; dut_selected %= dut_list.Count; SendToVialon(ref _mmc); need_request = false; } message_status = null; }
void _mc_OnConnect(MessagesCommunicator comm) { this.ActivateConnectControls(false); this.Log.PostHead("Emulator", "Connected to " + this._selected_server); this._mc.Send(new LoginMessage(this._selected_device.ID, this._selected_device.Password)); if (this.Settings.SendPingPackets) this.tmrPing.Change(this._ping_interval, this._ping_interval); }
void _mc_OnReceive(MessagesCommunicator comm, WialonIPS.Message msg) { this.Log.PostHead(">>>", msg.ToString()); if (msg.MsgType == MessageType.Message) this.Messages.Received((msg as WialonIPS.MessageMessage).Text); if (msg.MsgType == MessageType.LoginAns && !(msg as LoginAnsMessage).Success) Disconnect(); }
void _mc_OnSent(MessagesCommunicator comm, WialonIPS.Message msg) { this.Log.PostHead("<<<", msg.ToString()); if (msg.MsgType == MessageType.Message) this.Messages.Sent((msg as WialonIPS.MessageMessage).Text); if (this.Settings.SendPingPackets) this.tmrPing.Change(this._ping_interval, this._ping_interval); }
static void _mc_OnDisconnect(MessagesCommunicator comm) { Console.WriteLine("Emulator: " + "Disconnected from " + selected_server); tmrPing.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); }
void _mc_OnDisconnect(MessagesCommunicator comm) { this.Log.PostHead("Emulator", "Disconnected from " + this._selected_server); if (!this._closed) this.ActivateConnectControls(true); this.tmrPing.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); }
void ConnectClick() { try { var si = this.cbServer.SelectedItem as ServerInfo; var di = this.cbDevice.SelectedItem as DeviceInfo; if (di == null) throw new DeviceNotSelected(); if (this._mc != null) this._mc.Dispose(); this._mc = new MessagesCommunicator(si.Host, si.Port, this); this._mc.OnConnect += new MessageConnectorOperation(_mc_OnConnect); this._mc.OnDisconnect += new MessageConnectorOperation(_mc_OnDisconnect); this._mc.OnReceive += new MessageOperationDelegate(_mc_OnReceive); this._mc.OnSent += new MessageOperationDelegate(_mc_OnSent); this._mc.Connect(); } catch (DeviceNotSelected) { MessageBox.Show("Please create device first", "Cannot connect"); this.ShowConfigDevicesDialog(); } catch (Exception exc) { this.ActivateConnectControls(true); this.Log.PostHead("Exception", "Connect: " + exc); MessageBox.Show(exc.Message); } }
private static void SendToVialon(ref MessagesCommunicator _mmc) { if (zateya) { //if (black_box.Count() > 2) //zateya = false; string params_string = String.Empty; int dl_len = dut_list.Count; Dutyara counter; for (int iterator = 0; iterator < dl_len; iterator++) { counter = dut_list[iterator]; params_string += ViaDataFormater.GenerateString(counter, iterator); } params_string = params_string.Remove(params_string.Length - 1); var dts = DateTime.Now.ToUniversalTime().ToString("ddMMyy;HHmmss"); //MessageBox.Show(params_string); //SendDutData(params_string, _mmc); //Thread.Sleep(1000); //SendDutData(params_string, _mmc); //Thread.Sleep(1000); //SendDutData(params_string, _mmc); //Thread.Sleep(1000); bool conn = false; if (_mmc != null) { conn = _mmc.IsConnected; } if (conn) { //timer_stopper.Enabled = false; //var gg = timer_stopper.Interval; black_box.Add(params_string + "zuzuzu" + dts); if (!File.Exists(path)) { File.Create(path); } //#if !DEBUG //LinuxLog(params_string + "zuzuzu" + dts.Insert(2, ".").Insert(5, ".").Insert(11, ":").Insert(14, ":")); //#endif //#if DEBUG WindowsLog(params_string + "zuzuzu" + dts.Insert(2, ".").Insert(5, ".").Insert(11, ":").Insert(14, ":"));; //#endif if (black_box.Count > 0) { //int ts = timer_stopper.Interval / 1000; //timer_stopper.Stop(); //int step = 1; //if (black_box.Count > ts + ts*20/100) //{ // step*=2; // if (black_box.Count > 2*(ts + ts * 20 / 100)) // { // step *= 2; // if (black_box.Count > 4 * (ts + ts * 20 / 100)) // { // step *= 2; // if (black_box.Count > 8 * (ts + ts * 20 / 100)) // { // step *= 2; // } // } // } //} //for (int iterator = 0; iterator < black_box.Count; iterator += step) //{ // Console.WriteLine(black_box[iterator]); // SendDutData(black_box[iterator], _mmc); // Thread.Sleep(1000); // A nado? //} foreach (var item in black_box) { Console.WriteLine(item); SendDutData(item, _mmc); Thread.Sleep(1000); // A nado? } black_box.Clear(); //timer_stopper.Start(); } } else { var tt = dts.Insert(2, ".").Insert(5, ".").Insert(11, ":").Insert(14, ":"); black_box.Add(params_string + "zuzuzu" + dts); if (!File.Exists(path)) { File.Create(path); } //#if !DEBUG //LinuxLog(params_string + "zuzuzu" + dts.Insert(2, ".").Insert(5, ".").Insert(11, ":").Insert(14, ":")); //#endif //#if DEBUG WindowsLog(params_string + "zuzuzu" + dts.Insert(2, ".").Insert(5, ".").Insert(11, ":").Insert(14, ":"));; //#endif Console.WriteLine("Add"); } } }