static void Main(string[] args) { // .env DotNetEnv.Env.Load(); string HOST_IP = DotNetEnv.Env.GetString("HOST_IP"); Console.WriteLine("HOSTIP: " + HOST_IP); string CNC_IP = DotNetEnv.Env.GetString("CNC_IP"); Console.WriteLine("CNC_IP: " + CNC_IP); string INFLUX_CONSTR = DotNetEnv.Env.GetString("INFLUXDB_IP") + ":" + DotNetEnv.Env.GetString("INFLUXDB_PORT"); Console.WriteLine("INFLUXDB_CONNECTION: " + INFLUX_CONSTR); ReturnJson returnJson = new ReturnJson(); CNCInfoClass CNCInfo = new CNCInfoClass(); CNCInfo.SetConnectInfo(HOST_IP, CNC_IP, 5000); CNCInfo.Connect(); // while (true) { // Self(ref CNCInfo, ref returnJson); // string returnString = JsonSerializer.Serialize( returnJson ); // Send( returnString ); // } while (true) { try { Self(ref CNCInfo, ref returnJson); string returnString = JsonSerializer.Serialize(returnJson); Console.Write(returnString); Send(INFLUX_CONSTR, ref returnJson); } catch { } Thread.Sleep(100); } CNCInfo.Disconnect(); }
private void Run_DELTA() { for (int i = 0; i < DELTA_Count; i++)//判斷台數 { Configs[i] = ic.read_ini("DELTA setting", "name" + Convert.ToInt32(i + 1), "CNC1"); bool exportConfig = false; //false表示為不再建立xml string strConfigName = Configs[i]; //抓ini裡面所設定的xml名稱 string strApplicationDir = ""; GetConfigInfo(ref strConfigName, ref strApplicationDir, args, ref exportConfig); //設定連線訊息,此處未來應改為可以建立不同IP,甚至是更改IP info.SetConnectInfo(DELTA_localIP1, DELTA_remoteIP1, Convert.ToInt32(DELTA_timeout1)); eventLog1.WriteEntry("CNC" + i.ToString() + " Connection state is localIP" + DELTA_localIP1 + ",remote IP" + DELTA_remoteIP1 + ",timeout" + DELTA_timeout1); int isFailed = info.Connect(); if (isFailed.Equals(0)) { //此類別的List會用於之後各函式的更新執行緒 Lst_BP.Add(new Basic_BP(strConfigName, info)); //Start the interface to shared memory MemInterface.loop_switch = true; //建立實體 MemInterface interface_instance = new MemInterface(); interface_instance.main = this; interface_instance.Start(args, strConfigName, strApplicationDir, exportConfig, "DELTA", 0); } else { eventLog1.WriteEntry("LocalIP:" + DELTA_localIP1 + " remote IP:" + DELTA_remoteIP1 + "\n連線失敗,請重新嘗試\n"); } } }
//按下設定按鈕會記錄local ip,remote ip,timeout,是否有更新Tag,利用Checkbox勾選寫到ini設定檔 private void btn_setting_Click_1(object sender, EventArgs e) { if (DialogResult.Yes == MessageBox.Show("設定完需要重啟服務", "是否要重啟服務", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { if (!Lv_Addresses.SelectedItems.Count.Equals(0)) { CNC_info.SetConnectInfo(Lv_Addresses.SelectedItems[0].Text.Trim(), txt_RemoteIP.Text.Trim(), Convert.ToInt32(txt_Timeout.Text.Trim())); int Isfail = CNC_info.Connect(); if (Isfail == 0) { write_ini(); updateINFO("寫入ini記錄檔完成"); updateINFO("重啟服務中..."); ServiceController service = new ServiceController(service_name); if (service.Status == ServiceControllerStatus.Running) { try { shutdown_service(); start_service(); updateINFO("重啟完成..."); } catch { updateINFO("服務重啟失敗"); } } else if (service.Status == ServiceControllerStatus.Stopped) { start_service(); } updateINFO("服務重啟完成!"); } else { //如果回傳數值非0則跳出詢問是否仍寫入至ini設定檔 if (DialogResult.Yes == MessageBox.Show("無法連線至機台,仍要寫入設定檔嗎?", "連線錯誤", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { write_ini(); updateINFO("寫入ini設定檔完成"); //之後砍掉 ServiceController service = new ServiceController(service_name); if (service.Status == ServiceControllerStatus.Running) { try { shutdown_service(); start_service(); updateINFO("重啟完成..."); } catch { updateINFO("服務重啟失敗"); } } else if (service.Status == ServiceControllerStatus.Stopped) { start_service(); } } else { //按下否後不做任何事情 } } } else { //IP必須選定 MessageBox.Show("請先選擇上方的Local IP"); } } else { //按下取消後不做任何反應 } //Youngtec }