其他分享
首页 > 其他分享> > 2021-07-28

2021-07-28

作者:互联网

一个码垛的自动打包项目

本程序设计实现,机器人与码垛方式与物体的码垛定位。只提供个人学习,
禁止转载。

在这里插入图片描述

USE [PalletDB]
GO
/****** Object:  StoredProcedure [dbo].[AddBarCode]    Script Date: 2021/7/28 10:08:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddBarCode]
-- Add the parameters for the stored procedure here
	@barcode nvarchar(500),
	@PT nvarchar(50),
	@MSG VARCHAR(200) OUTPUT
AS

----调试
--DECLARE @barcode nvarchar(500);
--DECLARE @PT nvarchar(50);
--set @barcode = '52391123454';
--set @PT = '192.158.3.8';
DECLARE @PalletSum1 INT = 0;
DECLARE @PalletSum2 INT = 0;
DECLARE @PalletID VARCHAR(200) = '';
DECLARE @REPETITION int = 0;
BEGIN
	BEGIN TRY
		--开启事务
		BEGIN TRAN
			BEGIN
				--查找当前的PID
				SELECT @PalletID = [PalletID] FROM[PalletDB].[dbo].[Pallet] WHERE [BarCodeHead] = LEFT(@barcode,5)  AND [PT] = @PT AND [IsAutomaticEnd] = -1;
				print 'PalletID:' + @PalletID;
				IF LEN(@PalletID)>0
					BEGIN
						SELECT @REPETITION = COUNT(1) FROM [PalletDB].[dbo].[PalletStacking]  WHERE[PalletID] = @PalletID AND [BarCode] = @barcode;
						IF @REPETITION >0
						BEGIN
							PRINT '条码['+@barcode +']重复码垛';
							SET @MSG =  '条码['+@barcode +']重复码垛';
						END
						ELSE BEGIN
							--添加编码到对应位置
							UPDATE [PalletDB].[dbo].[PalletStacking] SET [BarCode] = @barcode ,[Note] = '成功'  WHERE[PalletID] =  @PalletID AND[Coordinates] = ( SELECT TOP 1  [Coordinates] FROM[PalletDB].[dbo].[PalletStacking] WHERE[BarCode] IS NULL);
							--整板装完更新整板的状态为自动结束1
							SELECT @PalletSum1 = COUNT([PalletID]) FROM [PalletDB].[dbo].[PalletStacking] WHERE[PalletID] = @PalletID AND [BarCode] IS NULL ;
							print 'OK,码垛剩余空位:'+CONVERT(VARCHAR(20) ,@PalletSum1)+'个';
							SET @MSG =   'OK,码垛剩余空位:'+CONVERT(VARCHAR(20) ,@PalletSum1)+'个';
							--IsAutomaticEnd -1:默认值,0:手动结束,1:自动结束
							IF(@PalletSum1 = 0)
							BEGIN
								UPDATE  [PalletDB].[dbo].[Pallet] SET [IsAutomaticEnd] = 1  WHERE [PalletID] = @PalletID  AND [IsAutomaticEnd] = -1;
								print 'OK,码垛完成';
								SET @MSG =   'OK,码垛完成'; 
							END
							
						END
					END
				ELSE BEGIN 
					print '没有对应的PalletID[整板编号]';
					SET @MSG = '没有对应的PalletID[整板编号]';
				END
				COMMIT TRAN;
			END
	END TRY
	BEGIN CATCH
		IF @@TRANCOUNT > 0
		BEGIN
			SET @MSG = '数据异常:' + 'barcode:' + @barcode + ' PT' +@PT ;
			ROLLBACK TRAN
		END 
	END CATCH
END

标签:BEGIN,END,07,--,barcode,28,PalletID,2021,码垛
来源: https://blog.csdn.net/zgp11zgp/article/details/119172029