public IDevice GoTo(int code) { byte [] result; switch (code) { case 0: OutputCommand cmdOpen = new OutputCommand(0x03, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Open); _port.Write(_serialize.Serialize <OutputCommand>(cmdOpen)) .Read(out result); break; case 1: OutputCommand cmdStop_2 = new OutputCommand(0x03, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Shut); _port.Write(_serialize.Serialize <OutputCommand>(cmdStop_2)) .Read(out result); break; case 2: break; case 3: break; case 4: break; } return(this); }
private void WriteToResponse(TransportClassMainAshx oTransportClassMainAshx, ErrorTypes eError, List <string> aUrls, NameValueCollection aNameValueCollection) { HttpContext oHttpContext = oTransportClassMainAshx.m_oHttpContext; AsyncCallback oAsyncCallback = oTransportClassMainAshx.m_oAsyncCallback; OutputCommand oOutputCommand = new OutputCommand(); if (null != aNameValueCollection) { for (int i = 0, length = aNameValueCollection.Count; i < length; ++i) { oOutputCommand.input.Add(aNameValueCollection.GetKey(i), aNameValueCollection.Get(i)); } } oOutputCommand.urls = aUrls; oOutputCommand.error = (int)eError; oOutputCommand.type = (int)PostMessageType.UploadImage; JavaScriptSerializer serializer = new JavaScriptSerializer(); StringBuilder sb = new StringBuilder(); serializer.Serialize(oOutputCommand, sb); string sJson = sb.ToString(); oHttpContext.Response.Write("<html><head><script type=\"text/javascript\">function load(){ parent.postMessage(\"" + sJson.Replace("\"", "\\\"") + "\", '*'); }</script></head><body onload='load()'></body></html>"); oAsyncCallback.Invoke(new AsyncOperationData(null)); }
/// <summary> /// 输入状态监测 /// </summary> /// <returns></returns> public IDevice SetMonitor() { byte[] result; OutputCommand cmd = new OutputCommand(0x04, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Open); _port.Write(_serialize.Serialize <OutputCommand>(cmd)) .Read(out result); bool isopen = true; while (isopen) { byte[] resultStue; StateCommand cmd1 = new StateCommand(0x04); _port.Write(_serialize.Serialize <StateCommand>(cmd1)) .Read(out resultStue); Logger.LogInfo(resultStue.ToString()); if (null != resultStue) { byte[] resultStuestop; var res = _serialize.Deserialize <StateResult>(resultStue); Logger.LogInfo(res.State.ToString()); switch (res.State) { case eAGVState.BackupOff: { OutputCommand cmd2 = new OutputCommand(0x04, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Shut); _port.Write(_serialize.Serialize <OutputCommand>(cmd2)) .Read(out resultStuestop); Logger.LogInfo("BackupOff"); isopen = false; } break; case eAGVState.BackupFPatrol: { OutputCommand cmd2 = new OutputCommand(0x04, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Shut); _port.Write(_serialize.Serialize <OutputCommand>(cmd2)) .Read(out resultStuestop); Logger.LogInfo("BackupFPatrol"); isopen = false; } break; case eAGVState.BackupBPatrol: { OutputCommand cmd2 = new OutputCommand(0x04, eSwitchNumber.SpareOutput_1, AGV.eSwitchStates.Shut); _port.Write(_serialize.Serialize <OutputCommand>(cmd2)) .Read(out resultStuestop); Logger.LogInfo("BackupBPatrol"); isopen = false; } break; } } Thread.Sleep(5000); } return(this); }
protected OutputCommand GetOutputCommand(string name = "oc1", string key = "oc1") { var outputCommand = new OutputCommand(); outputCommand.Name = name; outputCommand.Key = key; SetAuditParams(outputCommand); outputCommand.Parameters.Add(GetParameter("param1", "param1")); return(outputCommand); }
/// <summary> ///关闭 反 /// </summary> /// <returns></returns> public IDevice SetOutput_fan_close(byte car) { try { lock (_port) { byte[] result; OutputCommand cmd = new OutputCommand(car, eSwitchNumber.SpareOutput_2, AGV.eSwitchStates.Shut); _port.Write(_serialize.Serialize <OutputCommand>(cmd)) .Read(out result); } } catch { } return(this); }
protected OutputCommand GetOutputCommand() { var outputCommand = new OutputCommand() { Id = Guid.NewGuid().ToId(), Key = "outputone", Name = "Output Command One", CreatedBy = EntityHeader.Create(Guid.NewGuid().ToId(), "me"), LastUpdatedBy = EntityHeader.Create(Guid.NewGuid().ToId(), "me"), CreationDate = DateTime.UtcNow.ToJSONString(), LastUpdatedDate = DateTime.UtcNow.ToJSONString(), }; outputCommand.Parameters.Add(GetValidParameter()); return(outputCommand); }
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) { TransportClassMainAshx oTransportClassMainAshx = new TransportClassMainAshx(context, cb); AsyncContextReadOperation asynch = new AsyncContextReadOperation(); TransportClassContextRead oTransportClassContextRead = new TransportClassContextRead(oTransportClassMainAshx, asynch); try { asynch.ReadContextBegin(context.Request.InputStream, ReadContext, oTransportClassContextRead); } catch(Exception e) { OutputCommand oOutputCommand = new OutputCommand(ErrorTypes.Unknown); WriteOutputCommand(new TransportClassMainAshx(context, cb), oOutputCommand); _log.Error("Exception catched in BeginProcessRequest:", e); } return new AsyncOperationData(extraData); }
public void InputMessage(string message) { string argument = ""; UserCommand command = null; foreach (UserCommand cmd in UserCommands) { if (message.Contains(cmd.CommandName)) { command = cmd; string[] str = message.Split(char.Parse(" ")); //Debug.Log("contains " + message + " LEN " + str.Length); //if(str.Length==2){ // for(int i = 1;i<str.Length;i++){ // argument += str[i]; // } //} //else { for (int i = 1; i < str.Length - 1; i++) { argument += str[i] + " "; } argument += str[str.Length - 1]; //} } } if (command == null) { //do message OutputMessage.Invoke(message); } else { //do command //Debug.Log("function " + command.CommandName + " argument " + argument,gameObject); command.Command.Invoke(argument); OutputCommand.Invoke(command.CommandName + " " + argument); } }
/// <summary> /// 设置输出/开关状态(断电不保存) ok /// </summary> /// <returns></returns> public IDevice SetOutputCommand() { byte[] result; OutputCommand cmd = new OutputCommand(0x02, eSwitchNumber.AcoustoopticAlarm, AGV.eSwitchStates.Shut); _port.Write(_serialize.Serialize <OutputCommand>(cmd)) .Read(out result); if (null != result) { if (result.Length > 2) { if (0xFF == result[1]) { var res = _serialize.Deserialize <ErrorReportingResult>(result); } else { var res = _serialize.Deserialize <OutputResult>(result); } } } return(this); }
private void WriteOutputCommand(TransportClassMainAshx oTransportClassMainAshx, OutputCommand oOutputCommand) { HttpContext oHttpContext = oTransportClassMainAshx.m_oHttpContext; AsyncCallback fAsyncCallback = oTransportClassMainAshx.m_oAsyncCallback; oHttpContext.Response.ContentType = "text/xml"; oHttpContext.Response.Charset = "UTF-8"; string sXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><FileResult>"; if (null != oOutputCommand.m_sFileUrl) { sXml += string.Format("<FileUrl>{0}</FileUrl>", HttpUtility.HtmlEncode(oOutputCommand.m_sFileUrl)); } if (null != oOutputCommand.m_sPercent) { sXml += string.Format("<Percent>{0}</Percent>", oOutputCommand.m_sPercent); } if (true == oOutputCommand.m_bIsEndConvert.HasValue) { sXml += string.Format("<EndConvert>{0}</EndConvert>", oOutputCommand.m_bIsEndConvert.Value.ToString()); } if (ErrorTypes.NoError != oOutputCommand.m_eError) { sXml += string.Format("<Error>{0}</Error>", Utils.mapAscServerErrorToOldError(oOutputCommand.m_eError).ToString()); } sXml += "</FileResult>"; oHttpContext.Response.Write(sXml); fAsyncCallback.Invoke(new AsyncOperationData(null)); }
private void SaveCommand(TransportClassContextRead oTransportClassContextRead, InputCommand cmd) { _log.DebugFormat("SaveCommand, savetype={0}.", cmd.savetype); switch (cmd.savetype) { case c_sSaveTypePartStart: case c_sSaveTypeCompleteAll: { _log.Debug("cmd.savetype = SaveTypes.PartStart or SaveTypes.CompleteAll."); TaskResultData oTaskResultData = new TaskResultData(); oTaskResultData.sKey = cmd.id; oTaskResultData.sFormat = cmd.format; oTaskResultData.eStatus = FileStatus.WaitQueue; ITaskResultInterface oTaskResult = TaskResult.NewTaskResult(); TransportClassTaskResult oTransportClassTaskResult = new TransportClassTaskResult(oTransportClassContextRead, cmd, oTaskResult); oTaskResult.AddRandomKeyBegin(cmd.id, oTaskResultData, TaskResultAddRandomKeyAsyncCallback, oTransportClassTaskResult); break; } case c_sSaveTypePart: case c_sSaveTypeComplete: default: { _log.Debug("cmd.savetype = SaveTypes.Part or SaveTypes.Complete or default."); JavaScriptSerializer serializer = new JavaScriptSerializer(); OutputSavePartData oOutputSavePartData = new OutputSavePartData(cmd.savekey, cmd.outputformat.Value); OutputCommand oOutputCommand = new OutputCommand("savepart", serializer.Serialize(oOutputSavePartData)); string sFilename = "Editor"; string sExt = ".bin"; Storage oStorage = new Storage(); TransportClassStorage2 oTransportClassStorage2 = new TransportClassStorage2(oTransportClassContextRead, cmd, oStorage, null, cmd.savekey, sFilename, sExt, oOutputCommand); oStorage.GetTreeNodeBegin(cmd.savekey, GetTreeNodeCallback, oTransportClassStorage2); break; } } }
private void GetSettingsCommand(TransportClassContextRead oTransportClassContextRead, InputCommand cmd) { OutputSettingsData oOutputSettingsData = new OutputSettingsData(cmd.format); JavaScriptSerializer oJsSerializer = new JavaScriptSerializer(); OutputCommand oOutputCommand = new OutputCommand("getsettings", oJsSerializer.Serialize(oOutputSettingsData)); WriteOutputCommand(oTransportClassContextRead, oOutputCommand); }
private void WriteOutputCommand(TransportClassMainAshx oTransportClassMainAshx, OutputCommand oOutputCommand) { HttpContext oHttpContext = oTransportClassMainAshx.m_oHttpContext; AsyncCallback fAsyncCallback = oTransportClassMainAshx.m_oAsyncCallback; oHttpContext.Response.ContentType = "text/plain"; string sJson = new JavaScriptSerializer().Serialize(oOutputCommand); byte[] aJsonUtf8 = Encoding.UTF8.GetBytes(sJson); oHttpContext.Response.OutputStream.Write(aJsonUtf8, 0, aJsonUtf8.Length); fAsyncCallback.Invoke(new AsyncOperationData(null)); }
private void WriteToResponse(TransportClassMainAshx oTransportClassMainAshx, ErrorTypes eError, List<string> aUrls, NameValueCollection aNameValueCollection) { HttpContext oHttpContext = oTransportClassMainAshx.m_oHttpContext; AsyncCallback oAsyncCallback = oTransportClassMainAshx.m_oAsyncCallback; OutputCommand oOutputCommand = new OutputCommand(); if (null != aNameValueCollection) { for (int i = 0, length = aNameValueCollection.Count; i < length; ++i) oOutputCommand.input.Add(aNameValueCollection.GetKey(i), aNameValueCollection.Get(i)); } oOutputCommand.urls = aUrls; oOutputCommand.error = (int)eError; oOutputCommand.type = (int)PostMessageType.UploadImage; JavaScriptSerializer serializer = new JavaScriptSerializer(); StringBuilder sb = new StringBuilder(); serializer.Serialize(oOutputCommand, sb); string sJson = sb.ToString(); oHttpContext.Response.Write("<html><head><script type=\"text/javascript\">function load(){ parent.postMessage(\"" + sJson.Replace("\"", "\\\"") + "\", '*'); }</script></head><body onload='load()'></body></html>"); oAsyncCallback.Invoke(new AsyncOperationData(null)); }
private void WriteOutputCommand(TransportClassMainAshx oTransportClassMainAshx, OutputCommand oOutputCommand) { HttpContext oHttpContext = oTransportClassMainAshx.m_oHttpContext; AsyncCallback fAsyncCallback = oTransportClassMainAshx.m_oAsyncCallback; oHttpContext.Response.ContentType = "text/xml"; oHttpContext.Response.Charset = "UTF-8"; string sXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><FileResult>"; if (null != oOutputCommand.m_sFileUrl) sXml += string.Format("<FileUrl>{0}</FileUrl>", HttpUtility.HtmlEncode(oOutputCommand.m_sFileUrl)); if (null != oOutputCommand.m_sPercent) sXml += string.Format("<Percent>{0}</Percent>", oOutputCommand.m_sPercent); if (true == oOutputCommand.m_bIsEndConvert.HasValue) sXml += string.Format("<EndConvert>{0}</EndConvert>", oOutputCommand.m_bIsEndConvert.Value.ToString()); if (ErrorTypes.NoError != oOutputCommand.m_eError) sXml += string.Format("<Error>{0}</Error>", Utils.mapAscServerErrorToOldError(oOutputCommand.m_eError).ToString()); sXml += "</FileResult>"; oHttpContext.Response.Write(sXml); fAsyncCallback.Invoke(new AsyncOperationData(null)); }
public TransportClassStorage2(TransportClassMainAshx oTransportClassMainAshx, InputCommand oInputCommand, Storage oStorage, Stream stream, string sKey, string sFilename, string sExt, OutputCommand oOutputCommand) : base(oTransportClassMainAshx, oInputCommand, oStorage, stream, sKey) { m_sFilename = sFilename; m_sExt = sExt; m_oOutputCommand = oOutputCommand; }
public void Recieve() { int recieveCount = 0; while (!_cts.IsCancellationRequested) { var re = _port.ReadByte(); switch (recieveCount) { case 0: if (re == 'C') { OutputCommand?.Clear(); OutputCommand = new CommandModel(); OutputCommand.SyncCode1 = Convert.ToChar(re).ToString(); recieveCount++; } else { recieveCount = 0; } break; case 1: if (re == 'O') { OutputCommand.SyncCode2 = Convert.ToChar(re).ToString(); recieveCount++; } else { recieveCount = 0; } break; case 2: if (re == 'M') { OutputCommand.SyncCode3 = Convert.ToChar(re).ToString(); recieveCount++; } else { recieveCount = 0; } break; case 3: recieveCount++; OutputCommand.ControlCode = re.ToString("x2"); break; case 4: recieveCount++; OutputCommand.ControlVal1 = re.ToString("x2"); break; case 5: recieveCount++; OutputCommand.ControlVal2 = re.ToString("x2"); var command = new CommandModel(); command.SyncCode1 = OutputCommand.SyncCode1; command.SyncCode2 = OutputCommand.SyncCode2; command.SyncCode3 = OutputCommand.SyncCode3; command.ControlCode = OutputCommand.ControlCode; command.ControlVal1 = OutputCommand.ControlVal1; command.ControlVal2 = OutputCommand.ControlVal2; _commandQueue.Enqueue(command); break; default: recieveCount = 0; break; } } }