//public static System.Windows.Forms.Timer timer_stopper; //// ========================================================================================================= static void Main(string[] args) { tmrDutControl_TutnOff(); autoConnect_TurnOff(); #if !DEBUG CheckLicense(); #endif if (deb == 1) { dc_timer = 1 * 30 * 1000; } Dutyara.GetPorts(); dut_list.Add(new Dutyara(33722, 9600)); dut_list.Add(new Dutyara(22733, 9600)); Dutyara.GetPorts(); tmrDutControl_TutnOn(); autoConnect_TurnOn(); tmrPing = new System.Threading.Timer(new TimerCallback(PingTimerCallback), null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); var base_path = Environment.GetEnvironmentVariable("USERPROFILE"); if (base_path == null) { base_path = Environment.GetEnvironmentVariable("HOME"); } if (base_path == null) { base_path = Path.GetDirectoryName(Environment.CurrentDirectory); } _settings_file_name = Path.Combine(base_path, ".wialon_ips_emulator.settings"); if (!File.Exists(path)) { File.Create(path); } try { Settings = CSettings.Load(_settings_file_name); Console.WriteLine("Emulator" + "Settings loaded successfully"); } catch (Exception) { Console.WriteLine("Emulator" + "Cannot load settings"); Settings = new CSettings(); } //ConnectClick(); while (true) { string comm = ""; if (comm.ToLower() == "exit") { break; } } Console.ReadKey(); }
public static string GenerateString(Dutyara dut, int iter) { //string rtn = "id-" + (iter + 1) + ":3:" + dut.Id + ",fuel-" + (iter + 1) + ":2:" + FormatFluid(dut.msg_cont.fuel) // + ",water-" + (iter + 1) + ":2:" + FormatFluid(dut.msg_cont.water) + ",temp-" + (iter + 1) + ":2:" + FormatTemp(dut.msg_cont.temp) + ","; string rtn = "id" + (iter + 1) + ":3:" + dut.Id + ",fuel" + (iter + 1) + ":2:" + FormatFluid(dut.msg_cont.fuel) + ",water" + (iter + 1) + ":2:" + FormatFluid(dut.msg_cont.water) + ",temp" + (iter + 1) + ":2:" + FormatTemp(dut.msg_cont.temp) + ","; return(rtn); }
public string GetData() { if (flag == true) { try { byte[] inp; int inpQty = 0; string sReceiveDT = ""; string message = ""; // Если изменились настройки порта, перенастраиваем порт if (serialP.PortName != selectedPort) { serialP.Close(); serialP.PortName = selectedPort; } if (serialP.BaudRate != selectedSpeed) { serialP.Close(); serialP.BaudRate = selectedSpeed; } if (serialP.Parity != System.IO.Ports.Parity.None) { serialP.Close(); serialP.Parity = System.IO.Ports.Parity.None; } // Если порт закрыт, открываем if (!serialP.IsOpen) { serialP.Open(); } if (serialP.IsOpen) { inp = new Byte[4096]; inpQty = 0; if (serialP.BytesToRead > 0) //если пришли данные { sReceiveDT = DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00") + ":" + DateTime.Now.Second.ToString("00") + "." + DateTime.Now.Millisecond.ToString("000"); inpQty = serialP.BytesToRead; //определяем количество байт, которые пришли serialP.Read(inp, 0, serialP.BytesToRead); //считываем данные // ПОКАЗ В СПИСКЕ if (inpQty > 0) { message = ""; for (Int32 i = 0; i < inpQty; i++) { message += " " + ByteToStrHex(inp[i]); //формируем сообщение для отображения в ListView } // Console.WriteLine("HEX: " + message); message = Encoding.ASCII.GetString(inp, 0, inpQty); // GatewayServer // Console.WriteLine("ASCII: " + message); return(message); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); Dutyara.GetPorts(); //MainForm.message_status = MainForm.PORT_DROP; } } return(""); }