FrmSendWire.cs 4.9 KB
using log4net; 
using System; 
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using URSoldering.Common;
using URSoldering.DeviceLibrary;
using URSoldering.LoadCSVLibrary;

namespace URSoldering.Client
{
    public partial class FrmSendWire : FrmBase
    {
        public FrmSendWire()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

        private void btnStopSend_Click(object sender, EventArgs e)
        {
            SendWireManager.StopSend();
        }
        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);
            if (!IsHandleCreated)
            {
                this.Close();
            }
        }

        private void formStatus(bool isOpen)
        {
            btnSetSold.Enabled = isOpen;
            btnOpenSold.Enabled = !isOpen;
            btnCloseSold.Enabled = isOpen;
            btnStartSend.Enabled = isOpen; 
            btnStartSend.Enabled = isOpen;
            btnStartBack.Enabled = isOpen; 
            btnReadError.Enabled = isOpen;
        }
        private void btnOpenSold_Click(object sender, EventArgs e)
        {
            if (SendWireManager.Init(WeldRobotBean.RobotConfig.JBC_SendWire_Port))
            {
                formStatus(true);
            }
            else
            {
                MessageBox.Show("打开送丝机失败!");
            }
        }

        private void btnCloseSold_Click(object sender, EventArgs e)
        {
            SendWireManager.Release();
            formStatus(false);
        }

        private void btnSetSold_Click(object sender, EventArgs e)
        {
            int speed = FormUtil.GetIntValue(txtSpeed);
            int length = FormUtil.GetIntValue(txtLength);
            SendWireManager.setLength(length);
            SendWireManager.setSpeed(speed);
        }
         
        private void btnCloseForm_Click(object sender, EventArgs e)
        {
            this.Close();
        } 
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (RobotBean.KNDIOValue(IO_Type.SuddenStop_Single).Equals(IO_VALUE.LOW))
            {
                lblMsg.Text = "急停未开";
            }
            else
            {
                lblMsg.Text = "";
            }
        }

        private void btnReadError_Click(object sender, EventArgs e)
        {
            int error = SendWireManager.ReadPortError();
            txtPortError.Text = error.ToString(); 
        }

        private void btnStartSend_Click(object sender, EventArgs e)
        {
            SendWireManager.StartFSend();
        }

        private void btnStartBack_Click(object sender, EventArgs e)
        {
            SendWireManager.StartBSend();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            SendWireManager.StopSend();
        }

        private void FrmSendWire_Load(object sender, EventArgs e)
        {
            txtSoldingCom.Text = WeldRobotBean.RobotConfig.JBC_SendWire_Port;
            if (SendWireManager.IsRun)
            {
                formStatus(true);
            }
            else
            {
                formStatus(false);
            }
        }

        private void btnReadError_Click_1(object sender, EventArgs e)
        {
            int speed = SendWireManager.querySpeed();
            int length = SendWireManager.queryLength();
            int value = SendWireManager.ReadPortError();
            txtPortError.Text = value.ToString();
            txtLength.Text = length.ToString();
            txtSpeed.Text = speed.ToString();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            SendWireManager.Reset();
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            string msg = "";
            string str = "02 30 30 31 30 57 53 46 44 30 30 30 30 31 03 37 ";
            byte[] data = SerialBean.StringToByte(str);
            if (data != null && data.Length > 0)
            {
                msg = Encoding.ASCII.GetString(data, 1, data.Length - 3);
            }

            txtRevice.Text = "";
            string text = txtSend.Text;
            bool isOk = false;
            byte[] reviceData = SendWireManager.parseCommand(text, out isOk);
            if (reviceData != null && reviceData.Length > 0)
            {
                int length = reviceData.Length - 3;
                if (length <= 0)
                {
                    length = reviceData.Length;
                }
                string rawMsg = Encoding.ASCII.GetString(reviceData, 1, length);

                txtRevice.Text = rawMsg;
            }
        }
    }
}