Exemplo n.º 1
0
        /// <summary>
        /// 0x40读取监控数据
        /// </summary>
        /// <returns></returns>
        public MonitorData GetMonitorData()
        {
            try
            {
                MonitorData data = new MonitorData();

                SendCommand sendCmd40 = new SendCommand(CommandId.SystemMonitor, CommandExtendId.Read);
                RecvCommand recvCmd40 = (RecvCommand)PortManager.GetInstance().Send(InsName, sendCmd40);
                CheckRecvCommand(recvCmd40);
                if (recvCmd40 != null)
                {
                    data.Motor1Switch        = recvCmd40.GetByte(ParamId.SystemMonitor_ReadResponse_Motor1Status);
                    data.Motor1Status        = recvCmd40.GetByte(ParamId.SystemMonitor_ReadResponse_Motor1Result);
                    data.Motor1completeSteps = (int)recvCmd40.GetULong(ParamId.SystemMonitor_ReadResponse_Motor1CompleteSteps);
                    data.Motor1Steps         = (int)recvCmd40.GetULong(ParamId.SystemMonitor_ReadResponse_Motor1SumSteps);

                    data.Motor2Switch        = recvCmd40.GetByte(ParamId.SystemMonitor_ReadResponse_Motor2Status);
                    data.Motor2Status        = recvCmd40.GetByte(ParamId.SystemMonitor_ReadResponse_Motor2Result);
                    data.Motor2completeSteps = (int)recvCmd40.GetULong(ParamId.SystemMonitor_ReadResponse_Motor2CompleteSteps);
                    data.Motor2Steps         = (int)recvCmd40.GetULong(ParamId.SystemMonitor_ReadResponse_Motor2SumSteps);
                    return(data);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public ResponseCode SetMotorSteps(byte controlMode1, byte direction1, int totalSteps1, byte controlMode2, byte direction2, int totalSteps2)
        {
            SendCommand sendCmd60 = new SendCommand(CommandId.ControlConfig, CommandExtendId.Write);

            sendCmd60.SetParamValid(ParamId.ControlConfig_ReadWrite_Select, true);
            sendCmd60.SetValue(ParamId.ControlConfig_ReadWrite_Select, 0x60);

            sendCmd60.SetParamValid(ParamId.ControlConfig_ReadWrite_ControlMode1, true);
            sendCmd60.SetValue(ParamId.ControlConfig_ReadWrite_ControlMode1, controlMode1);

            sendCmd60.SetParamValid(ParamId.ControlConfig_ReadWrite_Direction1, true);
            sendCmd60.SetValue(ParamId.ControlConfig_ReadWrite_Direction1, direction1);

            sendCmd60.SetParamValid(ParamId.ControlConfig_ReadWrite_TotalSteps1, true);
            sendCmd60.SetValue(ParamId.ControlConfig_ReadWrite_TotalSteps1, totalSteps1);

            sendCmd60.SetParamValid(ParamId.ControlConfig_ReadWrite_ControlMode2, true);
            sendCmd60.SetValue(ParamId.ControlConfig_ReadWrite_ControlMode2, controlMode2);

            sendCmd60.SetParamValid(ParamId.ControlConfig_ReadWrite_Direction2, true);
            sendCmd60.SetValue(ParamId.ControlConfig_ReadWrite_Direction2, direction2);

            sendCmd60.SetParamValid(ParamId.ControlConfig_ReadWrite_TotalSteps2, true);
            sendCmd60.SetValue(ParamId.ControlConfig_ReadWrite_TotalSteps2, totalSteps2);

            RecvCommand  recvCmd60   = (RecvCommand)PortManager.GetInstance().Send(InsName, sendCmd60);
            var          v60         = recvCmd60.GetBytes();
            ResponseCode responeCode = new ResponseCode();

            responeCode.Code = recvCmd60.GetBytes()[0];
            return(responeCode);
        }
Exemplo n.º 3
0
 //发送函数
 public byte[] SendDirectCommand(byte[] data, string portName)
 {
     byte[] rev = null;
     try
     {
         PortManager.GetInstance().GetPipe(laserPipeName).GetBusProperty().GetProperty("port").value = portName;
         PortManager.GetInstance().Save();  //不保存打开,当前串口设置失效
         PortManager.GetInstance().Reset(); //解决配置中串口不存在时,后前无法open的bug
         PortManager.GetInstance().GetPipe(laserPipeName).Open();
         LogHelper.GetLogger <SerialPortHelper>().Error("Send Data: " + ByteHelper.Byte2ReadalbeXstring(data));
         SimpleProtocolData newData = new SimpleProtocolData(data);
         object             recv    = PortManager.GetInstance().Send(LARCommandHelper.InsName1, newData);
         if (recv != null)
         {
             rev = ((ByteArrayWrap)recv).GetBytes();
             LogHelper.GetLogger <SerialPortHelper>().Error("Reveived Data: " + ByteHelper.Byte2ReadalbeXstring(data));
         }
     }
     catch (Exception ex)
     {
         LogHelper.GetLogger <SerialPortHelper>().Error("error message: " + ex.Message);
         LogHelper.GetLogger <SerialPortHelper>().Error("error stacktrace: " + ex.StackTrace);
     }
     return(rev);
 }
Exemplo n.º 4
0
 public void SaveLaserPort(string comPort)
 {
     if (PortManager.GetInstance().pipes[laserPipeName] != null &&
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusName) != null &&
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusName).GetProperty(laserBusPort) != null)
     {
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusName).GetProperty(laserBusPort).value = comPort;
         Program.SysConfig.MotorPort = comPort;
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusName).GetProperty(laserBusPort).value    = "9600";
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusName).GetProperty(laserBusDataBit).value = "8";
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusName).GetProperty(laserBusStopBit).value = "1";
     }
     //PC
     if (PortManager.GetInstance().pipes[laserPipeName] != null &&
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusProtocolName) != null &&
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusProtocolName).GetProperty(laserBusProtocolRouterPort) != null &&
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusProtocolName).GetProperty(laserBusProtocolRouterPort).GetProperty(pcAddress) != null)
     {
         PortManager.GetInstance().pipes[laserPipeName].GetProperty(laserBusProtocolName).GetProperty(laserBusProtocolRouterPort).GetProperty(pcAddress).value = "0xFE";
     }
     PortManager.GetInstance().Save();
     PortManager.GetInstance().Reset();
 }