public bool Save() { try { PointAggregate.strName = textBox_Name.Text; StationModule sm = StationManage.FindStation(PointAggregate.strStationName); int eucf = 1000; for (int i = 0; i < PointAggregate.arrPoint.Length; i++) { NumericUpDown PonitSpeed = tag_list[i * 2]; NumericUpDown PonitValue = tag_list[i * 2 + 1]; if (sm != null) { eucf = (int)sm.arrAxis[i].Eucf; } else { eucf = (int)1000;; } PointAggregate.arrPoint[i].dblPonitSpeed = Convert.ToDouble(PonitSpeed.Value) * eucf; PointAggregate.arrPoint[i].dblPonitValue = Convert.ToDouble(PonitValue.Value); } } catch (System.Exception ex) { LogOutControl.OutLog(ex.Message, 0); Console.Write(ex.ToString()); return(false); } return(true); }
/// <summary> /// 继续函数 /// </summary> /// <param name="o"></param> /// <returns></returns> public short Continue(object o1) { if (Global.WorkVar.tag_ResetState == 0) { LogOutControl.OutLog("没有复位,请复位", 0); return(-1); } if (Global.WorkVar.tag_SuspendState == 1 || Global.WorkVar.bSuspendState_L || Global.WorkVar.bSuspendState_R) { object[] po = new object[1]; po[0] = o1; foreach (object o in tag_workObject) { Type t = o.GetType(); System.Reflection.MethodInfo[] methods = t.GetMethods(); System.Reflection.PropertyInfo[] PropertyInfo = t.GetProperties(); System.Reflection.MemberInfo[] MemberInfos = t.GetMembers(); for (int i = 0; i < methods.Length; i++) { if (methods[i].Name == "Continue") { methods[i].Invoke(o, po); } } } } Global.WorkVar.tag_SuspendState = 0; Global.WorkVar.bSuspendState_L = false; Global.WorkVar.bSuspendState_R = false; return(0); }
/// <summary> /// 右工位继续函数 /// </summary> /// <param name="o"></param> /// <returns></returns> public short Continue_R(object o1) { if (Global.WorkVar.tag_ResetState == 0) { LogOutControl.OutLog("没有复位,请复位", 0); return(-1); } object[] po = new object[1]; po[0] = o1; foreach (object o in tag_workObject) { Type t = o.GetType(); if (t.Name == "RightStation") { System.Reflection.MethodInfo[] methods = t.GetMethods(); for (int i = 0; i < methods.Length; i++) { if (methods[i].Name == "Continue") { methods[i].Invoke(o, po); } } } } Global.WorkVar.bSuspendState_R = false; return(0); }
private void FrmWait_Load(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem( delegate { try { short ret = tag_delegate_Exe(tag_o); this.Invoke( (MethodInvoker) delegate { if (tag_delegate_End != null) { tag_delegate_End(tag_o); } else { if (ret != 0) { MessageBoxLog.Show("操作失败"); } } this.Close(); } ); } catch (System.Exception ex) { LogOutControl.OutLog(ex.Message, 0); } } ); }
/// <summary> /// 判断当前轴运动是否是本点的安全区 安全返回TRUE /// </summary> /// <returns></returns> public static bool IoAxisIsSafe(StationModule sm, AxisConfig _ac, double offset, double pos) { bool ret = true; if (sm.arrPoint.Count == 0) { return(true); } foreach (PointAggregate pa in sm.arrPoint) { if (isIOAxisHavePoint(_ac, pa, pos)) { if (pa.tag_AxisSafeManage.PointIsSafe(pa)) { if (IOIsSafe(pa)) { ret = true; // break; } else { ret = false; break; } } } } if (ret == false) { LogOutControl.OutLog(_ac.AxisName + "运动不安全", 0); } return(ret); }
/// <summary> /// /// </summary> /// <param name="sendstr"></param> /// <returns></returns> public string sendCommand(string sendstr, int outTime) { try { if (!tag_PortParameter.tag_enable) { char[] ReadBuffer = new char[1024]; if (tag_SerialPort == null) { tag_SerialPort = new SerialPort(tag_PortParameter.tag_portName, tag_PortParameter.tag_baudRate, tag_PortParameter.tag_Parity, tag_PortParameter.tag_databits, tag_PortParameter.tag_stopBits); } if (!tag_SerialPort.IsOpen) { tag_SerialPort.Open(); } tag_SerialPort.ReadTimeout = outTime; tag_SerialPort.WriteTimeout = outTime; tag_SerialPort.Write(sendstr); string retstr = tag_SerialPort.ReadLine(); return(retstr); } else { return(tag_PortParameter.tag_DefintRet); } } catch (Exception mess) { LogOutControl.OutLog(mess.Message, 0); return(""); } }
/// <summary> /// /// </summary> /// <param name="sendstr"></param> /// <returns></returns> public byte[] sendCommand(byte[] Buffer, int bufferLen, int outTime) { byte[] ReadBuffer = new byte[128]; try { if (!tag_PortParameter.tag_enable) { if (tag_SerialPort == null) { tag_SerialPort = new SerialPort(tag_PortParameter.tag_portName, tag_PortParameter.tag_baudRate, tag_PortParameter.tag_Parity, tag_PortParameter.tag_databits, tag_PortParameter.tag_stopBits); } if (!tag_SerialPort.IsOpen) { tag_SerialPort.Open(); } tag_SerialPort.ReadTimeout = outTime; tag_SerialPort.WriteTimeout = outTime; tag_SerialPort.Write(Buffer, 0, bufferLen); Thread.Sleep(100); tag_SerialPort.Read(ReadBuffer, 0, 128); return(ReadBuffer); } else { return(ReadBuffer); } } catch (Exception mess) { LogOutControl.OutLog(mess.Message, 0); return(ReadBuffer); } }
/// <summary> /// connsendstr 当没有连接时候,发送的串,sendstring 发送的穿 /// </summary> /// <param name="connsendstr"></param> /// <param name="sendstring"></param> /// <returns></returns> public string Read(int outTime) { try { if (tag_Socket.Connected) { //1123 try { byte[] read = new byte[512]; tag_Socket.ReceiveTimeout = outTime; tag_readLen = tag_Socket.Receive(read, read.Length, 0); string retstr = Encoding.ASCII.GetString(read, 0, tag_readLen); //LogOutControl.OutLog(retstr, 0); return(retstr); } catch (Exception exx) { LogOutControl.OutLog(exx.Message, 0); return(""); } } else { return("error,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\r\n"); } } catch (Exception ex) { tag_SendLock = 0; LogOutControl.OutLog(ex.Message, 0); CLose(); return("error,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\r\n");; } }
/// <summary> /// 判断当前位置是否是所在按区域的时候,对应IO是否安全,安全返回TRUE,否则FLASE /// </summary> /// <returns></returns> public static bool IOIsSafe(PointAggregate pa) { if (pa == null || pa.tag_AxisSafeManage == null || pa.tag_AxisSafeManage.tag_InIoList == null || pa.tag_AxisSafeManage.tag_InIoList.Count == 0) { return(true); } foreach (OutIOParameterPoint io in pa.tag_AxisSafeManage.tag_InIoList) { bool var = false; // io.tag_IniO1.tag_name if (io != null && io.tag_IniO2 != null && NewCtrlCardV0.GetInputIoBitStatus(io.tag_IniO2.tag_name, io.tag_IniO2.tag_IOName, out var) == 0) { if (var == io.tag_IniO2.tag_var) { } else { LogOutControl.OutLog("IO:<" + io.tag_IniO2.tag_IOName + " >有安全隐患,可能撞机,请注意", 0); return(false); } } } return(true); }
/// <summary> /// 判断是否右轴报警 TRUE 报警 /// </summary> public bool IsAxisAlarm() { bool axio = false; //NewCtrlCardV0.GetInputIoBitStatus("", "Z1报警", out axio); if (axio) { LogOutControl.OutLog("轴报警", 0); return(true); } int CardIndex = 0; int axisIndex = 0; bool ret = false; for (MotionCardManufacturer i = 0; i < MotionCardManufacturer.MotionCardManufacturer_max; i++) { NewCtrlCardBase Base = NewCtrlCardV0.tag_NewCtrlCardBase[(int)i]; short j = 0; short n = 0; if (Base == null || NewCtrlCardIO.tag_CardHave[(int)i] == 0) { continue; } while (j < NewCtrlCardV0.tag_CardCount[(int)i]) { axisIndex = 0; while (n < NewCtrlCardV0.tag_CardAxisCount[(int)i]) { //tag_CardAxisAlarm[CardIndex] AxisConfig name = IshaveAxis((int)i, j, n); if (name != null) { if (name.tag_IoAlarmNHighEnable == 1) { if ((((int)NewCtrlCardIO.tag_CardAxisAlarm[CardIndex] & (1 << n)) > 0)) { LogOutControl.OutLog(NewCtrlCardBase.GetManufacturerName((int)i) + "第" + j + "卡" + n + "轴(" + name.AxisName + ")报警", 0); ret = true; } } else { if ((((int)NewCtrlCardIO.tag_CardAxisAlarm[CardIndex] & (1 << n)) == 0)) { LogOutControl.OutLog(NewCtrlCardBase.GetManufacturerName((int)i) + "第" + j + "卡" + n + "轴(" + name.AxisName + ")报警", 0); ret = true; } } } axisIndex++; n++; } CardIndex++; j++; } // } return(ret); }
// // 摘要: // 显示具有指定文本、标题、按钮和图标的消息框。 // // 参数: // text: // 要在消息框中显示的文本。 // // caption: // 要在消息框的标题栏中显示的文本。 // // buttons: // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 // // icon: // System.Windows.Forms.MessageBoxLog 值之一,它指定在消息框中显示哪个图标。 // // 返回结果: // System.Windows.Forms.DialogResult 值之一。 // // 异常: // System.ComponentModel.InvalidEnumArgumentException: // 指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 -指定的 icon // 参数不是 System.Windows.Forms.MessageBoxIcon 的成员。 // // System.InvalidOperationException: // 尝试在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBoxLog。这是由 System.Windows.Forms.SystemInformation.UserInteractive // 属性指定的。 public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) { LogOutControl.OutLog(text, 0); MessageBoxUI box = new MessageBoxUI(text, caption, buttons, icon); DialogResult tag_buttons = box.ShowDialog(); return(tag_buttons); }
// 摘要: // 显示具有指定文本的消息框。 // // 参数: // text: // 要在消息框中显示的文本。 // // 返回结果: // System.Windows.Forms.DialogResult 值之一。 public static DialogResult Show(string text) { LogOutControl.OutLog(text, 0); log = new MessageBoxUI(text, "", MessageBoxButtons.OK, MessageBoxIcon.Question); DialogResult tag_buttons = log.ShowDialog(); log = null; return(tag_buttons); }
private void 添加两个点位ToolStripMenuItem_Click(object sender, EventArgs e) { if (Global.CConst.UserLevel != Global.CConst.USER_SUPERADMIN) { MessageBoxLog.Show("无权限"); return; } string strStationName = "NewStation"; if (tag_work.Config.arrWorkStation.Count > 0) { foreach (StationModule ms in tag_work.Config.arrWorkStation) { if (ms.strStationName != "" && ms.strStationName == strStationName) { { MessageBoxLog.Show("已有工位配置"); return; } } } } StationModule sm = new StationModule(); tag_work.Config.arrWorkStation.Add(sm); tag_work.Config.arrWorkStation[tag_work.Config.arrWorkStation.Count - 1].strStationName = strStationName; PointAggregate pa = new PointAggregate(strStationName, "工位开始"); sm.arrPoint.Add(pa); sm.intUsePointCount++; int pointCount = 0; int i = 0; try { pointCount = int.Parse(texB_Count.Text); } catch (Exception mss) { LogOutControl.OutLog(mss.Message, 0); } while (i < pointCount && i < 100) { i++; pa = new PointAggregate(strStationName, "步骤" + i); sm.intUsePointCount++; sm.arrPoint.Add(pa); } pa = new PointAggregate(strStationName, "工位结束"); sm.intUsePointCount++; sm.arrPoint.Add(pa); tag_work.Config.intUseStationCount++; tag_work.Config.Save(); FrmStationMange_Load(null, null); }
private void TB_RightStationLog_TextChanged(object sender, EventArgs e) { try { worker._Config.tag_RightStationLogIndex = Int32.Parse(TB_RightStationLog.Text); } catch (Exception mess) { LogOutControl.OutLog(mess.Message, 0); } }
/// <summary> /// 构造函数,连接时候不需要发送数据 /// </summary> /// <param name="ip"></param> /// <param name="port"></param> public SocketClient(IPConfig ipa) { tag_IPConfig = ipa; //设定服务器IP地址 try { } catch (Exception ex) { LogOutControl.OutLog(ex.Message, 0); } }
/// <summary> ///启动列表 /// </summary> public void startList() { foreach (object o in tag_workObject) { Type t = o.GetType(); System.Reflection.MethodInfo[] methods = t.GetMethods(); System.Reflection.PropertyInfo[] PropertyInfo = t.GetProperties(); System.Reflection.MemberInfo[] MemberInfos = t.GetMembers(); WorkBase workBase = (WorkBase)o; for (int i = 0; i < methods.Length; i++) { if (methods[i].Name == "StartThread") { if (workBase.tag_isRestStation == 0) { workBase.tag_IsWork = 0; workBase.tag_Manual.tag_StepName = 0; methods[i].Invoke(o, null); } } } } //Rc rc = Rc.Ok; //rc = (Rc)NativeMethods.LJV7IF_Initialize(); //if (rc != Rc.Ok) //{ // LogOutControl.OutLog("测量仪初始化失败", 0); //} try { _ethernetConfig.abyIpAddress = new byte[] { Convert.ToByte("192"), Convert.ToByte("168"), Convert.ToByte("1"), Convert.ToByte("111") }; _ethernetConfig.wPortNo = Convert.ToUInt16("10000"); } catch (Exception ex) { LogOutControl.OutLog(ex.Message, 0); return; } //rc = (Rc)NativeMethods.LJV7IF_EthernetOpen(0, ref _ethernetConfig); //if (rc != Rc.Ok) //{ // LogOutControl.OutLog("与测量仪连接失败", 0); //} }
public static Config Load() { Config _Config = Load(GetSetPath("set.config")) as Config; if (_Config == null) { _Config = new Config(); } if (_Config.tag_safeStationModule == null) { _Config.tag_safeStationModule = new StationModule(); _Config.tag_safeStationModule.tag_type = 1; _Config.tag_safeStationModule.strStationName = "轴手动防呆配置工位"; _Config.tag_safeStationModule.intUsePointCount = 1; _Config.tag_safeStationModule.arrPoint.Add(new PointAggregate(_Config.tag_safeStationModule.strStationName, "p1")); } if (_Config.axisArray == null) { _Config.axisArray = new List <AxisConfig>(); } if (_Config.tag_PrivateSave == null) { _Config.tag_PrivateSave = new PrivateSave(); } if (_Config.tag_IPConfigList == null) { _Config.tag_IPConfigList = new List <IPConfig>(); for (int j = 0; j < 2; j++) { IPConfig pp = new IPConfig(); _Config.tag_IPConfigList.Add(pp); } } if (_Config.arrWorkStation == null) { _Config.arrWorkStation = new List <StationModule>(StationManage.intStationCount); for (int i = 0; i < StationManage.intStationCount; i++) { _Config.arrWorkStation[i] = new StationModule(); } } if (_Config.tag_PortParameterList == null) { _Config.tag_PortParameterList = new List <PortParameter>(); for (int j = 0; j < 4; j++) { PortParameter pp = new PortParameter(); _Config.tag_PortParameterList.Add(pp); } LogOutControl.OutLog("请配置端口", 0); } return(_Config); }
/// <summary> /// connsendstr 当没有连接时候,发送的串,sendstring 发送的穿 /// </summary> /// <param name="connsendstr"></param> /// <param name="sendstring"></param> /// <returns></returns> public string send(string sendstring, int outTime) { try { byte[] sendBuffer = Encoding.ASCII.GetBytes(sendstring); byte[] read = new byte[512]; tag_isSend = 1; if (tag_Socket == null || !tag_Socket.Connected) { tag_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } if (!tag_Socket.Connected) { Connect(); } if (tag_Socket.Connected) { try { tag_Socket.Send(sendBuffer); tag_Socket.ReceiveTimeout = outTime; tag_readLen = tag_Socket.Receive(read, read.Length, 0); string retstr = Encoding.ASCII.GetString(read, 0, tag_readLen); //LogOutControl.OutLog(retstr, 0); return(retstr); } catch (Exception) { tag_Socket = null; tag_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); tag_Socket.Send(sendBuffer); tag_Socket.ReceiveTimeout = outTime; tag_readLen = tag_Socket.Receive(read, read.Length, 0); string retstr = Encoding.ASCII.GetString(read, 0, tag_readLen); LogOutControl.OutLog(retstr, 0); return(retstr); } } else { return("error,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\r\n"); } } catch (Exception ex) { tag_SendLock = 0; LogOutControl.OutLog(ex.Message, 0); CLose(); return(""); } }
/// <summary> /// /// </summary> /// <param name="point"></param> public AxisSafeManage(PointAggregate point) { tag_AxisSafeList = new List <AxisSafe>(); StationModule sm = StationManage.FindStation(point.strStationName); if (sm == null) { LogOutControl.OutLog("无" + point.strStationName, 0); return; } foreach (AxisConfig ac in sm.arrAxis) { Add((short)ac.tag_MotionCardManufacturer, ac.CardNum, ac.AxisNum); } }
private void button1_Save_Click(object sender, EventArgs e) { if (MessageBoxLog.Show("确定要保存数据?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { tag_work._Config.tag_PrivateSave.fTestCYTime = Convert.ToDouble(textBox_OffsetTest.Text); tag_work._Config.Save(); } catch (Exception mess) { LogOutControl.OutLog(mess.Message, 0); } } }
public bool IsWork() { foreach (object o in tag_workObject) { Type t = o.GetType(); System.Reflection.MethodInfo[] methods = t.GetMethods(); System.Reflection.PropertyInfo[] PropertyInfo = t.GetProperties(); System.Reflection.MemberInfo[] MemberInfos = t.GetMembers(); WorkBase workBase = (WorkBase)o; if (workBase.tag_IsWork == 1) { LogOutControl.OutLog(workBase.tag_stationName + ":工位正在工作", 0); return(true); } } return(false); }
/// <summary> /// 读服务器下发的数据,几台通信 /// </summary> public void Connect() { try { IPAddress _ip = IPAddress.Parse(tag_IPConfig.tag_ip); tag_IPEndPoint = new IPEndPoint(_ip, tag_IPConfig.tag_port); tag_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); tag_Socket.Connect(tag_IPEndPoint); //配置服务器IP与端口 if if (!tag_Socket.Connected) { return; } } catch (Exception msg) { LogOutControl.OutLog(msg.Message, 0); } }
public void open() { try { if (tag_SerialPort == null) { tag_SerialPort = new SerialPort(tag_PortParameter.tag_portName, tag_PortParameter.tag_baudRate, tag_PortParameter.tag_Parity, tag_PortParameter.tag_databits, tag_PortParameter.tag_stopBits); } if (!tag_SerialPort.IsOpen) { tag_SerialPort.Open(); } } catch (Exception mess) { LogOutControl.OutLog(mess.Message, 0); } }
private void MenuItem_Del_Click(object sender, EventArgs e) { try { for (int i = 0; i < tag_PointModule.tag_AxisSafeManage.tag_InIoList.Count; i++) { if (tag_PointModule.tag_AxisSafeManage.tag_InIoList[i].tag_name == treeView_IO.SelectedNode.Text) { tag_PointModule.tag_AxisSafeManage.tag_InIoList.RemoveAt(i); } } Tree_Load(null, null); } catch (Exception mess) { LogOutControl.OutLog(mess.Message, 0); } }
/// <summary> /// 开始启动 /// </summary> public bool start() { if (Global.WorkVar.tag_ResetState == 1) { LogOutControl.OutLog("复位中,请等待", 0); return(false); } if (Global.WorkVar.tag_ResetState == 0) { LogOutControl.OutLog("没有复位,请复位", 0); return(false); } if (Global.WorkVar.tag_IsExit == 1) { LogOutControl.OutLog("请到主界面按启动键", 0); return(false); } if (Global.WorkVar.tag_StopState == 1) { LogOutControl.OutLog("急停中", 0); return(false); } if (IsWork()) { LogOutControl.OutLog("当前有工位正在工作,请停止正在工作的工位", 0); return(false); } if (Global.WorkVar.tag_workState == 0) { Global.WorkVar.tag_workState = 1; startList(); return(true); } else { if (Global.WorkVar.tag_ResetState == 1) { LogOutControl.OutLog("工作中", 0); } } return(false); }
//轴位配置 private void AxisCfigBT_Click(object sender, EventArgs e) { //Debug frac = new Debug(worker); //frac.Show(); if (tag_StationModule == null) { MessageBoxLog.Show("请选择工站名"); return; } try { PointDebugSetUI debugS = new PointDebugSetUI(worker, tag_StationModule); debugS.Text = "工位配置界面" + " 当前工站:" + tag_StationModule.strStationName; debugS.ShowDialog(); } catch (Exception mes) { LogOutControl.OutLog(mes.Message, 0); } }
public static bool IsRestExit() { bool axio = false; bool stopIoS = false; NewCtrlCardV0.GetInputIoBitStatus("", "急停", out stopIoS); //NewCtrlCardV0.GetInputIoBitStatus("", "Z1报警", out axio); if (axio || !stopIoS) { LogOutControl.OutLog("轴报警", 0); return(true); } if (Global.WorkVar.tag_SuspendState == 1 || Global.WorkVar.tag_ButtonStopState == 1) { Global.WorkVar.tag_StopState = 1; Global.WorkVar.tag_SuspendState = 0; return(true); } return(false); }
/// <summary> /// 读服务器下发的数据,几台通信 /// </summary> public void ConnectThread() { try { IPAddress _ip = IPAddress.Parse(tag_IPConfig.tag_ip); tag_IPEndPoint = new IPEndPoint(_ip, tag_IPConfig.tag_port); tag_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); tag_Socket.Connect(tag_IPEndPoint); //配置服务器IP与端口 if if (!tag_Socket.Connected) { return; } tag_myThread = new Thread(new ParameterizedThreadStart(SocketClient_Read)); tag_myThread.Start(); tag_myThread.IsBackground = true; } catch (Exception msg) { LogOutControl.OutLog(msg.Message, 0); } }
public void Save(bool isShowMessageBox) { if (isShowMessageBox) { if (MessageBoxLog.Show("是否保存", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) { return; } } if (tag_AxisSafe != null) { try { tag_AxisSafe.tag_max = double.Parse(textBox_Max.Text); tag_AxisSafe.tag_min = double.Parse(textBox_Min.Text); } catch { LogOutControl.OutLog(tag_axisName + "防呆保存失败", 0); } } }
/// <summary> /// 安全光栅是否OK /// </summary> /// <returns></returns> public bool IsafeLightOk() { //return true; if (_Config.tag_PrivateSave.tag_safeLightOffOn) { return(true); } if (_Config.tag_PrivateSave.tag_safeGateOffOn) { return(true); } foreach (object o in tag_workObject) { Type t = o.GetType(); WorkBase workBase = (WorkBase)o; if (workBase.tag_safe != null && !workBase.tag_safe(workBase)) { LogOutControl.OutLog(workBase.tag_stationName + "触发安全光栅或门限触发,急停", 0); return(false); } } return(true); }