예제 #1
0
        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            var id = (Rs232Action.Rs232ActionType)Enum.Parse(typeof(Rs232Action.Rs232ActionType), operationCmb.Text);
            var data = new Rs232Action.Rs232ActionData()
                                                   {
                                                       Port = portCmb.Text,
                                                       BaudRate = baudRateCmb.Text,
                                                       Command = commandTxb.Text,
                                                       DataBits = dataBitsCmb.Text,
                                                       Dtr = dtrCmb.Text,
                                                       Handshake = HandshakeCmb.Text,
                                                       Parity = parityCmb.Text,
                                                       Rts = rtsCmb.Text,
                                                       StopBits = stopBitsCmb.Text,
                                                       TargetVar = targetVarCmb.Text,
                                                       LogFileName = logCmb.Text,
                                                       AsBytes = asBytesCmb.Text,
                                                       SendLineFeed = lineFeedCmb.Text,
                                                       SendSingleChar = singleCharCmb.Text
                                                   };

            var rsObj = new Rs232Action(id, data);
            var entity = new StepEntity(rsObj);
            entity.Comment = string.Format("Rs232 Action - {0}", operationCmb.Text);
            Singleton.Instance<SaveData>().AddStepEntity(entity);
        }
예제 #2
0
        private bool Connect(Rs232Action.Rs232ActionData data)
        {
            if (_serialPort.IsOpen)
                _serialPort.Close();

            _resetLog = false;
            Port = Singleton.Instance<SavedData>().GetVariableData(data.Port);
            _serialPort.PortName = Port;
            _serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
            // Set the port's settings
            _serialPort.BaudRate = int.Parse(data.BaudRate);
            _serialPort.DataBits = int.Parse(data.DataBits);
            _serialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), data.StopBits);
            _serialPort.Parity = (Parity)Enum.Parse(typeof(Parity), data.Parity);
            _serialPort.DtrEnable = Convert.ToBoolean(data.Dtr); //some devices requires this
            _serialPort.RtsEnable = Convert.ToBoolean(data.Rts);
            _serialPort.Handshake = (Handshake)Enum.Parse(typeof(Handshake), data.Handshake);

            _serialPort.ReceivedBytesThreshold = 1;
            _serialPort.NewLine = "\r";
            // _serialPort.Encoding = System.Text.Encoding.UTF8;
            _serialPort.ReadTimeout = 100;
            _serialPort.WriteTimeout = 200;
            try
            {
                _serialPort.Open();
                LogFileName = Singleton.Instance<SavedData>().GetVariableData(data.LogFileName); //set log file name
                AutoApp.Logger.WriteInfoLog("Open Log file on " + LogFileName);
                CommonHelper.AddToLogFile(LogFileName, "Connecting COM Port - " + Port + System.Environment.NewLine);

                _ReadBuffer.Start();//start read buffer
                return true;
            }
            catch
            {
                return false;
            }
        }
예제 #3
0
 public Rs232Obj(Rs232Action.Rs232ActionData data)
 {
     _data = data;
 }
예제 #4
0
        public static ActionBase GetAction(Enums.ActionTypeId id)
        {
            ActionBase action = null;
            switch (id)
            {
                case Enums.ActionTypeId.RunProgram:
                    action = new RunProgram();
                    break;

                case Enums.ActionTypeId.Sleep:
                    action = new SleepAction();
                    break;

                case Enums.ActionTypeId.VariablesOperations:
                    action = new VariablesAction();
                    break;

                case Enums.ActionTypeId.TextOperations:
                    action = new TextManipulationAction();
                    break;

                case Enums.ActionTypeId.Lable:
                    action = new LabelAction();
                    break;

                case Enums.ActionTypeId.Conditions:
                    action = new ConditionAction();
                    break;

                case Enums.ActionTypeId.Rs232Operations:
                    action = new Rs232Action();
                    break;

                case Enums.ActionTypeId.Timers:
                    action = new TimersAction();
                    break;

                case Enums.ActionTypeId.SSH:
                    action = new SshAction();
                    break;

                case Enums.ActionTypeId.Telnet:
                    action = new TelentAction();
                    break;

                case Enums.ActionTypeId.Sftp:
                    action = new SftpAction();
                    break;

                case Enums.ActionTypeId.Sqlite:
                    action = new SqliteAction();
                    break;

                case Enums.ActionTypeId.Table:
                    action = new TableAction();
                    break;

                case Enums.ActionTypeId.GuiAutomation:
                    action = new AutoItUiAction();
                    break;

                case Enums.ActionTypeId.MessageBox:
                    action = new MessageAction();
                    break;

                case Enums.ActionTypeId.RelayControl:
                    action = new RelayControlAction();
                    break;

                case Enums.ActionTypeId.WaynSim:
                    action = new WaynPumpAction();
                    break;

                case Enums.ActionTypeId.ScriptExecute:
                    action = new ScriptAction();
                    break;

                case Enums.ActionTypeId.Ping:
                    action = new PingAction();
                    break;

                case Enums.ActionTypeId.Horison80PowerSupplyAction:
                    action = new Horison80PowerSupplyAction();
                    break;

                case Enums.ActionTypeId.MotorController:
                    action = new MotorControllerAction();
                    break;

                case Enums.ActionTypeId.FileInfo:
                    action = new FileAction();
                    break;

                case Enums.ActionTypeId.SystemAction:
                    action = new SystemAction();
                    break;

                case Enums.ActionTypeId.EmailAction:
                    action = new EmailAction();
                    break;

                case Enums.ActionTypeId.DateTime:
                    action = new DateTimeAction();
                    break;

                case Enums.ActionTypeId.ListAction:
                    action = new ListAction();
                    break;

                case Enums.ActionTypeId.DictionaryAction:
                    action = new DictionaryAction();
                    break;

                case Enums.ActionTypeId.SwitchAction:
                    action = new SwitchAction();
                    break;

                case Enums.ActionTypeId.ServerComAction:
                    action = new RemoteServerAction();
                    break;
            }

            action.Details.Clear();
            return action;
        }