/********************************************************************************************* * function:Welding setup data * input value: * output: * return value: * *********************************************************************************************/ private void WeldingSetupData(ref IntPtr weldingData, TraceSetup traceInfo, ProductParameter productParameter) { // trace method int offset = 0; int activeMethodId = -1; foreach (S_TraceMethod method in traceInfo.TraceMehodList) { if (method.activeMethod) { activeMethodId = method.id; } } Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (offset++) * sizeof(int)), activeMethodId); // XF_1 to XF_3 motors and z motor Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (offset++) * sizeof(int)), traceInfo.MotorsInfo.BottomMotor.motorLeft); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (offset++) * sizeof(int)), traceInfo.MotorsInfo.BottomMotor.motorFront); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (offset++) * sizeof(int)), traceInfo.MotorsInfo.BottomMotor.motorRight); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (offset++) * sizeof(int)), traceInfo.MotorsInfo.BottomMotor.motorZ); // XY_X to XY_Y motors Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (offset++) * sizeof(int)), traceInfo.MotorsInfo.UpMotor.motorX); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (offset++) * sizeof(int)), traceInfo.MotorsInfo.UpMotor.motorY); // Platform Point double[] platformPoint = new double[10]; platformPoint[0] = traceInfo.PlatformPoint.stepX; platformPoint[1] = traceInfo.PlatformPoint.stepY; platformPoint[2] = traceInfo.PlatformPoint.stepLeft; platformPoint[3] = traceInfo.PlatformPoint.stepRight; platformPoint[4] = traceInfo.PlatformPoint.stepFront; platformPoint[5] = traceInfo.PlatformPoint.stepZ; platformPoint[6] = traceInfo.ZZeroPoint.stepLeft; platformPoint[7] = traceInfo.ZZeroPoint.stepRight; platformPoint[8] = traceInfo.ZZeroPoint.stepFront; platformPoint[9] = traceInfo.ZZeroPoint.stepZ; Marshal.Copy(platformPoint, 0, (IntPtr)((UInt32)weldingData + offset * sizeof(int)), 10); offset = offset * sizeof(int) + 10 * sizeof(double); // 限位 platformPoint[0] = traceInfo.MaxPosition.stepX; platformPoint[1] = traceInfo.MaxPosition.stepY; platformPoint[2] = traceInfo.MaxPosition.stepLeft; platformPoint[3] = traceInfo.MaxPosition.stepRight; platformPoint[4] = traceInfo.MaxPosition.stepFront; platformPoint[5] = traceInfo.MaxPosition.stepMinX; platformPoint[6] = traceInfo.MaxPosition.stepMinY; platformPoint[7] = traceInfo.MaxPosition.stepZ; Marshal.Copy(platformPoint, 0, (IntPtr)((UInt32)weldingData + offset), 8); offset += 8 * sizeof(double); //product parameter float[] outputvalue = new float[1]; outputvalue[0] = productParameter.MinimumVpp; Marshal.Copy(outputvalue, 0, (IntPtr)((UInt32)weldingData + offset), 1); offset += sizeof(float); int productParamOffset = 0; Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.DelayMoveOutReleaseColloidDIo); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.DelayReleaseColloid); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.ReleaseColloid.front); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.ReleaseColloid.left); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.ReleaseColloid.right); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.DelayMoveBackReleaseColloidDIo); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.BakeColloid); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.AdAdjust); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), Convert.ToInt32(productParameter.ReleaseColloidBeforeCoupling)); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), Convert.ToInt32(productParameter.FindCenter)); outputvalue[0] = productParameter.LxLyDownVoltage; Marshal.Copy(outputvalue, 0, (IntPtr)((UInt32)weldingData + (productParamOffset) * sizeof(int) + offset), 1); offset += sizeof(float); outputvalue[0] = productParameter.LzDownVoltage; Marshal.Copy(outputvalue, 0, (IntPtr)((UInt32)weldingData + (productParamOffset) * sizeof(int) + offset), 1); offset += sizeof(float); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.LxLyMin); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.LxLyMax); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.LzMin); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.LzMax); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.ZMin); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.ZMax); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), (int)productParameter.VbrConfig); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.VbrMax); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), productParameter.VbrMin); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), Convert.ToInt32(productParameter.FNSR)); Marshal.WriteInt32((IntPtr)((UInt32)weldingData + (productParamOffset++) * sizeof(int) + offset), Convert.ToInt32(productParameter.TOCAN)); offset += productParamOffset * sizeof(int); // ProductParameter pm = ProductParameter.GetInstance(); float[] apdParams = new float[11]; apdParams[0] = pm.APDParam.Ir_AD_Zero_Value; apdParams[1] = pm.APDParam.Ir_Calib_Value; apdParams[2] = pm.APDParam.Ir_Calib_AD_Value; apdParams[3] = pm.APDParam.Vapd_Max_Value; apdParams[4] = pm.APDParam.Vapd_Max_DA_Value; apdParams[5] = pm.APDParam.Vapd_Min_Value; apdParams[6] = pm.APDParam.Vapd_Min_DA_Value; apdParams[7] = pm.APDParam.Vapd_Upper_Limit; apdParams[8] = pm.APDParam.Vapd_Lower_Limit; apdParams[9] = pm.APDParam.Vbr_Judge; apdParams[10] = pm.APDParam.VbrType; Marshal.Copy(apdParams, 0, (IntPtr)((UInt32)weldingData + offset), 11); offset += sizeof(float) * 11; }
/********************************************************************************************* * function: 发送命令 * input value: * output: * return value: * *********************************************************************************************/ public int SendCommands(CmdType command, ref RetData retData, object sendData) { IntPtr surData = Marshal.AllocHGlobal(1024); int ret = 0; try { switch (command) { case CmdType.CMD_WELDING_SETUP: WeldingSetupData(ref surData, (TraceSetup)((List <object>)sendData)[0], (ProductParameter)((List <object>)sendData)[1]); break; // Test command case CmdType.CMD_OPERATE_ANGLEMOVE: { double[] angleArray = new double[2]; angleArray[0] = ((AngleMove)sendData).angleA; angleArray[1] = ((AngleMove)sendData).angleB; Marshal.Copy(angleArray, 0, surData, 2); } break; case CmdType.CMD_OPERATE_UPMOVE: { double[] upArray = new double[2]; upArray[0] = ((StepMove)sendData).xStep; upArray[1] = ((StepMove)sendData).yStep; Marshal.Copy(upArray, 0, surData, 2); } break; case CmdType.CMD_OPERATE_BOTTOMMOVE: { double[] downArray = new double[4]; downArray[0] = ((StepMove)sendData).leftStep; downArray[1] = ((StepMove)sendData).rightStep; downArray[2] = ((StepMove)sendData).frontStep; downArray[3] = ((StepMove)sendData).zStep; Marshal.Copy(downArray, 0, surData, 4); } break; case CmdType.CMD_SET_PRODUCT_PARAMETER: { int productParamOffset = 0; ProductParameter productParameter = (ProductParameter)sendData; float[] outputvalue = new float[1]; outputvalue[0] = productParameter.MinimumVpp; Marshal.Copy(outputvalue, 0, surData, 1); UInt32 startPos = (UInt32)surData + sizeof(float); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.DelayMoveOutReleaseColloidDIo); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.DelayReleaseColloid); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.ReleaseColloid.front); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.ReleaseColloid.left); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.ReleaseColloid.right); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.DelayMoveBackReleaseColloidDIo); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.BakeColloid); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.AdAdjust); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), Convert.ToInt32(productParameter.ReleaseColloidBeforeCoupling)); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), Convert.ToInt32(productParameter.FindCenter)); outputvalue[0] = productParameter.LxLyDownVoltage; Marshal.Copy(outputvalue, 0, (IntPtr)(startPos + (productParamOffset) * sizeof(int)), 1); startPos += sizeof(float); outputvalue[0] = productParameter.LzDownVoltage; Marshal.Copy(outputvalue, 0, (IntPtr)(startPos + (productParamOffset) * sizeof(int)), 1); startPos += sizeof(float); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.LxLyMin); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.LxLyMax); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.LzMin); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.LzMax); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.ZMin); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.ZMax); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), (int)productParameter.VbrConfig); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.VbrMax); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), productParameter.VbrMin); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), Convert.ToInt32(productParameter.FNSR)); Marshal.WriteInt32((IntPtr)(startPos + (productParamOffset++) * sizeof(int)), Convert.ToInt32(productParameter.TOCAN)); } break; case CmdType.CMD_SET_OUTPUT_IO: { int outPutIoOffset = 0; Marshal.WriteInt32((IntPtr)((UInt32)surData + (outPutIoOffset++) * sizeof(int)), retData.axisNum); Marshal.WriteInt32((IntPtr)((UInt32)surData + (outPutIoOffset++) * sizeof(int)), retData.cardNum); } break; case CmdType.CMD_OPERATE_RESETPLATFORMPOINT: { TraceSetup traceInfo = (TraceSetup)sendData; double[] platformPoint = new double[10]; platformPoint[0] = traceInfo.PlatformPoint.stepX; platformPoint[1] = traceInfo.PlatformPoint.stepY; platformPoint[2] = traceInfo.PlatformPoint.stepLeft; platformPoint[3] = traceInfo.PlatformPoint.stepRight; platformPoint[4] = traceInfo.PlatformPoint.stepFront; platformPoint[5] = traceInfo.PlatformPoint.stepZ; platformPoint[6] = traceInfo.ZZeroPoint.stepLeft; platformPoint[7] = traceInfo.ZZeroPoint.stepRight; platformPoint[8] = traceInfo.ZZeroPoint.stepFront; platformPoint[9] = traceInfo.ZZeroPoint.stepZ; Marshal.Copy(platformPoint, 0, surData, 10); } break; case CmdType.CMD_ADJUST_BAKE_COLLOID: { int outPutIoOffset = 0; Marshal.WriteInt32((IntPtr)((UInt32)surData + (outPutIoOffset++) * sizeof(int)), retData.axisNum); } break; case CmdType.CMD_ADJUST_RELEASE_COLLOID: case CmdType.CMD_ADJUST_RELEASE_COLLOID2: { int outPutIoOffset = 0; Marshal.WriteInt32((IntPtr)((UInt32)surData + (outPutIoOffset++) * sizeof(int)), ((int)retData.coordinate.stepFront)); Marshal.WriteInt32((IntPtr)((UInt32)surData + (outPutIoOffset++) * sizeof(int)), ((int)retData.coordinate.stepLeft)); Marshal.WriteInt32((IntPtr)((UInt32)surData + (outPutIoOffset++) * sizeof(int)), ((int)retData.coordinate.stepRight)); } break; case CmdType.CMD_ADJUST_VAL_OUTPUT: { float[] outputvalue = new float[1]; outputvalue[0] = (float)retData.coordinate.stepFront; Marshal.Copy(outputvalue, 0, surData, 1); } break; case CmdType.CMD_ADJUST_VBR_CURRENT: { float[] current = new float[1]; current[0] = (float)retData.coordinate.stepFront; Marshal.Copy(current, 0, surData, 1); } break; case CmdType.CMD_APD_PARM: { ProductParameter pm = ProductParameter.GetInstance(); float[] apdParams = new float[11]; apdParams[0] = pm.APDParam.Ir_AD_Zero_Value; apdParams[1] = pm.APDParam.Ir_Calib_Value; apdParams[2] = pm.APDParam.Ir_Calib_AD_Value; apdParams[3] = pm.APDParam.Vapd_Max_Value; apdParams[4] = pm.APDParam.Vapd_Max_DA_Value; apdParams[5] = pm.APDParam.Vapd_Min_Value; apdParams[6] = pm.APDParam.Vapd_Min_DA_Value; apdParams[7] = pm.APDParam.Vapd_Upper_Limit; apdParams[8] = pm.APDParam.Vapd_Lower_Limit; apdParams[9] = pm.APDParam.Vbr_Judge; apdParams[10] = (float)pm.APDParam.VbrType; Marshal.Copy(apdParams, 0, surData, 11); } break; default: break; } ret = UICommands(Convert.ToInt32(command), surData); switch (command) { case CmdType.CMD_INIT_MPC2810: DealWithInitMPCData(ref retData, ref surData, ret); break; case CmdType.CMD_GET_TRACE_METHOD: DealWithTraceMethodsData(ref retData, ref surData, ret); break; case CmdType.CMD_WELDING_SETUP: if (ret < 0) { retData.errMsg = "耦合配置错误,ID=" + ret.ToString(); } break; case CmdType.CMD_GET_COORDINATE: DealWithInitCoordinateData(ref retData, ref surData); break; case CmdType.CMD_GET_VERSION: retData.str = Marshal.PtrToStringAnsi(surData); break; case CmdType.CMD_SET_PRODUCT_PARAMETER: if (ret < 0) { retData.errMsg = "工艺参数配置错误,ID=" + ret.ToString(); } break; case CmdType.CMD_GET_VPP: float[] vpp = new float[1]; Marshal.Copy(surData, vpp, 0, 1); retData.coordinate.stepFront = vpp[0]; break; default: break; } } catch (Exception ee) { string error = ee.Message; } Marshal.FreeHGlobal(surData); return(ret); }