private void AsyncFloatStart(LibnodavePLC lIBnodavePLC) { int ERROR = 0; string recive = null; logNet2 = new LogNetSingle("FloatDataLog.txt"); ThreadState1 = true; Task.Run(() => { float _value = 1.00f; while (true) { _value = _value + 0.01f; lIBnodavePLC.WriteFloat(_value); this.Invoke(new Action(() => { logNet2.RecordMessage(HslMessageDegree.DEBUG, "写入", _value.ToString()); recive = lIBnodavePLC.ReadFloat().ToString(); logNet2.RecordMessage(HslMessageDegree.DEBUG, "读取", recive); if (_value.ToString() != recive.ToString()) { ERROR++; } logNet2.RecordMessage(HslMessageDegree.DEBUG, "ERROR", ERROR.ToString()); } ) ); } }); }
private void button1_Click(object sender, EventArgs e) { string model = txtModel.Text.Trim(); string sql = string.Empty; if (string.IsNullOrEmpty(model)) { return; } curPath = path = Application.StartupPath + "\\HO-\\" + model + ".txt";// file = new LogNetSingle(path); if (String.IsNullOrEmpty(m_lastModel)) { m_lastModel = ConfigurationManager.AppSettings["LastModel676"]; sql = m_676.Replace(m_lastModel, model); m_lastModel = model; AppSetting.SetAppSettingValue("LastModel676", m_lastModel); } else { sql = m_676.Replace(m_lastModel, model); m_lastModel = model; AppSetting.SetAppSettingValue("LastModel676", m_lastModel); } file.WriteInfo(sql); }
public static int Main1(String[] args) { LogNet = new LogNetDateTime(Application.StartupPath + "\\Logs\\服务端", GenerateMode.ByEveryDay); // 创建日志器,按每天存储不同的文件 InitPLC(); StartListening(); return(0); }
/// <summary> /// 使用用户自定义的解密方法从文件读取数据 /// </summary> /// <param name="decrypt">用户自定义的解密方法</param> public void LoadByFile(Converter <string, string> decrypt) { if (FileSavePath != "") { if (File.Exists(FileSavePath)) { HybirdLock.Enter(); try { using (StreamReader sr = new StreamReader(FileSavePath, Encoding.Default)) { LoadByString(decrypt(sr.ReadToEnd())); } } catch (Exception ex) { ILogNet?.WriteException(StringResources.FileLoadFailed, ex); } finally { HybirdLock.Leave(); } } } }
private void AsyncBitStart(LIBnodavePLC lIBnodavePLC) { if (!ThreadState3) { int ERROR = 0; ThreadState3 = true; bool flagl = true; string log = string.Format("BitDataLog.txt"); LogNetBit = new LogNetSingle(log); string recive = null; Task task = new Task(() => { while (true) { Thread.Sleep(10); flagl = !flagl; lIBnodavePLC.WriteBit(flagl); LogNetBit.RecordMessage(HslMessageDegree.DEBUG, "写入", flagl.ToString()); recive = lIBnodavePLC.ReadBit().ToString(); LogNetBit.RecordMessage(HslMessageDegree.DEBUG, "读入", recive); if (flagl.ToString() != recive.ToString()) { ERROR++; } LogNetBit.RecordMessage(HslMessageDegree.DEBUG, "ERROR", ERROR.ToString()); } } ); task.Start(); } }
/// <summary> /// 新增一个账户,如果账户名称已经存在,则返回False,注册成功返回True /// </summary> /// <param name="account">账户对象</param> /// <returns>成功<c>True</c>,失败<c>False</c></returns> public bool AddNewAccount(T account) { bool result = true; hybirdLock.Enter(); // 账户名重复的时候不允许添加 for (int i = 0; i < all_list_accounts.Count; i++) { if (all_list_accounts[i].UserName == account.UserName) { result = false; break; } } // 账户名为空的时候不允许添加 if (string.IsNullOrEmpty(account.UserName)) { result = false; } // 检测通过后进行添加账户名 if (result) { all_list_accounts.Add(account); ILogNet?.WriteInfo(SoftResources.StringResouce.AccountAddSuccess + account.UserName); } hybirdLock.Leave(); return(result); }
private void FormGuid_Load(object sender, EventArgs e) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } file = new LogNetSingle(path); }
/// <summary> /// 从所有的账户的json数据加载账户 /// </summary> /// <param name="json"></param> public void LoadAllAccountsJson(string json) { hybirdLock.Enter(); try { all_list_accounts = JArray.Parse(json).ToObject <List <T> >(); } catch (Exception ex) { ILogNet?.WriteException(SoftResources.StringResouce.AccountLoadFailed, ex); } hybirdLock.Leave(); }
private void FormMain_Load(object sender, EventArgs e) { //程序验证注册码 //CheckSoftAuthorize(); //初始化程序日志 LogNetProgramer = new LogNetSingle(ProgramerLogPath); //初始化用户日志 LogNetUser = new LogNetSingle(UserLogPath); //初始化扫描枪 //InitSocket(); //初始化PLC通讯 //InitPLCCommunication(); //初始化页面布局 InitalizalForm(); //打开视觉网络连接 OpenEthernet(); m_socketScan = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); endPoint = new IPEndPoint(IPAddress.Parse(AppSetting.GetScanIP()), int.Parse(AppSetting.GetScanPort())); //检测数据库连接状态 CheckDbConnected(); //核心线程 m_mainThread = new Thread(StartMainThread); m_mainThread.IsBackground = true; m_mainThreadState = true; m_mainThread.Start(); //控件焦点自动切换 t_change = new Thread(ChangeActiveControl); t_change.IsBackground = true; t_change.Start(); //视觉通讯线程 Thread tVisionThread = new Thread(VisionDataCollect); tVisionThread.IsBackground = true; //tVisionThread.Start(); //初始化检测提醒功能 InitWarnCheck(); }
public MainView() { InitializeComponent(); if (!mvvmContext1.IsDesignMode) { InitializeBindings(); } //读取系统参数 SysPara = OperatePara.LoadPara("Para.cfg"); DB_Operate = new DB_Operate(SysPara.UserDB, SysPara.UserTB, SysPara.UserPath); //指定用户数据库和表 DB_Work = new DB_Operate(SysPara.WorkDB, SysPara.WorkTB, SysPara.WorkPath); //指定工作数据库和表 //页面跳转 getUserList(); if (!getAuthority()) { this.TabControl.SelectedPage = this.TabControl.Pages[0];//跳转到登录页面 } FirstSign = true; //创建页面 if (TabControl.SelectedPage.Text == "用户") { //刷新列表 getUserList(); User_List.SelectedIndex = 0; } //DB_Work.DB_Table.RowChanged += new DataRowChangeEventHandler(refreshDB); //配置连接参数 ReadPLCValue = new ReadValue(SysPara.PlcIp, SysPara.PlcPort, SysPara.PlcSA1, SysPara.PlcDA1, SysPara.PlcDA2); plcStatus(); //配置流程参数 WorkProcess.equal1ClearEvent += new ValueChange.Change_Event(workProcessClear); //清空参数 WorkProcess.equal1Event += new ValueChange.Change_Event(workProcessGoing); //==1触发读取流程参数 //配置Log参数 Log = new LogNetDateTime("./Log", GenerateMode.ByEveryHour); //配置扫码枪参数 CodeDevice = new RS232(); CodeDevice.Receive_Event += new Receive_Delegate(CodeResolve); //刷新串口列表 Com_List.Items.AddRange(CodeDevice.PortName.ToArray()); Com_List.SelectedIndex = SysPara.PortNo; //连接扫码枪 OpenCodeDevice(); //判断OK/NG judgeEnable.Checked = SysPara.Judge; JudgeDisable.Checked = !SysPara.Judge; //User管理 userListEdit.DataSource = DB_Operate.DB_Table; //主页的信息显示 InitialData(); }
/// <summary> /// 更新指定账户的密码 /// </summary> /// <param name="name"></param> /// <param name="password"></param> public void UpdatePassword(string name, string password) { hybirdLock.Enter(); for (int i = 0; i < all_list_accounts.Count; i++) { if (name == all_list_accounts[i].UserName) { all_list_accounts[i].Password = password; ILogNet?.WriteInfo(SoftResources.StringResouce.AccountModifyPassword + name); break; } } hybirdLock.Leave(); }
/// <summary> /// 更新指定账户的大小尺寸的头像MD5码 /// </summary> /// <param name="name"></param> /// <param name="largePortraitMD5">大尺寸头像的MD5</param> /// <param name="smallPortraitMD5">小尺寸头像的MD5</param> public void UpdatePortraitMD5(string name, string smallPortraitMD5, string largePortraitMD5) { hybirdLock.Enter(); for (int i = 0; i < all_list_accounts.Count; i++) { if (name == all_list_accounts[i].UserName) { all_list_accounts[i].SmallPortraitMD5 = smallPortraitMD5; all_list_accounts[i].LargePortraitMD5 = largePortraitMD5; ILogNet?.WriteInfo(SoftResources.StringResouce.AccountUploadPortrait + name); break; } } hybirdLock.Leave(); }
/// <summary> /// 删除一个账户信息, /// </summary> /// <param name="name">需要删除的账户的名称</param> public void DeleteAccount(string name) { hybirdLock.Enter(); for (int i = 0; i < all_list_accounts.Count; i++) { if (name == all_list_accounts[i].UserName) { all_list_accounts.RemoveAt(i); ILogNet?.WriteInfo(SoftResources.StringResouce.AccountDeleteSuccess + name); break; } } hybirdLock.Leave(); }
//private IPLC PLC; #region 单DB块构造函数 /// <summary> /// 单块线程,一个线程一个DB块 /// </summary> /// <param name="length">数据长度</param> /// <param name="Addr">地址块</param> /// <param name="IP">PLC的IP地址</param> /// <param name="dataTyte">数据类型</param> /// <param name="ThreadCount">线程数,不设置为空</param> public ThreadingTest(int length, string Addr, string IP, comm.DataTyte dataTyte, IPLC PLCTextBox, string ThreadCount = null) { isFirst = true; timer1.Elapsed += timer1_Elapsed; timer1.Interval = 3000; logNet = new LogNetSingle("Treadinglog.txt"); _PLCDriver = PLCTextBox; //PLC = new SenmensPLC(); this._DataLength = length; this._Addr = Addr; this._IP = IP; _hda = new List <HistoryData>(); this._ThreadCount = ThreadCount; this._dataTyte = dataTyte; Name = "单线程读取,地址:" + _Addr + "PLC IP:" + IP + "\r\n"; timer1.Start(); }
private void LibInit() { try { ThreadState4 = true; logNet2 = new LogNetSingle("StrDataLog.txt"); _LibnodavePLC = new LibnodavePLC(); bool isopen = _LibnodavePLC.Init("DB1.0", Txt_IP.Text);; byte[] ReciveData = new byte[1000]; string sendmessage = ""; Task.Run(() => { while (true) { this.Invoke(new Action(() => { lock (this) { sendmessage = Txt_Send.Text = GetRandomString(400); } } ) ); _LibnodavePLC.WriteBytes(SoftBasic.HexStringToBytes(Txt_Send.Text)); logNet2.RecordMessage(HslMessageDegree.DEBUG, "写入", sendmessage); ReciveData = _LibnodavePLC.ReadBytes(200); this.Invoke(new Action(() => { lock (this) Txt_Recieve.Text = SoftBasic.ByteToHexString(ReciveData); logNet2.RecordMessage(HslMessageDegree.DEBUG, "读取", Txt_Recieve.Text); logNet2.RecordMessage(HslMessageDegree.DEBUG, null, "是否正常" + Check(Txt_Recieve.Text, Txt_Send.Text)); })); } } ); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//private void AsyncFloatStart( LIBnodavePLC lIBnodavePLC, float[] floats) //{ // int _Lenth = floats.Length; // int ERROR = 0; // string recive = null; // //string send = null; // bool check= false; // LogNetFloat = new LogNetSingle("FloatDataLog.txt"); // ThreadState1 = true; // double during = 0; // Task.Run(() => { // while (true) // { // if (floats != null) // { // Thread.Sleep(10); // floats = GetRandomfloat(750); // lIBnodavePLC.WriteFloats(floats); // lIBnodavePLC.ReadFloats(Convert.ToUInt16(floats.Length)); // check = (floats as IStructuralEquatable).Equals(lIBnodavePLC.Floats, StructuralComparisons.StructuralEqualityComparer); // during = (lIBnodavePLC.Readtime - lIBnodavePLC.Sendtime).TotalMilliseconds; // LogNetFloat.RecordMessage(HslMessageDegree.DEBUG, null, "耗时" + (lIBnodavePLC.Readtime - lIBnodavePLC.Sendtime).TotalMilliseconds + "字节数" + _Lenth.ToString() + "是否正常" + check); // _hdaFloat.Add(new HistoryData(during,_Lenth,check,DateTime.Now,)); // } // else // { // float _value = 1.00f; // _value = _value + 0.01f; // lIBnodavePLC.WriteFloat(_value); // this.Invoke(new Action(() => // { // LogNetFloat.RecordMessage(HslMessageDegree.DEBUG, "写入", _value.ToString()); // recive = lIBnodavePLC.ReadFloat().ToString(); // LogNetFloat.RecordMessage(HslMessageDegree.DEBUG, "读取", recive); // if (_value.ToString() != recive.ToString()) // { // ERROR++; // } // LogNetFloat.RecordMessage(HslMessageDegree.DEBUG, "ERROR", ERROR.ToString()); // } // ) // ); // } // } // }); //} //private void AsyncInt32Start(LIBnodavePLC lIBnodavePLC,int _Length) //{ // //if (ThreadState2) // //{ // // return; // //} // try // { // int ERROR = 0; // string log = string.Format("Int32DataLog.txt"); // LogNetInt32 = new LogNetSingle(log); // string recive = null; // int[] send=null; // ThreadState2 = true; // bool check = false; // Task task = new Task(() => // { // int _value = 1; // while (true) // { // if (_Length!= 0) // { // send = GetRandomInt32(_Length); // Thread.Sleep(10); // lIBnodavePLC.WriteInt32s(send); // lIBnodavePLC.ReadInt32s(_Length); // check = Check(lIBnodavePLC.Int32s,send); // //LogNetInt32.RecordMessage(HslMessageDegree.DEBUG, null, "耗时" + (lIBnodavePLC.Readtime - lIBnodavePLC.Sendtime).TotalMilliseconds + "字节数" + _Lenth.ToString() + "是否正常" + Check(recive, send)); // _hdaInt32.Add(new HistoryData((lIBnodavePLC.Readtime - lIBnodavePLC.Sendtime).TotalMilliseconds, _Length*4, check, DateTime.Now)); // } // else // { // _value = _value + 1; // lIBnodavePLC.WriteInt32(_value); // // Txt_Send.Text = _value.ToString(); // LogNetInt32.RecordMessage(HslMessageDegree.DEBUG, "写入", _value.ToString()); // recive = lIBnodavePLC.ReadInt32().ToString(); // LogNetInt32.RecordMessage(HslMessageDegree.DEBUG, "读取", recive); // if (_value.ToString() != recive.ToString()) // { // ERROR++; // } // LogNetInt32.RecordMessage(HslMessageDegree.DEBUG, "ERROR", ERROR.ToString()); // } // } // }); // task.Start(); // } // catch (Exception ex) // { // throw ex; // } //} private void AsyncInt32Start(LIBnodavePLC lIBnodavePLC) { //if (ThreadState2) //{ // return; //} try { int ERROR = 0; string log = string.Format("Int32DataLog.txt"); LogNetInt32 = new LogNetSingle(log); string recive = null; ThreadState2 = true; Task task = new Task(() => { int _value = 1; while (true) { Thread.Sleep(10); _value = _value + 1; lIBnodavePLC.WriteInt32(_value); // Txt_Send.Text = _value.ToString(); LogNetInt32.RecordMessage(HslMessageDegree.DEBUG, "写入", _value.ToString()); recive = lIBnodavePLC.ReadInt32().ToString(); LogNetInt32.RecordMessage(HslMessageDegree.DEBUG, "读取", recive); if (_value.ToString() != recive.ToString()) { ERROR++; } LogNetInt32.RecordMessage(HslMessageDegree.DEBUG, "ERROR", ERROR.ToString()); } }); task.Start(); } catch (Exception ex) { throw ex; } }
//private void ReadData<T>(T t) //{ // AsyncStart(new LIBnodavePLC(), new byte[1]); //} //private void AsyncInt16Start(LIBnodavePLC lIBnodavePLC, int Length) //{ // if (ThreadState) // { // return; // } // short[] sendbyte = null; // int ERROR = 0; // bool check = false; // // string send = null; // string recive = null; // string log = string.Format("Int16DataLog.txt"); // LogNetInt16 = new LogNetSingle(log); // ThreadState = true; // Task task = new Task(() => // { // Int16 _value = 1; // while (true) // { // if (Length != 0) // { // Thread.Sleep(10); // sendbyte = GetRandomInt16(Length); // lIBnodavePLC.WriteInt16s(GetRandomInt16(Length)); // lIBnodavePLC.ReadInt16s(sendbyte.Length); // // LogNetInt16.RecordMessage(HslMessageDegree.DEBUG, null, "耗时" + (lIBnodavePLC.Readtime - lIBnodavePLC.Sendtime).TotalMilliseconds + "字节数" + sendbyte.Length.ToString() + "是否正常" + Check(recive, send)); // check = Check(lIBnodavePLC.Int16s, sendbyte); // //LogNetInt32.RecordMessage(HslMessageDegree.DEBUG, null, "耗时" + (lIBnodavePLC.Readtime - lIBnodavePLC.Sendtime).TotalMilliseconds + "字节数" + _Lenth.ToString() + "是否正常" + Check(recive, send)); // _hdaInt16.Add(new HistoryData((lIBnodavePLC.Readtime - lIBnodavePLC.Sendtime).TotalMilliseconds, Length * 2, check, DateTime.Now)); // } // else // { // _value++; // lIBnodavePLC.WriteInt16(_value); // LogNetInt16.RecordMessage(HslMessageDegree.DEBUG, "写入", _value.ToString()); // recive = lIBnodavePLC.ReadInt16().ToString(); // LogNetInt16.RecordMessage(HslMessageDegree.DEBUG, "读取", recive); // if (_value.ToString() != recive.ToString()) // { // ERROR++; // } // LogNetInt16.RecordMessage(HslMessageDegree.DEBUG, "ERROR", ERROR.ToString()); // if (_value > 100) // { // _value = 0; // } // } // } // }); // task.Start(); //} private void AsyncInt16Start(LIBnodavePLC lIBnodavePLC) { if (ThreadState) { return; } int ERROR = 0; string recive = null; string log = string.Format("Int16DataLog.txt"); LogNetInt16 = new LogNetSingle(log); ThreadState = true; Task task = new Task(() => { Int16 _value = 1; while (true) { Thread.Sleep(10); _value++; lIBnodavePLC.WriteInt16(_value); LogNetInt16.RecordMessage(HslMessageDegree.DEBUG, "写入", _value.ToString()); recive = lIBnodavePLC.ReadInt16().ToString(); LogNetInt16.RecordMessage(HslMessageDegree.DEBUG, "读取", recive); if (_value.ToString() != recive.ToString()) { ERROR++; } LogNetInt16.RecordMessage(HslMessageDegree.DEBUG, "ERROR", ERROR.ToString()); if (_value > 100) { _value = 0; } } }); task.Start(); }
/// <summary> /// 使用用户自定义的加密方法保存数据到文件 /// </summary> /// <param name="encrypt">用户自定义的加密方法</param> public void SaveToFile(Converter <string, string> encrypt) { if (FileSavePath != "") { HybirdLock.Enter(); try { using (StreamWriter sw = new StreamWriter(FileSavePath, false, Encoding.Default)) { sw.Write(encrypt(ToSaveString())); sw.Flush(); } } catch (Exception ex) { ILogNet?.WriteException(StringResources.FileSaveFailed, ex); } finally { HybirdLock.Leave(); } } }
public Log_Helper(string path) { logNet = new LogNetFileSize(path, 2 * 1024 * 1024); }
static LogHelper() { LogNet = Program.LogNet; }
public SynchronousSocketClient() { LogNet = new LogNetDateTime(Application.StartupPath + "\\Logs\\客户端", GenerateMode.ByEveryDay); // 创建日志器,按每天存储不同的文件 }
/// <summary> /// 实例化一个新的数据管理容器 /// </summary> /// <param name="logNet">日志记录对象,可以为空</param> /// <param name="path">文件的路径</param> public GroupFileContainer(ILogNet logNet, string path) { LogNet = logNet; GroupFileContainerLoadByPath(path); }
/// <summary> /// 初始化Log组件 /// </summary> public static void IniLogComponent() { //初始化日志 LogNet = new LogNetFileSize(@"./Log/", 5 * 1024 * 1024); }
public ILogNet LogRecord;//日志记录 /// <summary> /// 默认 /// </summary> public Log() { //配置Log参数 LogRecord = new LogNetDateTime("./Log", GenerateMode.ByEveryHour); }
/// <summary> /// 配置参数 /// </summary> public Log(GenerateMode mode) { //配置Log参数 LogRecord = new LogNetDateTime("./Log", mode); }
//构造函数 public Crane(SiemensPlc PLC_Siemens, ILogNet log) { this.PLC_Siemens = PLC_Siemens; this.Crane_Run_Log = log; }
/// <summary> /// 实例化一个文件标记对象 /// </summary> public FileMarkId(ILogNet logNet, string fileName) { LogNet = logNet; FileName = fileName; }
/// <summary> /// 创建与PLC的通信连接对象,并自动建立长连接 /// </summary> /// <param name="siemens"></param> /// <param name="ipAddress"></param> /// <param name="plcLog"></param> public SiemensPlc(SiemensPLCS siemens, string ipAddress, ILogNet plcLog) : this(siemens, ipAddress) { this.Plc_Commu_Log = plcLog; //建立与PLC的长连接 Initialization(); }