예제 #1
0
 public ConnectMU(SerialPort sp, string prefix, string side, RollExam frm)
 {
     InitializeComponent();
     serialPort     = sp;
     boTransmitLogs = new BOTransmitLogs(frm.ConnectionString);
     boExamRollLogs = new BOExamRollLogs(frm.ConnectionString);
     Prefix         = prefix;
     Side           = side;
     frmRollExam    = frm;
 }
예제 #2
0
        private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (IsPortOpen && RollInfo.CurrentRollID.HasValue)
            {
                try
                {
                    string receivedCmd = serialPort.ReadLine();

                    BOTransmitLogs boTransmitLogsHelper = new BOTransmitLogs(ConnectionString);
                    BOExamRollLogs boExamRollLogsHelper = new BOExamRollLogs(ConnectionString);
                    if (receivedCmd.Length > 9)
                    {
                        char commandType = receivedCmd[9];

                        boTransmitLogsHelper.SaveTransmitLog(RollInfo.CurrentRollID.Value, receivedCmd, commandType, "RX");
                        switch (commandType)
                        {
                        case 'E':
                        case 'W':
                            if (CurrentExamRollLog == null)
                            {
                                CurrentExamRollLog = new ExamRollLogView();
                            }

                            CurrentExamRollLog.LogID       = boExamRollLogsHelper.SaveExamRollLog(RollInfo.CurrentRollID.Value, receivedCmd.Substring(3, 6), commandType.ToString(), "I");
                            CurrentExamRollLog.LMR         = receivedCmd.Substring(3, 6);
                            CurrentExamRollLog.Grade       = null;
                            CurrentExamRollLog.Spot        = null;
                            CurrentExamRollLog.Shade       = null;
                            CurrentExamRollLog.DefectCode  = "";
                            CurrentExamRollLog.Side        = commandType.ToString();
                            CurrentExamRollLog.ActionID    = 1;
                            CurrentExamRollLog.ActionDesc  = "";
                            CurrentExamRollLog.Type        = "I";
                            CurrentExamRollLog.Transmitted = false;
                            CurrentCommandType             = RollCommandType.OperatorInfo;
                            break;

                        case 'Z':
                            boExamRollLogsHelper.SaveExamRollLog(RollInfo.CurrentRollID.Value, "", "", "Z");
                            CurrentCommandType = RollCommandType.EndOfRoll;
                            break;

                        case 'N':
                            if (!RollInfo.NextRollID.HasValue)
                            {
                                MessageBox.Show("No next roll exists. The new roll cannot be started.");
                                return;
                            }
                            boExamRollLogsHelper.SaveExamRollLog(RollInfo.NextRollID.Value, "", "", "N");

                            CurrentCommandType = RollCommandType.NewRoll;
                            break;

                        default:
                            CurrentCommandType = RollCommandType.Others;
                            break;
                        }

                        try
                        {
                            serialPort.WriteLine(receivedCmd.Substring(0, 3) + "$");
                            boTransmitLogsHelper.SaveTransmitLog(CurrentCommandType == RollCommandType.NewRoll ? RollInfo.NextRollID.Value : RollInfo.CurrentRollID.Value, receivedCmd.Substring(0, 3) + "$", Side == "EAST" ? 'E' : 'W', "TX");
                        }
                        catch (InvalidOperationException ioEx)
                        {
                            MessageBox.Show(ioEx.Message);
                        }
                        catch (TimeoutException toEx)
                        {
                            MessageBox.Show(toEx.Message);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else if (receivedCmd.Length > 3)
                    {
                        CurrentCommandType = RollCommandType.EnableDisable;
                        boTransmitLogsHelper.SaveTransmitLog(RollInfo.CurrentRollID.Value, receivedCmd, 'A', "RX");
                    }
                    this.Invoke(new Action(() => UpdateUI(CurrentCommandType)));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("SerialPort1_DataReceived: " + ex.Message);
                }
            }
        }