/// <summary> /// 移动 -- 相对位置 (以当前步数为基础) /// </summary> /// <param name="axis">电机轴</param> /// <param name="steps">步数</param> /// <returns></returns> public bool MoveRef(Axis axis, int steps) { int indexBoard = (int)axis / MAX_AXIS_CHANNEL; //板卡索引 int indexAxis = (int)axis % MAX_AXIS_CHANNEL; //板卡内轴号索引 if (!IsBoardConnected((Board)indexBoard)) { return(false); } Message.MakeSendArrayByCode((byte)ArmCommandCode.SetAxisStepsRef, ref m_SendMeas); int DataIndex = Message.MessageCommandIndex + 1; m_SendMeas[DataIndex] = (byte)indexAxis; m_SendMeas[DataIndex + 1] = (byte)(steps & 0xffU); m_SendMeas[DataIndex + 2] = (byte)((steps >> 8) & 0xffU); m_SendMeas[DataIndex + 3] = (byte)((steps >> 16) & 0xffU); m_SendMeas[DataIndex + 4] = (byte)((steps >> 24) & 0xffU); m_SendMeas[Message.MessageSumCheck] = MyMath.CalculateSum(m_SendMeas, Message.MessageLength); m_MyTcpClientArm[indexBoard].ClientWrite(m_SendMeas); return(true); }
public static void ProcessTcpServerMessage() { if (m_MyTcpServer != null) { while (m_MyTcpServer.m_RecvMeasQueue.Count != 0) { TcpMeas TempMeas = m_MyTcpServer.m_RecvMeasQueue.Dequeue(); if (TempMeas != null && TempMeas.Client != null) { if (TempMeas.MeasType == TcpMeasType.MEAS_TYPE_PLC) // 处理和PLC之间的消息 { if (TempMeas.MeasCode == (byte)Message.MessageCodePLC.GetCurStationState) { NetworkStream stream = TempMeas.Client.GetStream(); TempMeas.Param[7] = GetStationCurState(); //工作站运行状态 TempMeas.Param[8] = GetStationSalverState(); //物料盘的状态 TempMeas.Param[TempMeas.Param.Length - 2] = MyMath.CalculateSum(TempMeas.Param, TempMeas.Param.Length); //校验和 stream.Write(TempMeas.Param, 0, TempMeas.Param.Length); } } else if (TempMeas.MeasType == TcpMeasType.MEAS_TYPE_MIS) //处理和MIS之间的消息 { } } } } }
//设置单片机控制板的IO public bool SetArmControlBoardIo(Board board, ARM_OutputPoint Io, IOValue Value) { if (!IsBoardConnected(board)) { return(false); } int data1 = 8; //1~8输出口使能控制字节, 最大是0x80 int data2 = 16; int data3 = 24; int data4 = 32; const int CommandIndex = Message.MessageCommandIndex; Message.MakeSendArrayByCode((byte)ArmCommandCode.SetOutput, ref m_SendMeas); //根据Type, Value 设置使能位和数据 int TempIo = (int)Io; int ControlIndex = CommandIndex + 1; byte ControlValue = 0; byte IoData = 0; if (TempIo <= data1) { ControlIndex = CommandIndex + 1; ControlValue = (byte)(0x01 << (TempIo - 1)); IoData = (byte)(((byte)Value) << (TempIo - 1)); } else if (TempIo > data1 && TempIo <= data2) { ControlIndex = CommandIndex + 2; ControlValue = (byte)(0x01 << (TempIo - data1 - 1)); IoData = (byte)(((byte)Value) << (TempIo - data1 - 1)); } else if (TempIo > data2 && TempIo <= data3) { ControlIndex = CommandIndex + 3; ControlValue = (byte)(0x01 << (TempIo - data2 - 1)); IoData = (byte)(((byte)Value) << (TempIo - data2 - 1)); } else if (TempIo > data3 && TempIo <= data4) { ControlIndex = CommandIndex + 4; ControlValue = (byte)(0x01 << (TempIo - data3 - 1)); IoData = (byte)(((byte)Value) << (TempIo - data3 - 1)); } m_SendMeas[ControlIndex] = ControlValue; m_SendMeas[ControlIndex + 4] = IoData; m_SendMeas[Message.MessageSumCheck] = MyMath.CalculateSum(m_SendMeas, Message.MessageLength); m_MyTcpClientArm[(int)board].ClientWrite(m_SendMeas); return(true); }
//给单片机发送电机轴相关的指令,axis 轴号, code命令 public bool SendCommandToArmWithAxis(Axis axis, ArmCommandCode Code) { int indexBoard = (int)axis / MAX_AXIS_CHANNEL; //板卡索引 int indexAxis = (int)axis % MAX_AXIS_CHANNEL; //板卡内轴号索引 if (!IsBoardConnected((Board)indexBoard)) { return(false); } Message.MakeSendArrayByCode((byte)Code, ref m_SendMeas); m_SendMeas[Message.MessageCommandIndex + 1] = (byte)indexAxis; m_SendMeas[Message.MessageSumCheck] = MyMath.CalculateSum(m_SendMeas, Message.MessageLength); m_MyTcpClientArm[indexBoard].ClientWrite(m_SendMeas); return(true); }
/// <summary> /// 设置电机轴速度参数 /// </summary> /// <param name="axis">轴号</param> /// <param name="velLow">初速度</param> /// <param name="velHigh">运行速度</param> /// <param name="acc">加速度</param> /// <param name="dec">减速度</param> /// <param name="Default">是否为默认值</param> public bool SetSpeedParam(Axis axis, int velLow, int velHigh, int acc, int dec, bool Default) { int indexBoard = (int)axis / MAX_AXIS_CHANNEL; //板卡索引 int indexAxis = (int)axis % MAX_AXIS_CHANNEL; //板卡内轴号索引 if (!IsBoardConnected((Board)indexBoard)) { return(false); } ArmCommandCode Code = Default ? ArmCommandCode.SetAxisParametersDefault : ArmCommandCode.SetAxisParameters; Message.MakeSendArrayByCode((byte)Code, ref m_SendMeas); int DataIndex = Message.MessageCommandIndex + 1; m_SendMeas[DataIndex] = (byte)indexAxis; m_SendMeas[DataIndex + 1] = (byte)(velLow & 0xffU); m_SendMeas[DataIndex + 2] = (byte)((velLow >> 8) & 0xffU); m_SendMeas[DataIndex + 3] = (byte)((velLow >> 16) & 0xffU); m_SendMeas[DataIndex + 4] = (byte)((velLow >> 24) & 0xffU); m_SendMeas[DataIndex + 5] = (byte)(velHigh & 0xffU); m_SendMeas[DataIndex + 6] = (byte)((velHigh >> 8) & 0xffU); m_SendMeas[DataIndex + 7] = (byte)((velHigh >> 16) & 0xffU); m_SendMeas[DataIndex + 8] = (byte)((velHigh >> 24) & 0xffU); m_SendMeas[DataIndex + 9] = (byte)(acc & 0xffU); m_SendMeas[DataIndex + 10] = (byte)((acc >> 8) & 0xffU); m_SendMeas[DataIndex + 11] = (byte)((acc >> 16) & 0xffU); m_SendMeas[DataIndex + 12] = (byte)((acc >> 24) & 0xffU); m_SendMeas[DataIndex + 13] = (byte)(dec & 0xffU); m_SendMeas[DataIndex + 14] = (byte)((dec >> 8) & 0xffU); m_SendMeas[DataIndex + 15] = (byte)((dec >> 16) & 0xffU); m_SendMeas[DataIndex + 16] = (byte)((dec >> 24) & 0xffU); m_SendMeas[Message.MessageSumCheck] = MyMath.CalculateSum(m_SendMeas, Message.MessageLength); m_MyTcpClientArm[indexBoard].ClientWrite(m_SendMeas); return(true); }