using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.Windows.Forms;
|
using System.Runtime.InteropServices;
|
using System.Data.SqlClient;
|
using System.Collections;
|
using System.IO;
|
using com.force.json;
|
using System.Net;
|
using System.Net.NetworkInformation;
|
using Oracle.ManagedDataAccess.Client;
|
|
namespace WCS
|
{
|
public class Common
|
{
|
/// <summary>
|
/// 系统路径
|
/// </summary>
|
public static string filepath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
//public static string exepath = Application.ExecutablePath;
|
//public static string path = filepath.Substring(0, filepath.LastIndexOf('\\'));
|
|
/// <summary>
|
/// 系统配置文件
|
/// </summary>
|
public static string sysinipath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\System.ini";
|
//public static string cmdinipath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\Command.ini";
|
//public static string inipath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\labels\\";
|
//public static string pbdpath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\report.pbd";
|
|
/// <summary>
|
/// 公司名称
|
/// </summary>
|
public static string gs_companyName = "";
|
|
/// <summary>
|
/// 系统图片路径
|
/// </summary>
|
public static string picpath = filepath.Substring(0, filepath.LastIndexOf('\\')) + "\\image\\";
|
|
/// <summary>
|
/// 系统信号,弹出提示框后根据选择传值回主窗口,后期考虑窗口间传参
|
/// </summary>
|
public static bool sysinfo = false;
|
//public static bool logout = false;
|
//public static bool sameinfo = false;
|
|
/// <summary>
|
/// ASRS数据库连接字符串
|
/// </summary>
|
public static string sqlcon = "Initial Catalog=klsasrs2;Persist Security Info=True;User ID=sa;Password=sa@123;";
|
//public static string sqlcon = "Initial Catalog=jsasrs;Persist Security Info=True;User ID=;Password=klsasrs@zy;";
|
|
/// <summary>
|
/// ERP数据库连接字符串
|
/// </summary>
|
public static string erpcon = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dm01db01-vip.dssyebs.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME = PROD)));User Id=HSTORE;Password=HSTORE;";
|
|
/// <summary>
|
/// 数据库服务器IP
|
/// </summary>
|
public static string serverIp = "127.0.0.1";
|
|
/// <summary>
|
/// WMS接口
|
/// </summary>
|
public static string HttpUrl = "";
|
|
//public static string servername = ".";
|
//public static string login = "asrs";
|
//public static string psw = "asrs";
|
//public static int crnwriteadd = 80;
|
/// <summary>
|
/// 定义FORM窗体f1
|
/// </summary>
|
public static Form f1 = null;
|
|
/// <summary>
|
/// 堆垛机数量
|
/// </summary>
|
public static int ci_crn_count = 3;
|
/// <summary>
|
/// 站点数量
|
/// </summary>
|
public static int ci_sta_count = 36;
|
/// <summary>
|
/// PLC数量
|
/// </summary>
|
public static int ci_plc_count = 1;
|
/// <summary>
|
/// 磅秤数量
|
/// </summary>
|
public static int ci_scale_count = 1;
|
/// <summary>
|
/// 条码扫描器数量
|
/// </summary>
|
public static int ci_barcode_count = 1;
|
/// <summary>
|
/// LED显示屏
|
/// </summary>
|
public static int ci_led_count = 5;
|
|
/// <summary>
|
/// 台车数量
|
/// </summary>
|
public static int ci_rgv_count = 0;
|
|
/// <summary>
|
/// WCS服务器Socket IP
|
/// </summary>
|
public static string gs_wcs_ip = "";
|
/// <summary>
|
/// WCS服务器Socket端口
|
/// </summary>
|
public static int gs_wcs_port = 10001;
|
|
//public static int ci_plc_error_count = 7;// 91;
|
|
/// <summary>
|
/// 站点错误数
|
/// </summary>
|
public static int ci_plcerrcount = 100;
|
public static string[] plcerr;// = new string[ci_plcerrcount];
|
public static string[] gs_PlcErrDesc;// = new string[ci_plcerrcount];
|
//public static int ci_plcerrrecord = 30;
|
//public static int[] gi_plc_err = new int[ci_plcerrrecord];
|
/// <summary>
|
/// S7写数据到西门子PLC互锁标志,同一时间只允许一个写入
|
/// </summary>
|
public static bool writeFlag = true;
|
|
/// <summary>
|
/// 磅秤重量上限
|
/// </summary>
|
public static double ci_scale_maxwt = 1000;
|
/// <summary>
|
/// 磅秤重量下限
|
/// </summary>
|
public static double ci_scale_minwt = 30;
|
|
/// <summary>
|
/// 堆垛机入库站站点编号数组
|
/// </summary>
|
public static int[] crn_inStns = new int[8] { 104,106,117,120,124,131,133,136 };
|
|
/// <summary>
|
/// 堆垛机出库站站点编号数组
|
/// </summary>
|
public static int[] crn_outStns = new int[4] { 101,110, 113,127 };
|
|
//public static bool[] plctag = new bool[2];
|
//public static bool[] stasts = new bool[16];
|
//public static bool[] stasts1 = new bool[4];
|
//public static int[] gi_wrkno_pick = new int[5];
|
//public static string[] gi_sts=new string[4];
|
|
#region 常量定义区
|
//堆垛机内部状态参数状态字
|
public static long ch_crn_sdms = 1; //手动模式
|
public static long ch_crn_zdms = 2; //自动模式
|
public static long ch_crn_dnms = 4; //电脑模式
|
public static long ch_crn_sdz = 8; //手动中
|
public static long ch_crn_zdz = 16; //自动中
|
public static long ch_crn_dnmsz = 32; //电脑模式中
|
public static long ch_crn_jt = 64; //急停
|
public static long ch_crn_yc = 128; //异常
|
public static long ch_crn_dndmz = 256; //电脑待命中
|
public static long ch_crn_dnmljs = 512; //电脑命令正确接收
|
public static long ch_crn_rkz = 1024; //入库中
|
public static long ch_crn_ckz = 2048; //出库中
|
public static long ch_crn_kdkz = 4096; //库对库中
|
public static long ch_crn_zdzz = 8192; //站对站中
|
public static long ch_crn_yxz = 16384; //移行中
|
public static long ch_crn_dcqhjd = 32768; //堆垛机取货阶段
|
|
// {CRN STATUS2}
|
public static long ch_crn_dcfhjd = 1; //堆垛机放货阶段
|
public static long ch_crn_dckx = 2; //堆垛机空闲
|
public static long ch_crn_zxyddw = 4; //走行原点定位
|
public static long ch_crn_sjyddw = 8; //升降原点定位
|
public static long ch_crn_zxzdw = 16; //走行在定位
|
public static long ch_crn_cyzzj = 32; //叉牙在中间
|
public static long ch_crn_cyzzd = 64; //叉牙在左端
|
public static long ch_crn_cyzyd = 128; //叉牙在右端
|
public static long ch_crn_sjsdw = 256; //升降上定位
|
public static long ch_crn_sjxdw = 512; //升降下定位
|
public static long ch_crn_plcdlbz = 1024; //plc电力不足
|
public static long ch_crn_sjtycyw = 2048; //升降台有物
|
|
//public static bool[] gl_crn_status = new bool[ci_crn_count];
|
|
//plc状态字
|
public static int ch_d1 = 1;
|
public static int ch_d2 = 2;
|
public static int ch_d3 = 4;
|
public static int ch_d4 = 8;
|
public static int ch_d5 = 16;
|
public static int ch_d6 = 32;
|
public static int ch_d7 = 64;
|
public static int ch_d8 = 128;
|
public static int ch_d9 = 256;
|
public static int ch_d10 = 512;
|
public static long ch_d11 = 1024;
|
public static long ch_d12 = 2048;
|
public static long ch_d13 = 4096;
|
public static long ch_d14 = 8192;
|
public static long ch_d15 = 16384;
|
public static long ch_d16 = 32768;
|
|
//堆垛机工作模式
|
/// <summary>
|
/// 手动模式
|
/// </summary>
|
public static int ci_CRN_MANUAL = 1;
|
/// <summary>
|
/// 自动模式
|
/// </summary>
|
public static int ci_CRN_AUTO = 2;
|
/// <summary>
|
/// 连线模式
|
/// </summary>
|
public static int ci_CRN_ONLINE = 3;
|
|
//堆垛机io状态
|
public static int ci_CRN_LINK = 1;
|
public static int ci_CRN_RESET = 2;
|
public static int ci_CRN_CLEAR = 3;
|
public static int ci_CRN_HOME = 4;
|
public static int ci_CRN_STN = 5;
|
public static int ci_CRN_SHELF = 6;
|
public static int ci_CRN_INQUIRY = 7;
|
public static int ci_CRN_STORE = 7;
|
public static int ci_CRN_RETRIEVE = 8;
|
public static int ci_CRN_MOVE = 10;
|
public static int ci_CRN_STNTOSTN = 11;
|
public static int ci_CRN_LOCTOLOC = 12;
|
|
//堆垛机状态
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
public static int ci_CRN_STS_INIT = -1;
|
/// <summary>
|
/// 空闲,无任务
|
/// </summary>
|
public static int ci_CRN_STS_IDLE = 0;
|
/// <summary>
|
/// 取货定位中
|
/// </summary>
|
public static int ci_CRN_STS_FETCH_MOVING = 1;
|
/// <summary>
|
/// 取货中
|
/// </summary>
|
public static int ci_CRN_STS_FETCH = 2;
|
/// <summary>
|
/// 取货完成,放货定位中
|
/// </summary>
|
public static int ci_CRN_STS_RELEASE_MOVING = 3;
|
/// <summary>
|
/// 放货中
|
/// </summary>
|
public static int ci_CRN_STS_RELEASE = 4;
|
/// <summary>
|
/// 回原点中
|
/// </summary>
|
public static int ci_CRN_STS_HP = 5;
|
/// <summary>
|
/// 去反原点中
|
/// </summary>
|
public static int ci_CRN_STS_OHP = 6;
|
/// <summary>
|
/// 库位移转中
|
/// </summary>
|
public static int ci_CRN_STS_LOC_MOVE = 7;
|
/// <summary>
|
/// 任务完成,等待WCS确认
|
/// </summary>
|
public static int ci_CRN_STS_TASK_FINISH = 90;
|
|
//public static int ci_CRN_SETTING = 0;
|
//public static int ci_CRN_STS_IDLE = 1;
|
public static int ci_CRN_STS_STORE_MOVE = 2; //{ STORE COMMAND }
|
public static int ci_CRN_STS_RETRIEVE_MOVE = 3; //{ RETRIEVE COMMAND }
|
public static int ci_CRN_STS_MOVING = 4; //{ MOVE COMMAND }
|
public static int ci_CRN_STS_STORE_OK = 5;
|
public static int ci_CRN_STS_RETRIEVE_OK = 6;
|
public static int ci_CRN_STS_MOVING_OK = 7;
|
public static int ci_CRN_STS_ERROR = 8;
|
public static int ci_CRN_STS_ERROR_IDLE = 9;
|
//public static int ci_CRN_STS_OHP = 10;
|
public static int ci_CRN_STS_STOP = 11;
|
public static int ci_CRN_STS_STNCHG_MOVE = 12;
|
public static int ci_CRN_STS_STNCHG_OK = 13;
|
public static int ci_CRN_STS_LOCATION_MOVE = 14;
|
public static int ci_CRN_STS_LOCATION_MOVE_OK = 16;
|
public static int ci_CRN_STS_HP_POSITION = 15; ///20061007
|
|
//工作状态
|
public static int ci_WRK_STORE_SETDATA = 1;
|
public static int ci_WRK_STORE_SETPLC = 2;
|
public static int ci_WRK_STORE_SETCRN = 3;
|
public static int ci_WRK_STORE_OK = 4;
|
public static int ci_WRK_STORE_UPDDB = 5;
|
public static int ci_WRK_STORE_exit = 6;
|
public static int ci_WRK_STNMOVE_OK = 7;
|
|
public static int ci_WRK_RETRIEVE_SETDATA = 11;
|
public static int ci_WRK_RETRIEVE_SETCRN = 12;
|
public static int ci_WRK_RETRIEVE_OK = 14;
|
public static int ci_WRK_RETRIEVE_UPDDB = 15;
|
|
public static int ci_plc_MAX = 10; //PLC最大队列数
|
|
//plc工作命令类型
|
public static int ci_PLC_SETID = 1;
|
public static int ci_PLC_SETDEST = 2;
|
public static int ci_PLC_SETIDDEST = 3;
|
|
//COMUCATION I/O BUFFER SIZE
|
public static int ci_crn_MAXBUFSIZE = 4096;
|
public static int ci_barcode_MAXBUFSIZE = 4096;
|
//public static int ci_MAXINCOUNT = 35;
|
//public static int ci_MAXOUTCOUNT = 50;
|
|
/// <summary>
|
/// CRANE SLEEP TIME
|
/// </summary>
|
public static int ci_CRNtimeInterval = 300;
|
/// <summary>
|
/// PLC SLEEP TIME
|
/// </summary>
|
public static int ci_PLCtimeInterval = 300;
|
/// <summary>
|
/// Barcode Scanner SLEEP TIME
|
/// </summary>
|
public static int ci_BarcodetimeInterval = 200;
|
/// <summary>
|
/// LED SLEEP TIME
|
/// </summary>
|
public static int ci_LedtimeInterval = 200;
|
|
/// <summary>
|
/// 系统运行中
|
/// </summary>
|
public static int ch_CMD_START = 1;
|
/// <summary>
|
/// 系统暂停中
|
/// </summary>
|
public static int ch_CMD_PAUSE = 10;
|
/// <summary>
|
/// 系统关闭中
|
/// </summary>
|
public static int ch_CMD_CLOSE = 100;
|
#endregion
|
|
//-------------------------------------------------------------变量定义---------------------------------------------------------------------------
|
/// <summary>
|
/// 下发堆垛机命令后,等待一个周期,再判断堆垛机是否空闲
|
/// </summary>
|
public static int gi_cycle_flag = 0;
|
|
/// <summary>
|
/// 堆垛机IP
|
/// </summary>
|
public static string[] gs_crn_ip = new string[ci_crn_count];
|
/// <summary>
|
/// PLC输送设备IP
|
/// </summary>
|
public static string[] gs_plc_ip = new string[ci_plc_count];
|
/// <summary>
|
/// 磅秤端口号,串口
|
/// </summary>
|
public static int[] gi_scale_port = new int[ci_scale_count];
|
/// <summary>
|
/// 磅秤设备IP
|
/// </summary>
|
public static string[] gs_scale_ip = new string[ci_scale_count];
|
/// <summary>
|
/// 条码设备串口端口
|
/// </summary>
|
public static int[] gs_barcode_port = new int[ci_barcode_count];
|
/// <summary>
|
/// 条码设备IP
|
/// </summary>
|
public static string[] gs_barcode_ip = new string[ci_barcode_count];
|
/// <summary>
|
/// 条码设备IP
|
/// </summary>
|
public static string[] gs_led_ip = new string[ci_led_count];
|
/// <summary>
|
/// 磅秤称重数据
|
/// </summary>
|
public static double[] gd_gross_wt = new double[ci_scale_count];
|
/// <summary>
|
/// 条码扫描数据
|
/// </summary>
|
public static string[] gs_barcode_data = new string[ci_barcode_count];
|
/// <summary>
|
/// LED待发送数据
|
/// </summary>
|
public static string[] gs_led_data = new string[ci_led_count];
|
public static string[] gs_led_data_pre = new string[ci_led_count];
|
|
///// <summary>
|
///// LED页数
|
///// </summary>
|
//public static int[] gi_led_Pages = new int[ci_led_count];
|
|
/// <summary>
|
/// LED页码
|
/// </summary>
|
public static int[] gi_led_PageNumber = new int[ci_led_count];
|
|
/// <summary>
|
/// LED显示当前页码
|
/// </summary>
|
public static int[] gi_led_CurPageNumber = new int[ci_led_count];
|
|
/// <summary>
|
/// LED显示循环次数
|
/// </summary>
|
public static int[] gi_led_Counts = new int[ci_led_count];
|
|
///// <summary>
|
///// LED显示效果
|
///// </summary>
|
//public static int[] gi_led_ShowStyle = new int[ci_led_count];
|
|
/// <summary>
|
/// 台车位置
|
/// </summary>
|
public static int[] gi_RGVPos = new int[ci_rgv_count];
|
|
/// <summary>
|
/// 扫描超时时间判断
|
/// </summary>
|
public static double gd_scanTimeout = 4;
|
|
///// <summary>
|
///// PLC工作模式,0--入库,1--出库
|
///// </summary>
|
//public static int gi_PLCModel = 0;
|
///// <summary>
|
///// PLC手工完成出库信号,工作档将12->14
|
///// </summary>
|
//public static int gi_PLCClear = 0;
|
|
/// <summary>
|
/// 1号站条码扫描判断有没有扫到,计时判断
|
/// </summary>
|
public static DateTime barcodeTime = DateTime.Now;
|
public static int barcodeFlag = 0;
|
//public static string gs_barcode = "";
|
|
#region LED参数
|
/// <summary>
|
/// 显示屏宽度
|
/// </summary>
|
public static int SCREEN_WIDTH = 96;
|
/// <summary>
|
/// 显示屏高度
|
/// </summary>
|
public static int SCREEN_HEIGHT = 48;
|
public static int CONTROLLER_TYPE = 850; //控制器类型
|
public static int SCREEN_TYPE = 1; //显示屏类型
|
public static int SCREEN_PIXELMODE = 1; //点阵类型
|
public static int SCREEN_DATADA = 0; //数据极性
|
public static int SCREEN_DATAOE = 0; //OE极性
|
public static int SCREEN_ROWORDER = 0; //行序模式
|
public static int SCREEN_FREQPAR = 0; //扫描点频
|
|
public static string SCREEN_COMM = "COM1"; //串口
|
public static int SCREEN_BAUD = 57600; //串口波特率
|
public static string SCREEN_STATUSFILE = "C:\\ScreenStatus.ini"; //显示屏状态保存文件
|
|
public static int SCREEN_SENDMODE = 2; //通讯模式,0:串口 2:网络 4:wifi
|
public const int SENDALLPROGRAM = 41456; //发送所有节目信息。
|
/// <summary>
|
/// 发送数据给控制卡时互斥作用,每次只能发送一条过去
|
/// </summary>
|
public static bool m_bSendBusy = false;
|
#endregion
|
|
//public static string barrec = "";
|
public static int[] areamode = new int[4];
|
//public static bool insesheettag = false;
|
//public static string[] gs_barcode_tmp = new string[5];
|
public static string[] crncmd = new string[ci_crn_count];
|
public static int[] crnwrkno = new int[ci_crn_count];
|
//public static int[] pickquereseq = new int[12];
|
//public static int bk = 1;
|
|
public static Form form1 = null;
|
public static Form form2 = null;
|
//public static bool stnmove = true;
|
//public static bool crnmove = true;
|
//public static bool crnallow = true;
|
|
public static int gi_Online_Flag = 10;
|
public static bool[] gb_crn_status = new bool[ci_crn_count];
|
//public static int gi_wrkfileh = 0;
|
public static string[] gs_crnlastio = new string[ci_crn_count];
|
public static int[] gi_crnstn = new int[ci_crn_count];
|
public static string[] gs_crn_data_pre = new string[ci_crn_count];
|
public static int[] gi_crn_wrkno = new int[ci_crn_count];
|
public static string[] gs_crn_err_pre = new string[ci_crn_count];
|
//public static int[] clrled = new int[10];
|
public static int gi_buffer_count = 16;
|
public static int gi_trolleypos_count = 2;
|
//public static int[] stnbuffer = new int[gi_buffer_count];//
|
public static int[] trolleypos = new int[gi_trolleypos_count];//2个,14,29
|
//public static int[] ci_stnbuffer = new int[gi_buffer_count];
|
public static int[] gi_stabuffer = new int[gi_buffer_count];
|
//public static int[] gi_crn_actsts = new int[ci_crn_count];
|
public static int[] gi_stn_iotype = new int[ci_sta_count];
|
|
public static int[] g_ari_staion = new int[ci_sta_count];
|
public static string[] g_ars_staion_name = new string[ci_sta_count];
|
public static int[] g_ari_staion_plc_no = new int[ci_sta_count];
|
public static Control[] g_ari_staion_Component_seq = new Control[ci_sta_count];
|
public static int[] g_ari_station_idaddr = new int[ci_sta_count];
|
public static int[] g_ari_station_stsaddr = new int[ci_sta_count];
|
public static int[] g_ari_station_destaddr = new int[ci_sta_count];
|
public static string[] gs_plc_data_pre = new string[ci_sta_count];
|
public static int[] gi_crn_iotype = new int[ci_crn_count];
|
public static int[] gi_loctype = new int[ci_sta_count];
|
|
//堆垛机变量
|
//public static string[,] crnstsvalue = new string[ci_crn_count, 33];
|
public static string[] crnerrlist = new string[ci_crn_count];
|
//public static string[] crnip = new string[ci_crn_count];
|
|
public static int[] crn_i_crnno = new int[ci_crn_count];
|
public static int[] crn_i_crn_sts = new int[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机命令
|
/// </summary>
|
public static string[] gs_crncmd = new string[ci_crn_count];
|
public static string[] crn_s_commandstr = new string[ci_crn_count];
|
public static int[] crn_i_kind = new int[ci_crn_count];
|
public static int[] crn_i_Wrkno = new int[ci_crn_count];
|
public static int[] crn_i_fstn = new int[ci_crn_count];
|
public static int[] crn_i_tstn = new int[ci_crn_count];
|
public static string[] crn_s_Flocno = new string[ci_crn_count];
|
public static string[] crn_s_Tlocno = new string[ci_crn_count];
|
public static int[] crn_i_Errcod = new int[ci_crn_count];
|
public static bool[] gi_Yanshi_Flag = new bool[ci_crn_count];
|
/// <summary>
|
/// 是否在原点,1=原点
|
/// </summary>
|
public static int[] crn_i_onHP = new int[ci_crn_count];
|
|
////////////////////---------------------------堆垛机变量表--------------------------
|
#region 堆垛机(CRN)状态信息
|
/// <summary>
|
/// 堆垛机工作模式,0 = 离线模式,1=手动模式中,2=自动模式中,3=电脑连线模式中
|
/// </summary>
|
public static int[] Mode = new int[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机当前任务号
|
/// </summary>
|
public static int[] TaskNo = new int[ci_crn_count];
|
|
/// <summary>
|
/// SRM工位1当前任务执行状态,0=空闲,1=取货定位中,2=取货中,3=取货完成,放货定位中,
|
/// 4=放货中,5=回原点中,6=去反原点中,7=库位移转,90=任务完成,WCS未确认,99=报警
|
/// </summary>
|
public static int[] CrnState = new int[ci_crn_count];
|
|
///// <summary>
|
///// 堆垛机当前列号
|
///// </summary>
|
//public static int[] CurBay = new int[ci_crn_count];
|
|
///// <summary>
|
///// 堆垛机当前层号
|
///// </summary>
|
//public static int[] CurLev = new int[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机当前货叉位置,0=货叉原位,1=货叉在左侧,2=货叉在右侧
|
/// </summary>
|
public static int[] ForkPos = new int[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机当前载货台定位位置,1=下定位,2=上定位,0=不在定位
|
/// </summary>
|
public static int[] LiftPos = new int[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机走行定位位置,1=在定位,0=不在定位
|
/// </summary>
|
public static int[] WalkPos = new int[ci_crn_count];
|
|
/// <summary>
|
/// =1 堆垛机任务完成信号
|
/// </summary>
|
public static int[] TaskFinish = new int[ci_crn_count];
|
|
/// <summary>
|
/// SRM工位1任务完成处理标记,防止重复处理。默认为0,timer1根据F1TaskFinish处理工作档状态后赋值1
|
/// 堆垛机线程中下发确认信息后,重置为0
|
/// </summary>
|
public static int[] TaskFlag = new int[ci_crn_count];
|
|
/// <summary>
|
/// =1 堆垛机载货台有货
|
/// </summary>
|
public static int[] Loaded = new int[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机异常码
|
/// </summary>
|
public static int[] AlarmCode = new int[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机走行速度(m/min)
|
/// </summary>
|
public static float[] WalkSpeed = new float[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机升降速度(m/min)
|
/// </summary>
|
public static float[] LiftSpeed = new float[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机叉牙速度(m/min)
|
/// </summary>
|
public static float[] ForkSpeed = new float[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机累计走行距离(km)
|
/// </summary>
|
public static float[] XDistance = new float[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机累计升降距离(km)
|
/// </summary>
|
public static float[] YDistance = new float[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机累计走行时长(H)
|
/// </summary>
|
public static float[] XDuration = new float[ci_crn_count];
|
|
/// <summary>
|
/// 堆垛机累计升降时长(H)
|
/// </summary>
|
public static float[] YDuration = new float[ci_crn_count];
|
|
///// <summary>
|
///// 1=SRM处于报警状态
|
///// </summary>
|
//public static int[] AlarmStatus = new int[ci_crn_count];
|
|
|
///// <summary>
|
///// SRM工位1当前货叉位置,[1:左近,2:中位,3:右近,4:左远,5:右远]
|
///// </summary>
|
//public static int[] F1PosZ = new int[ci_crn_count];
|
|
///// <summary>
|
///// SRM当前列坐标,单位mm
|
///// </summary>
|
//public static double[] PosXmm = new double[ci_crn_count];
|
|
///// <summary>
|
///// SRM当前层坐标,单位mm
|
///// </summary>
|
//public static double[] PosYmm = new double[ci_crn_count];
|
|
///// <summary>
|
///// SRM工位1当前货叉坐标,单位mm
|
///// </summary>
|
//public static double[] F1PosZmm = new double[ci_crn_count];
|
|
///// <summary>
|
///// SRM工位2当前任务执行状态,0=位置,1=空闲,2=检查任务数据,3=定位到取货位,7=取货完成,
|
///// 8=等待调度柜允许,9=移动到放货位置,10=放货中,13=搬运完成,14=空载避让,15=检查任务数据
|
///// 20=检查源位置,21=检查目标位置,50=移动任务,98=任务完成,WCS未确认,99=报警
|
///// </summary>
|
//public static int[] F2State = new int[ci_crn_count];
|
|
#endregion
|
|
#region 堆垛机状态字定义
|
/// <summary>
|
/// 手动模式
|
/// </summary>
|
public static bool[] crn_sdms = new bool[ci_crn_count];
|
/// <summary>
|
/// 自动模式
|
/// </summary>
|
public static bool[] crn_zdms = new bool[ci_crn_count];
|
/// <summary>
|
/// 电脑模式
|
/// </summary>
|
public static bool[] crn_dnms = new bool[ci_crn_count];
|
/// <summary>
|
/// 手动中
|
/// </summary>
|
public static bool[] crn_sdz = new bool[ci_crn_count];
|
/// <summary>
|
/// 自动中
|
/// </summary>
|
public static bool[] crn_zdz = new bool[ci_crn_count];
|
/// <summary>
|
/// 电脑模式中
|
/// </summary>
|
public static bool[] crn_dnmsz = new bool[ci_crn_count];
|
/// <summary>
|
/// 急停
|
/// </summary>
|
public static bool[] crn_jt = new bool[ci_crn_count];
|
/// <summary>
|
/// 异常
|
/// </summary>
|
public static bool[] crn_yc = new bool[ci_crn_count];
|
/// <summary>
|
/// 保留
|
/// </summary>
|
public static bool[] crn_dndmz = new bool[ci_crn_count];
|
/// <summary>
|
/// 任务完成
|
/// </summary>
|
public static bool[] crn_dnmljs = new bool[ci_crn_count];
|
/// <summary>
|
/// 入库中
|
/// </summary>
|
public static bool[] crn_rkz = new bool[ci_crn_count];
|
/// <summary>
|
/// 出库中
|
/// </summary>
|
public static bool[] crn_ckz = new bool[ci_crn_count];
|
/// <summary>
|
/// 库到库
|
/// </summary>
|
public static bool[] crn_kdkz = new bool[ci_crn_count];
|
/// <summary>
|
/// 站到站
|
/// </summary>
|
public static bool[] crn_zdzz = new bool[ci_crn_count];
|
/// <summary>
|
/// 去原点
|
/// </summary>
|
public static bool[] crn_yxz = new bool[ci_crn_count];
|
/// <summary>
|
/// 去反原点
|
/// </summary>
|
public static bool[] crn_dcqhjd = new bool[ci_crn_count];
|
/// <summary>
|
/// 放货阶段
|
/// </summary>
|
public static bool[] crn_dcfhjd = new bool[ci_crn_count];
|
/// <summary>
|
/// 吊车空闲
|
/// </summary>
|
public static bool[] crn_dckx = new bool[ci_crn_count];
|
/// <summary>
|
/// 走行原点定位
|
/// </summary>
|
public static bool[] crn_zxyddw = new bool[ci_crn_count];
|
/// <summary>
|
/// 升降原点定位
|
/// </summary>
|
public static bool[] crn_sjyddw = new bool[ci_crn_count];
|
/// <summary>
|
/// 走行在定位
|
/// </summary>
|
public static bool[] crn_zxzdw = new bool[ci_crn_count];
|
/// <summary>
|
/// 叉牙在中间
|
/// </summary>
|
public static bool[] crn_cyzzj = new bool[ci_crn_count];
|
/// <summary>
|
/// 叉牙在左端
|
/// </summary>
|
public static bool[] crn_cyzzd = new bool[ci_crn_count];
|
/// <summary>
|
/// 叉牙在右端
|
/// </summary>
|
public static bool[] crn_cyzyd = new bool[ci_crn_count];
|
/// <summary>
|
/// 升降上定位
|
/// </summary>
|
public static bool[] crn_sjsdw = new bool[ci_crn_count];
|
/// <summary>
|
/// 升降下定位
|
/// </summary>
|
public static bool[] crn_sjxdw = new bool[ci_crn_count];
|
/// <summary>
|
/// 保留
|
/// </summary>
|
public static bool[] crn_plcdlbz = new bool[ci_crn_count];
|
/// <summary>
|
/// 升降台有物
|
/// </summary>
|
public static bool[] crn_sjtycyw = new bool[ci_crn_count];
|
/// <summary>
|
/// 当前排数
|
/// </summary>
|
public static int[] crn_dqps = new int[ci_crn_count];
|
/// <summary>
|
/// 当前层数
|
/// </summary>
|
public static int[] crn_dqcs = new int[ci_crn_count];
|
/// <summary>
|
/// 走行镭射距离
|
/// </summary>
|
public static double[] crn_zxlsz = new double[ci_crn_count];
|
/// <summary>
|
/// 升降镭射距离
|
/// </summary>
|
public static double[] crn_sjlsz = new double[ci_crn_count];
|
public static int[] crn_dnmlyc = new int[ci_crn_count];
|
/// <summary>
|
/// 设备异常码
|
/// </summary>
|
public static int[] crn_ycmm = new int[ci_crn_count];
|
public static int[] crn_yczm = new int[ci_crn_count];
|
|
//public static int[] crn_zxlsz1 = new int[ci_crn_count];
|
//public static int[] crn_zxlsz2 = new int[ci_crn_count];
|
//public static int[] crn_sjlsz1 = new int[ci_crn_count];
|
//public static int[] crn_sjlsz2 = new int[ci_crn_count];
|
#endregion
|
|
public static string[] crncmdtext = new string[ci_crn_count];
|
//定义plc变量
|
//public struct sta
|
//{
|
public static int PlcMaxQuereCount = 10;//plc最大队列存储数量
|
public static string[,] s_cmd = new string[4, PlcMaxQuereCount];
|
//public static Queue<string> PlcAQueue = new Queue<string>();
|
//public static Queue<string> PlcBQueue = new Queue<string>();
|
|
public static string[,] plc_s_dev_no = new string[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_type_mk = new string[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_term_mk = new string[ci_plc_count, ci_sta_count];
|
public static int[,] plc_i_status = new int[ci_plc_count, ci_sta_count];
|
public static int[,] plc_i_plc_no = new int[ci_plc_count, ci_sta_count];
|
public static int[,] plc_i_Wrk_no = new int[ci_plc_count, ci_sta_count];
|
public static int[,] plc_i_ctn_type = new int[ci_plc_count, ci_sta_count];
|
public static int[,] plc_i_pakmk = new int[ci_plc_count, ci_sta_count];
|
public static int[,] plc_i_buff_count = new int[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_stn_status = new string[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_from_stn = new string[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_next_stn = new string[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_t_station = new string[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_autoing = new string[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_loading = new string[ci_plc_count, ci_sta_count];
|
/// <summary>
|
/// 可入
|
/// </summary>
|
public static string[,] plc_s_canining = new string[ci_plc_count, ci_sta_count];
|
/// <summary>
|
/// 可出
|
/// </summary>
|
public static string[,] plc_s_canouting = new string[ci_plc_count, ci_sta_count];
|
/// <summary>
|
/// 空板信号
|
/// </summary>
|
public static string[,] plc_s_inreq1 = new string[ci_plc_count, ci_sta_count];
|
/// <summary>
|
/// 满托信号
|
/// </summary>
|
public static string[,] plc_s_inreq2 = new string[ci_plc_count, ci_sta_count];
|
/// <summary>
|
/// 货物类型
|
/// </summary>
|
public static string[,] plc_s_loctype = new string[ci_plc_count, ci_sta_count];
|
/// <summary>
|
/// 报警
|
/// </summary>
|
public static string[,] plc_s_error = new string[ci_plc_count, ci_sta_count];
|
public static string[,] plc_s_modeallow = new string[ci_plc_count, ci_sta_count];
|
|
//public static string[] s_plc_err_count1 = new string[ci_plcerrcount];
|
//public static string[] s_plc_err_count2 = new string[ci_plcerrcount];
|
|
//public struct fieldds//字段描述
|
//{
|
// public int index;
|
// public string dataname;
|
// public string datadesc;
|
//}
|
|
|
//public Common()
|
//{
|
//}
|
|
//public static string Proc_GetNum(string str)
|
//{
|
// string result = "";
|
// try
|
// {
|
// for (int i = 0; i < str.Length; i++)
|
// {
|
// if (str[i] == '0' || str[i] == '1' || str[i] == '2' || str[i] == '3' || str[i] == '4' || str[i] == '6' || str[i] == '7' || str[i] == '8' || str[i] == '9')
|
// {
|
// result = result.Trim() + str[i];
|
// }
|
// }
|
// }
|
// catch (Exception t)
|
// {
|
|
// }
|
// return result;
|
//}
|
|
/// <summary>
|
/// 增加plc命令队列
|
/// </summary>
|
/// <param name="plcno">plc号</param>
|
/// <param name="cmd">指令</param>
|
public static void AddPlcQuereCmd(int plcno, string cmd)
|
{
|
if (cmd == "") { return; };
|
for (int j = PlcMaxQuereCount - 1; j >= 0; j--)
|
{
|
if (s_cmd[plcno, j] == "" || s_cmd[plcno, j] == null)
|
{
|
s_cmd[plcno, j] = cmd;
|
break;
|
}
|
}
|
AdjPlcQuere(plcno);
|
}
|
|
/// <summary>
|
/// 得到plc指令队列的数量
|
/// </summary>
|
/// <param name="plcno">plc号</param>
|
/// <returns>队列的数量</returns>
|
public static int GetPlcQuereCount(int plcno)
|
{
|
int count = 0;
|
for (int i = 0; i < ci_plc_MAX; i++)
|
{
|
if (s_cmd[plcno, i] != "" && s_cmd[plcno, i] != null)
|
{
|
count++;
|
}
|
}
|
return count;
|
}
|
|
/// <summary>
|
/// 从plc队列中取最先进的一笔指令
|
/// </summary>
|
/// <param name="plcno">plc号</param>
|
/// <returns>对应最先进的指令</returns>
|
public static string GetPlcQuereCmd(int plcno)
|
{
|
string cmd = "";
|
for (int i = 0; i < PlcMaxQuereCount; i++)
|
{
|
if (s_cmd[plcno, i] != "" && s_cmd[plcno, i] != null)
|
{
|
cmd = s_cmd[plcno, i];
|
s_cmd[plcno, i] = "";
|
break;
|
}
|
}
|
AdjPlcQuere(plcno);
|
return cmd;
|
}
|
|
/// <summary>
|
/// 调整队列存储
|
/// </summary>
|
/// <param name="plcno">plc号</param>
|
public static void AdjPlcQuere(int plcno)
|
{
|
string s_tmep1 = "", s_tmep2 = "";
|
for (int j = PlcMaxQuereCount - 1; j >= 0; j--)
|
{
|
s_tmep1 = s_cmd[plcno, j];
|
if (j > 0)
|
{
|
s_tmep2 = s_cmd[plcno, j - 1];
|
if (s_tmep1 != "" && s_tmep2 == "")
|
{
|
s_cmd[plcno, j - 1] = s_tmep1;
|
s_cmd[plcno, j] = "";
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 根据堆垛机状态值得到状态名称
|
/// </summary>
|
/// <param name="i_sts">堆垛机状态值</param>
|
/// <returns>堆垛机状态</returns>
|
public static string GetCrnStsName(int i_sts)
|
{
|
string crnstsname = "";
|
switch (i_sts)
|
{
|
case -1:
|
crnstsname = "初始化";
|
break;
|
case 0:
|
crnstsname = "空闲";
|
break;
|
case 1:
|
crnstsname = "取货定位中";
|
break;
|
case 2:
|
crnstsname = "取货中";
|
break;
|
case 3:
|
crnstsname = "取货完成,放货定位中";
|
break;
|
case 4:
|
crnstsname = "放货中";
|
break;
|
case 5:
|
crnstsname = "回原点中";
|
break;
|
case 6:
|
crnstsname = "去反原点中";
|
break;
|
case 7:
|
crnstsname = "库位移转";
|
break;
|
case 90:
|
crnstsname = "任务完成,WCS未确认";
|
break;
|
case 99:
|
crnstsname = "报警";
|
break;
|
default:
|
crnstsname = "未知";
|
break;
|
}
|
return crnstsname;
|
}
|
|
/// <summary>
|
/// 站点初始化,PLC读写地址定义
|
/// </summary>
|
public static void InitSta()
|
{
|
int i;
|
for (i = 1; i <= ci_sta_count; i++)
|
{
|
//站点号
|
g_ari_staion[i - 1] = i + 100;
|
g_ars_staion_name[i - 1] = (i + 100).ToString();
|
g_ari_staion_plc_no[i - 1] = 1;
|
//工作号 目标库位 状态
|
g_ari_station_idaddr[i - 1] = (i - 1) * 4; //工作号地址
|
g_ari_station_destaddr[i - 1] = (i - 1) * 4 + 2; //目标站地址
|
g_ari_station_stsaddr[i - 1] = i + 149; //状态位地址
|
|
//else if (i > 5 && i <= 10)
|
//{
|
// g_ari_staion[i - 1] = i + 194;
|
// g_ars_staion_name[i - 1] = (i + 194).ToString();
|
// g_ari_staion_plc_no[i - 1] = 1;
|
|
// g_ari_station_idaddr[i - 1] = (i - 1) * 4;
|
// g_ari_station_destaddr[i - 1] = (i - 1) * 4 + 2;
|
// g_ari_station_stsaddr[i - 1] = i + 59;
|
//}
|
|
//初始化站点中各个值的数据。
|
plc_s_dev_no[g_ari_staion_plc_no[i - 1] - 1, i - 1] = g_ari_staion[i - 1].ToString();
|
plc_s_autoing[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_s_loading[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_s_canining[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_s_canouting[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_s_inreq1[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_s_inreq2[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_s_loctype[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_s_error[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_i_buff_count[g_ari_staion_plc_no[i - 1] - 1, i - 1] = 0;
|
plc_i_Wrk_no[g_ari_staion_plc_no[i - 1] - 1, i - 1] = 0;
|
plc_s_stn_status[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "N";
|
plc_s_next_stn[g_ari_staion_plc_no[i - 1] - 1, i - 1] = "0";
|
plc_i_pakmk[g_ari_staion_plc_no[i - 1] - 1, i - 1] = 0;
|
|
gi_stn_iotype[i - 1] = 0; //初始化站点出入形态
|
}
|
}
|
|
/// <summary>
|
/// 堆垛机初始化
|
/// </summary>
|
public static void InitCrn()
|
{
|
int i;
|
for (i = 1; i <= ci_crn_count; i++)
|
{
|
crn_i_crnno[i - 1] = i;
|
//crn_i_crn_sts[i - 1] = ci_CRN_SETTING;
|
gs_crncmd[i - 1] = "";
|
crn_i_kind[i - 1] = 0;
|
crn_i_Wrkno[i - 1] = 0;
|
crn_i_fstn[i - 1] = 0;
|
crn_i_tstn[i - 1] = 0;
|
crn_s_Flocno[i - 1] = "";
|
crn_s_Tlocno[i - 1] = "";
|
//crn_i_Errcod[i - 1] = 0;
|
crn_i_onHP[i - 1] = 0;
|
|
gs_crnlastio[i - 1] = "I";
|
gs_crncmd[i - 1] = "";
|
crn_s_commandstr[i - 1] = "";
|
gi_crn_iotype[i - 1] = 0;
|
|
gb_crn_status[i - 1] = true;
|
|
AlarmCode[i - 1] = 0;
|
TaskFlag[i - 1] = 0;
|
CrnState[i - 1] = -1;
|
}
|
}
|
|
/// <summary>
|
/// 条码、LED、磅秤数据初始化
|
/// </summary>
|
public static void InitDev()
|
{
|
int i;
|
for (i = 0; i < ci_barcode_count; i++)
|
{
|
gs_barcode_data[i] = "";
|
}
|
for (i = 0; i < ci_led_count; i++)
|
{
|
gs_led_data[i] = "";
|
gs_led_data_pre[i] = "";
|
gi_led_PageNumber[i] = 1;
|
//gi_led_Pages[i] = 1;
|
gi_led_Counts[i] = 0;
|
gi_led_CurPageNumber[i] = 1;
|
}
|
for (i = 0; i < ci_scale_count; i++)
|
{
|
gd_gross_wt[i] = 0;
|
}
|
}
|
|
/// <summary>
|
/// 得到站序号
|
/// </summary>
|
/// <param name="stn"></param>
|
/// <returns></returns>
|
public static int GetStnSeq(int stn)
|
{
|
int retval = 0;
|
for (int i = 0; i <= ci_sta_count - 1; i++)
|
{
|
if (g_ari_staion[i] == stn)
|
{
|
retval = i;
|
return retval;
|
//break;
|
}
|
}
|
return 0;
|
}
|
|
////得到区域模式地址
|
//public static int GetBufAddrByStn(int stn)
|
//{
|
// int addr = 0;
|
// switch (stn)
|
// {
|
// case 1:
|
// addr = 4107;
|
// break;
|
// case 2:
|
// addr = 4110;
|
// break;
|
// default:
|
// break;
|
// }
|
// return addr;
|
//}
|
|
//public static string InttoStringYN(int i, int j)
|
//{
|
// if (i == 1)
|
// {
|
// if (j == 1)
|
// {
|
// return "出";
|
// }
|
// else
|
// {
|
// return "入";
|
// }
|
// }
|
// else
|
// {
|
// if (j == 1)
|
// {
|
// return "入";
|
// }
|
// else
|
// {
|
// return "出";
|
// }
|
// }
|
//}
|
|
///// <summary>
|
///// 十六进制转十进制
|
///// </summary>
|
///// <param name="s_data"></param>
|
///// <param name="i_len"></param>
|
///// <returns></returns>
|
//public static int funi_htoi(string s_data, int i_len)
|
//{
|
// int i_sum = 0, i_tmp = 0, x = 0;
|
// s_data = s_data.ToUpper();
|
// if (s_data == "" || s_data == null)
|
// {
|
// return 0;
|
// }
|
// for (x = 0; x < i_len; x++)
|
// {
|
|
// i_tmp = Convert.ToInt32(s_data[x]);
|
// if (i_tmp > 58) i_tmp = i_tmp - 7;
|
// i_sum = i_sum * 16 + i_tmp - 48;
|
// }
|
// return i_sum;
|
//}
|
|
///// <summary>
|
///// 判断是否4位十六进制是否正确
|
///// </summary>
|
///// <param name="data"></param>
|
///// <returns></returns>
|
//public static bool fun_chkhex(string data)
|
//{
|
// string s_str = data.PadLeft(4, '0');
|
// int i_asc = 0, i_count = 0;
|
// for (int i = 0; i < s_str.Length; i++)
|
// {
|
// i_asc = Convert.ToInt32(s_str[i]);
|
// if ((i_asc > 47 && i_asc < 58) || (i_asc > 64 && i_asc < 71))
|
// {
|
|
// }
|
// else
|
// {
|
// i_count++;
|
// }
|
// }
|
// if (i_count > 0)
|
// {
|
// return false;
|
// }
|
// else
|
// {
|
// return true;
|
// }
|
//}
|
|
/// <summary>
|
/// 十六进制转十进制
|
/// </summary>
|
/// <param name="data"></param>
|
/// <returns></returns>
|
public static double fun_hextodec(string data)
|
{
|
string cptr = "";
|
string s_str = data.Trim();
|
int len = s_str.Length;
|
double nsum = 0;
|
int k = 1;
|
for (int i = 0; i < len; i++)
|
{
|
cptr = s_str.Substring(len - i - 1, 1);
|
if (cptr == "A")
|
{
|
cptr = "10";
|
}
|
else if (cptr == "B")
|
{
|
cptr = "11";
|
}
|
else if (cptr == "C")
|
{
|
cptr = "12";
|
}
|
else if (cptr == "D")
|
{
|
cptr = "13";
|
}
|
else if (cptr == "E")
|
{
|
cptr = "14";
|
}
|
else if (cptr == "F")
|
{
|
cptr = "15";
|
}
|
if (i == 0)
|
{
|
k = 1;
|
}
|
else if (i == 1)
|
{
|
k = 16;
|
}
|
else if (i == 2)
|
{
|
k = 256;
|
}
|
else if (i == 3)
|
{
|
k = 16 * 256;
|
}
|
else if (i == 4)
|
{
|
k = 256 * 256;
|
}
|
else if (i == 5)
|
{
|
k = 16 * 256 * 256;
|
}
|
else if (i == 6)
|
{
|
k = 256 * 256 * 256;
|
}
|
else if (i == 7)
|
{
|
k = 16 * 256 * 256 * 256;
|
}
|
nsum = nsum + Convert.ToInt32(cptr) * k;
|
}
|
return nsum;
|
}
|
|
////得到十六进制
|
//public static string fun_gethex(string s_data)
|
//{
|
// string tohex = "";
|
// tohex = Convert.ToString(Convert.ToInt32(funi_htoi(s_data, 4)), 2);
|
// return tohex;
|
//}
|
|
////得到位与运算结果,并判断是否相同
|
//public static bool fun_ChkAndByte(string s_data, long t_data)
|
//{
|
// long tohex1 = 0, tohex2 = 0, tohex3 = 0;
|
// tohex1 = Convert.ToInt64(Convert.ToString(Convert.ToInt64(funi_htoi(s_data, s_data.Length)), 2));
|
// tohex2 = t_data;// Convert.ToInt32(Convert.ToString(t_data, 2));
|
// tohex3 = tohex1 & tohex2;
|
// if (tohex3 == tohex2)
|
// {
|
// return true;
|
// }
|
// else
|
// {
|
// return false;
|
// }
|
//}
|
|
/// <summary>
|
/// 得到位与运算结果,并判断是否相同
|
/// </summary>
|
/// <param name="i_data"></param>
|
/// <param name="t_data"></param>
|
/// <returns></returns>
|
public static bool fun_ChkAndByte(long i_data, long t_data)
|
{
|
long tohex1 = 0, tohex2 = 0, tohex3 = 0;
|
tohex1 = i_data;
|
tohex2 = t_data;// Convert.ToInt32(Convert.ToString(t_data, 2));
|
tohex3 = tohex1 & tohex2;
|
if (tohex3 == tohex2)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 生成工作号
|
/// </summary>
|
/// <param name="wrkmk"></param>
|
/// <returns></returns>
|
public static int GetWrkno(int wrkmk)
|
{
|
int wrkno = 0, li_s_no = 0, li_e_no = 0;
|
SqlConnection sqlcn = new SqlConnection(sqlcon);
|
sqlcn.Open();
|
SqlDataAdapter sqlda = new SqlDataAdapter("select wrk_no,s_no,e_no from asr_wrk_lastno where wrk_mk=" + wrkmk + "", sqlcn);
|
DataSet ds = new DataSet();
|
sqlda.Fill(ds);
|
DataView dv = new DataView(ds.Tables[0]);
|
sqlcn.Close();
|
foreach (System.Data.DataRowView drow in dv)
|
{
|
wrkno = Convert.ToInt32(drow[0].ToString().Trim());
|
li_s_no = Convert.ToInt32(drow[1].ToString().Trim());
|
li_e_no = Convert.ToInt32(drow[2].ToString().Trim());
|
}
|
if (wrkno >= li_e_no)
|
{
|
wrkno = li_s_no;
|
}
|
else
|
{
|
wrkno++;
|
}
|
|
SqlConnection sqlcon1 = new SqlConnection(sqlcon);
|
sqlcon1.Open();
|
SqlTransaction sqlts = sqlcon1.BeginTransaction();
|
string sql = "update asr_wrk_lastno set wrk_no=" + wrkno + " where wrk_mk=" + wrkmk + "";
|
SqlCommand sqlcom1 = new SqlCommand(sql, sqlcon1);
|
sqlcom1.Transaction = sqlts;
|
try
|
{
|
sqlcom1.ExecuteNonQuery();
|
sqlts.Commit();
|
}
|
catch (SqlException r)
|
{
|
//MessageBox.Show("更新[asr_wrk_lastno]错误!", "错误");
|
sqlts.Rollback();
|
wrkno = 0;
|
}
|
finally
|
{
|
sqlcom1.Dispose();
|
sqlcon1.Dispose();
|
sqlcon1.Close();
|
}
|
return wrkno;
|
}
|
|
/// <summary>
|
/// 生成库位号
|
/// </summary>
|
/// <param name="type">入库类型</param>
|
/// <param name="loc_type">高低库位</param>
|
/// <param name="crn_no">堆垛机号</param>
|
/// <param name="stano">入库站号</param>
|
/// <param name="stnType">入库方向,1为东侧1列起数,2为西侧最大列起数</param>
|
/// <returns></returns>
|
public static string GetLocNo(int type, int loc_type, int crn_no, int stano, int stnType)
|
{
|
int e_staNo = 0;
|
string locno = "";
|
int li_crnrow = 0, li_crn = 0, li_cnt = 0, li_max_cnt = 0, i = 0, n = 0, li_min = 0, li_max = 0, li_max_1 = 0, li_crn_qty = 0, crnsts = 0;
|
string orderBy = "lev1,bay1 asc";
|
if (stnType == 1) //东侧
|
{
|
orderBy = "lev1,bay1 asc";
|
}
|
else if (stnType == 2) //西侧
|
{
|
orderBy = "lev1 asc,bay1 desc";
|
}
|
//DataView dv = ExecAsrsSelect("select current_row,s_row,e_row,crn_qty from asr_row_lastno where whs_type=" + whs_type);
|
DataView dv = ExecAsrsSelect("select current_row,s_row,e_row,crn_qty from asr_row_lastno ");
|
foreach (DataRowView drv in dv)
|
{
|
li_crnrow = Convert.ToInt32(drv[0].ToString());
|
li_min = Convert.ToInt32(drv[1].ToString());
|
li_max = Convert.ToInt32(drv[2].ToString());
|
li_crn_qty = Convert.ToInt32(drv[3].ToString());
|
}
|
li_max_1 = li_max - 1;
|
i = 1;
|
do
|
{
|
if (li_crnrow == li_max)
|
{
|
li_crnrow = li_min;
|
}
|
else if (li_crnrow == li_max_1)
|
{
|
li_crnrow = li_min + 1;
|
}
|
else
|
{
|
li_crnrow = li_crnrow + 2;
|
}
|
li_crn = (li_crnrow + 1) / 2;
|
|
if (ChkCrnEnable(li_crn, "I") == "Y")
|
{
|
e_staNo = getIoStaNo(type, li_crn, stano);
|
if (e_staNo == 0)
|
{
|
continue;
|
}
|
//if (type == 10)
|
//{
|
// locno = getEmptyLocation(li_crnrow, loc_type, orderBy);
|
//}
|
|
if (locno == "")
|
{
|
string sql = "";
|
//if (type == 10)
|
//{
|
sql = "select top 1 loc_no from asr_loc_mast where row1=" + li_crnrow + " and loc_sts='O' order by " + orderBy;
|
//}
|
//else
|
//{
|
// sql = "select top 1 loc_no from asr_loc_mast where row1=" + li_crnrow + " and loc_sts='O' order by " + orderBy;
|
//}
|
SqlConnection sqlconn = new SqlConnection(sqlcon);
|
sqlconn.Open();
|
SqlDataAdapter sqlap = new SqlDataAdapter(sql, sqlconn);
|
DataSet ds = new DataSet();
|
sqlap.Fill(ds);
|
DataView dv1 = new DataView(ds.Tables[0]);
|
sqlap.Dispose();
|
sqlconn.Dispose();
|
//sqlconn.Close();
|
foreach (DataRowView drv in dv1)
|
{
|
locno = drv[0].ToString();
|
break;
|
}
|
}
|
}
|
|
//if (locno != "" && int.Parse(locno.Substring(0, 2)) < 3 && (stano == 1304 || stano == 1205))
|
//{//1204站无法入库1号堆垛机
|
// locno = "";
|
//}
|
//if (crn_no > 0 && crn_no != li_crn)
|
//{//先入品分配新库位,必须同一台堆垛机
|
// locno = "";
|
//}
|
if (Common.AlarmCode[li_crn - 1] > 0 || Common.Mode[li_crn - 1] != 3)
|
{ //堆垛机异常或者非自动,寻找下一个库位
|
locno = "";
|
}
|
|
//int seqno = Common.GetStnSeq(e_staNo);
|
//int plcno = stnType - 1;
|
//string s_loading = Common.plc_s_loading[plcno, seqno];
|
//if (s_loading == "Y")
|
//{//堆垛机入库站点有物,寻找下一个
|
// locno = "";
|
//}
|
|
i++;
|
if (i > li_crn_qty * 2)
|
{
|
break;
|
}
|
} while (locno == "");
|
|
if (locno != "")
|
{
|
SqlConnection sqlconn = new SqlConnection(sqlcon);
|
sqlconn.Open();
|
SqlTransaction sqltrans = sqlconn.BeginTransaction();
|
string sql = "update dbo.asr_row_lastno set current_row='" + li_crnrow + "',modi_time='" + DateTime.Now.ToString() + "' ";
|
SqlCommand sqlcmd = new SqlCommand(sql, sqlconn);
|
sqlcmd.Transaction = sqltrans;
|
try
|
{
|
sqlcmd.ExecuteNonQuery();
|
sqltrans.Commit();
|
}
|
catch (SqlException r)
|
{
|
//MessageBox.Show("更新[asr_row_lastno]错误!", "错误");
|
sqltrans.Rollback();
|
sqlcmd.Dispose();
|
sqlconn.Dispose();
|
locno = "";
|
}
|
}
|
return locno;
|
}
|
|
/// <summary>
|
/// 根据作业类型得到站点编号
|
/// </summary>
|
/// <param name="type">入库类型</param>
|
/// <param name="crnno">堆垛机号</param>
|
/// <param name="stnno">站点号</param>
|
/// <returns></returns>
|
public static int getIoStaNo(int type, int crnno, int stnno)
|
{
|
int e_staNo = 0;
|
try
|
{
|
string sql = "select crn_stn from asr_sta_desc ";
|
sql += " where type_no=" + type + " and stn_no=" + stnno + " and crn_no=" + crnno;
|
DataView dv_crn_stn = Common.ExecAsrsSelect(sql);
|
if (dv_crn_stn != null || dv_crn_stn.Count > 0)
|
{
|
foreach (DataRowView drow in dv_crn_stn)
|
{
|
e_staNo = int.Parse(drow[0].ToString());
|
}
|
}
|
}
|
catch (Exception)
|
{
|
}
|
return e_staNo;
|
}
|
|
/// <summary>
|
/// 判断堆垛机是否可用
|
/// </summary>
|
/// <param name="crn"></param>
|
/// <param name="type"></param>
|
/// <returns></returns>
|
public static string ChkCrnEnable(int crnno, string type)
|
{
|
DataView dv = null;
|
string ls_in = "N", ls_ou = "N";
|
dv = ExecAsrsSelect("select in_enable,out_enable from asr_bas_crnp where crn_no=" + crnno);
|
foreach (DataRowView drv in dv)
|
{
|
ls_in = drv[0].ToString();
|
ls_ou = drv[1].ToString();
|
}
|
if (type == "I")
|
{
|
return ls_in;
|
}
|
else if (type == "O")
|
{
|
return ls_ou;
|
}
|
else
|
{
|
return "N";
|
}
|
}
|
|
//public static string GetRow(string row)
|
//{
|
// if (row == "01")
|
// {
|
// return "01";
|
// }
|
// else if (row == "02")
|
// {
|
// return "02";
|
// }
|
// //else if (row == "03")
|
// //{
|
// // return "01";
|
// //}
|
// //else if (row == "04")
|
// //{
|
// // return "02";
|
// //}
|
// //else if (row == "05")
|
// //{
|
// // return "01";
|
// //}
|
// //else if (row == "06")
|
// //{
|
// // return "02";
|
// //}
|
// else
|
// {
|
// return "";
|
// }
|
//}
|
|
/// <summary>
|
/// 根据堆垛机异常码得到异常描述
|
/// </summary>
|
/// <param name="error_code"></param>
|
/// <returns></returns>
|
public static string GetErr(int error_code)
|
{
|
string result = "";
|
switch (error_code)
|
{
|
case 1:
|
result = "左超限";
|
break;
|
case 2:
|
result = "右超限";
|
break;
|
case 3:
|
result = "前超限";
|
break;
|
case 4:
|
result = "后超限";
|
break;
|
case 5:
|
result = "高超限";
|
break;
|
case 6:
|
result = "取货载货台有货";
|
break;
|
case 7:
|
result = "放货载货台无货";
|
break;
|
case 8:
|
result = "取货左货格无货";
|
break;
|
case 9:
|
result = "取货右货格无货";
|
break;
|
case 10:
|
result = "放货左一有货";
|
break;
|
case 11:
|
result = "放货右一有货";
|
break;
|
case 12:
|
result = "取左二货格无货";
|
break;
|
case 13:
|
result = "取右二货格无货";
|
break;
|
case 14:
|
result = "放货左二货格有货";
|
break;
|
case 15:
|
result = "放货右二货格有货";
|
break;
|
case 16:
|
result = "左二取货左一有货";
|
break;
|
case 17:
|
result = "右二取货右一有货";
|
break;
|
case 18:
|
result = "左取货失败";
|
break;
|
case 19:
|
result = "右取货失败";
|
break;
|
case 20:
|
result = "左放货失败";
|
break;
|
case 21:
|
result = "右放货失败";
|
break;
|
case 22:
|
result = "货叉运行超时";
|
break;
|
case 23:
|
result = "货叉断路器跳闸";
|
break;
|
case 24:
|
result = "货叉变频器报警";
|
break;
|
case 25:
|
result = "货叉编码器故障";
|
break;
|
case 26:
|
result = "货叉伸叉故障";
|
break;
|
case 27:
|
result = "层运行货叉不在中位";
|
break;
|
case 28:
|
result = "列运行货叉不在中位";
|
break;
|
case 29:
|
result = "货叉中位开关故障";
|
break;
|
case 30:
|
result = "货叉变频器通讯故障";
|
break;
|
case 31:
|
result = "货叉编码器通讯故障";
|
break;
|
case 32:
|
result = "伸叉超出左极限";
|
break;
|
case 33:
|
result = "伸叉超出右极限";
|
break;
|
case 34:
|
result = "入左二货格货时左一货格有货";
|
break;
|
case 35:
|
result = "入右二货格货时右一货格有货";
|
break;
|
case 36:
|
result = "货叉右侧回中停止位置错误";
|
break;
|
case 37:
|
result = "货叉左侧回中停止位置错误";
|
break;
|
case 38:
|
result = "货叉左侧极限停止位置错误";
|
break;
|
case 39:
|
result = "货叉右侧极限停止位置错误";
|
break;
|
case 40:
|
result = "面板急停";
|
break;
|
case 41:
|
result = "远程急停";
|
break;
|
case 42:
|
result = "主接触器控制回路故障";
|
break;
|
case 43:
|
result = "超重保护";
|
break;
|
case 44:
|
result = "松绳保护";
|
break;
|
case 45:
|
result = "限速保护";
|
break;
|
case 46:
|
result = "层停止位置错误";
|
break;
|
case 47:
|
result = "列停止位置错误";
|
break;
|
case 48:
|
result = "列停止位置错误";
|
break;
|
case 49:
|
result = "接收列超限";
|
break;
|
case 50:
|
result = "接收层超限";
|
break;
|
case 51:
|
result = "接收层超限";
|
break;
|
case 52:
|
result = "行走后退极限";
|
break;
|
case 53:
|
result = "提升上极限";
|
break;
|
case 54:
|
result = "提升下极限";
|
break;
|
case 55:
|
result = "行走运行超时";
|
break;
|
case 56:
|
result = "提升运行超时";
|
break;
|
case 57:
|
result = "行走断路器跳闸";
|
break;
|
case 58:
|
result = "提升断路器跳闸";
|
break;
|
case 59:
|
result = "行走变频器故障";
|
break;
|
case 60:
|
result = "提升变频器故障";
|
break;
|
case 61:
|
result = "行走测距/条码故障";
|
break;
|
case 62:
|
result = "提升测距/条码故障";
|
break;
|
case 63:
|
result = "行走测距/条码被挡";
|
break;
|
case 64:
|
result = "提升测距/条码被挡";
|
break;
|
case 65:
|
result = "上升减速光电故障";
|
break;
|
case 66:
|
result = "下降减速光电故障";
|
break;
|
case 67:
|
result = "提升原点光电故障";
|
break;
|
case 68:
|
result = "行走前减速光电故障";
|
break;
|
case 69:
|
result = "行走后减速光电故障";
|
break;
|
case 70:
|
result = "行走原点光电故障";
|
break;
|
case 71:
|
result = "与输送机通讯故障";
|
break;
|
case 72:
|
result = "升降超出最小层";
|
break;
|
case 73:
|
result = "升降超出最大层";
|
break;
|
case 74:
|
result = "行走超出最小列";
|
break;
|
case 75:
|
result = "行走超出最大列";
|
break;
|
case 76:
|
result = "接收排错误";
|
break;
|
case 77:
|
result = "起始站货格被禁用";
|
break;
|
case 78:
|
result = "目的站货格被禁用";
|
break;
|
case 79:
|
result = "行走抱闸故障";
|
break;
|
case 80:
|
result = "提升抱闸故障";
|
break;
|
case 81:
|
result = "安全门打开故障";
|
break;
|
default:
|
result = "";
|
break;
|
}
|
return result;
|
}
|
|
////判断数字是否合法
|
//public static bool ChkFloat(string str)
|
//{
|
// try
|
// {
|
// float f = (float)Convert.ToDouble(str);
|
// return true;
|
// }
|
// catch (Exception e)
|
// {
|
// return false;
|
// }
|
//}
|
////判断整数是否合法
|
//public static bool ChkInt(string str)
|
//{
|
// try
|
// {
|
// int f = Convert.ToInt32(str);
|
// return true;
|
// }
|
// catch (Exception e)
|
// {
|
// return false;
|
// }
|
//}
|
////得到地址
|
//public static string GetAddr(int li)
|
//{
|
// string addr = "";
|
// try
|
// {
|
// switch (li)
|
// {
|
// case 0:
|
// return addr = "1030";
|
// case 1:
|
// return addr = "1032";
|
// case 2:
|
// return addr = "1034";
|
// case 3:
|
// return addr = "1036";
|
// case 4:
|
// return addr = "1038";
|
// case 5:
|
// return addr = "1040";
|
// case 6:
|
// return addr = "1042";
|
// default:
|
// return addr = "";
|
|
// }
|
// }
|
// catch (Exception e)
|
// {
|
// return addr = "";
|
// }
|
//}
|
|
/// <summary>
|
/// 查询erp数据
|
/// </summary>
|
/// <param name="sql"></param>
|
/// <returns></returns>
|
public static DataView ExecErpSelect(string sql)
|
{
|
try
|
{
|
OracleConnection sqlerp = new OracleConnection(erpcon);
|
sqlerp.Open();
|
OracleDataAdapter odasrs = new OracleDataAdapter(sql, sqlerp);
|
DataSet dserp = new DataSet();
|
odasrs.Fill(dserp);
|
DataView dverp = new DataView(dserp.Tables[0]);
|
odasrs.Dispose();
|
sqlerp.Dispose();
|
sqlerp.Close();
|
return dverp;
|
}
|
catch (SqlException em)
|
{
|
return null;
|
}
|
}
|
|
/// <summary>
|
/// 执行ERP数据更新sql语句
|
/// </summary>
|
/// <param name="sql"></param>
|
/// <returns></returns>
|
public static bool ExecERPModify(string sql)
|
{
|
bool result = false;
|
try
|
{
|
OracleConnection sqlconn = new OracleConnection(erpcon);
|
sqlconn.Open();
|
OracleTransaction sqltrans = sqlconn.BeginTransaction();
|
OracleCommand sqlcmd = new OracleCommand();
|
//SqlCommand sqlcmd = new SqlCommand(sql, sqlconn);
|
//sqlcmd.Transaction = sqltrans;
|
string[] arraySql = sql.Split(';');
|
try
|
{
|
for (int i = 0; i < arraySql.Length; i++)
|
{
|
if (arraySql[i] != "")
|
{
|
sqlcmd.CommandText = arraySql[i];
|
sqlcmd.Connection = sqlconn;
|
sqlcmd.Transaction = sqltrans;
|
sqlcmd.ExecuteNonQuery();
|
}
|
}
|
sqltrans.Commit();
|
result = true;
|
}
|
catch (SqlException t)
|
{
|
sqltrans.Rollback();
|
result = false;
|
|
}
|
finally
|
{
|
sqlcmd.Dispose();
|
sqltrans.Dispose();
|
sqlconn.Dispose();
|
//sqlconn.Close();
|
}
|
}
|
catch (Exception r)
|
{
|
return false;
|
}
|
return result;
|
}
|
|
/////-------------------------------从asrs数据库中执行查询功能返回数据集----------------
|
public static DataView ExecAsrsSelect(string sql)
|
{
|
try
|
{
|
SqlConnection sqlasrs = new SqlConnection(sqlcon);
|
sqlasrs.Open();
|
SqlDataAdapter odasrs = new SqlDataAdapter(sql, sqlasrs);
|
DataSet dsasrs = new DataSet();
|
odasrs.Fill(dsasrs);
|
DataView dvasrs = new DataView(dsasrs.Tables[0]);
|
odasrs.Dispose();
|
sqlasrs.Dispose();
|
sqlasrs.Close();
|
return dvasrs;
|
}
|
catch (SqlException em)
|
{
|
return null;
|
}
|
}
|
|
public static DataView ExecAsrsSelect(string sql, out string err)
|
{
|
err = null;
|
try
|
{
|
SqlConnection sqlasrs = new SqlConnection(sqlcon);
|
sqlasrs.Open();
|
SqlDataAdapter odasrs = new SqlDataAdapter(sql, sqlasrs);
|
DataSet dsasrs = new DataSet();
|
odasrs.Fill(dsasrs);
|
DataView dvasrs = new DataView(dsasrs.Tables[0]);
|
odasrs.Dispose();
|
sqlasrs.Dispose();
|
sqlasrs.Close();
|
return dvasrs;
|
}
|
catch (SqlException em)
|
{
|
err = "查询sql语句失败:" + em.Message;
|
//MessageBox.Show("查询sql语句失败:" + em.Message + "\r\n" + sql);
|
return null;
|
}
|
}
|
/////-------------------------------从asrs数据库中执行查询功能返回数据量----------------
|
public static int ExecAsrsSelect1(string sql)
|
{
|
int li_count1 = 0;
|
SqlConnection sqlasrs0 = new SqlConnection(sqlcon);
|
sqlasrs0.Open();
|
SqlCommand ocasrs = new SqlCommand(sql, sqlasrs0);
|
li_count1 = Convert.ToInt32(ocasrs.ExecuteScalar());
|
sqlasrs0.Dispose();
|
ocasrs.Dispose();
|
sqlasrs0.Close();
|
|
return li_count1;
|
}
|
/////-------------------------------从asrs数据库中执行异动功能(提交)----------------
|
/// <summary>
|
/// 执行sql更新语句(insert、delete、update)
|
/// </summary>
|
/// <param name="sql"></param>
|
/// <returns></returns>
|
public static bool ExecAsrsModify(string sql)
|
{
|
bool result = false;
|
try
|
{
|
SqlConnection sqlconn = new SqlConnection(sqlcon);
|
sqlconn.Open();
|
SqlTransaction sqltrans = sqlconn.BeginTransaction();
|
SqlCommand sqlcmd = new SqlCommand();
|
//SqlCommand sqlcmd = new SqlCommand(sql, sqlconn);
|
//sqlcmd.Transaction = sqltrans;
|
string[] arraySql = sql.Split(';');
|
try
|
{
|
for (int i = 0; i < arraySql.Length; i++)
|
{
|
if (arraySql[i] != "")
|
{
|
sqlcmd.CommandText = arraySql[i];
|
sqlcmd.Connection = sqlconn;
|
sqlcmd.Transaction = sqltrans;
|
sqlcmd.ExecuteNonQuery();
|
}
|
}
|
sqltrans.Commit();
|
result = true;
|
}
|
catch (SqlException em)
|
{
|
WriteLogFile("WcsError", "Common/ExecAsrsModify--执行SQL语句发生异常:" + em.Message + "\r\n" + sql);
|
sqltrans.Rollback();
|
result = false;
|
|
}
|
finally
|
{
|
sqlcmd.Dispose();
|
sqltrans.Dispose();
|
sqlconn.Dispose();
|
//sqlconn.Close();
|
}
|
}
|
catch (Exception r)
|
{
|
return false;
|
}
|
return result;
|
}
|
///////-------------------------------从asrs数据库中执行异动功能(未提交)----------------
|
//public static bool ExecAsrsModify1(string sql)
|
//{
|
// bool result = false;
|
// SqlConnection sqlasrs1 = new SqlConnection(sqlcon);
|
// sqlasrs1.Open();
|
// SqlTransaction otasrs = sqlasrs1.BeginTransaction();
|
// SqlCommand ocom = new SqlCommand(sql, sqlasrs1);
|
// ocom.Transaction = otasrs;
|
// try
|
// {
|
// ocom.ExecuteNonQuery();
|
// //otasrs.Commit();
|
// result = true;
|
// }
|
// catch (SqlException t)
|
// {
|
// otasrs.Rollback();
|
// result = false;
|
|
// }
|
// finally
|
// {
|
// ocom.Dispose();
|
// otasrs.Dispose();
|
// sqlasrs1.Dispose();
|
// sqlasrs1.Close();
|
// }
|
// return result;
|
//}
|
///////-------------------------------从asrs数据库中执行异动功能(两个表),同步执行----------------
|
//public static bool ExecAsrsModifyByMD(string sql, string sql1)
|
//{
|
// bool result = false;
|
// SqlConnection sqlasrs1 = new SqlConnection(sqlcon);
|
// sqlasrs1.Open();
|
// SqlTransaction otasrs = sqlasrs1.BeginTransaction();
|
// SqlCommand ocom = new SqlCommand(sql, sqlasrs1);
|
// SqlCommand ocom1 = new SqlCommand(sql1, sqlasrs1);
|
// ocom.Transaction = otasrs;
|
// ocom1.Transaction = otasrs;
|
// try
|
// {
|
// ocom.ExecuteNonQuery();
|
// ocom1.ExecuteNonQuery();
|
// otasrs.Commit();
|
// result = true;
|
// }
|
// catch (SqlException t)
|
// {
|
// otasrs.Rollback();
|
// result = false;
|
|
// }
|
// finally
|
// {
|
// ocom.Dispose();
|
// otasrs.Dispose();
|
// sqlasrs1.Dispose();
|
// sqlasrs1.Close();
|
// }
|
// return result;
|
//}
|
///////-------------------------------从asrs数据库中执行异动功能(4个表),同步执行----------------
|
//public static bool ExecAsrsModifyByMD(string sql, string sql1, string sql2, string sql3)
|
//{
|
// bool result = false;
|
// SqlConnection sqlasrs1 = new SqlConnection(sqlcon);
|
// sqlasrs1.Open();
|
// SqlTransaction otasrs = sqlasrs1.BeginTransaction();
|
// SqlCommand ocom = new SqlCommand(sql, sqlasrs1);
|
// SqlCommand ocom1 = new SqlCommand(sql1, sqlasrs1);
|
// SqlCommand ocom2 = new SqlCommand(sql2, sqlasrs1);
|
// SqlCommand ocom3 = new SqlCommand(sql3, sqlasrs1);
|
// ocom.Transaction = otasrs;
|
// ocom1.Transaction = otasrs;
|
// ocom2.Transaction = otasrs;
|
// ocom3.Transaction = otasrs;
|
// try
|
// {
|
// ocom.ExecuteNonQuery();
|
// ocom1.ExecuteNonQuery();
|
// ocom2.ExecuteNonQuery();
|
// ocom3.ExecuteNonQuery();
|
// otasrs.Commit();
|
// result = true;
|
// }
|
// catch (SqlException t)
|
// {
|
// otasrs.Rollback();
|
// result = false;
|
|
// }
|
// finally
|
// {
|
// ocom.Dispose();
|
// otasrs.Dispose();
|
// sqlasrs1.Dispose();
|
// sqlasrs1.Close();
|
// }
|
// return result;
|
//}
|
/////-------------------------------从asrs数据库中执行异动功能(5个表),同步执行----------------
|
public static bool ExecAsrsModifyByMD(string sql, string sql1, string sql2, string sql3, string sql4)
|
{
|
bool result = false;
|
SqlConnection sqlasrs1 = new SqlConnection(sqlcon);
|
sqlasrs1.Open();
|
SqlTransaction otasrs = sqlasrs1.BeginTransaction();
|
SqlCommand ocom = new SqlCommand(sql, sqlasrs1);
|
SqlCommand ocom1 = new SqlCommand(sql1, sqlasrs1);
|
SqlCommand ocom2 = new SqlCommand(sql2, sqlasrs1);
|
SqlCommand ocom3 = new SqlCommand(sql3, sqlasrs1);
|
SqlCommand ocom4 = new SqlCommand(sql4, sqlasrs1);
|
ocom.Transaction = otasrs;
|
ocom1.Transaction = otasrs;
|
ocom2.Transaction = otasrs;
|
ocom3.Transaction = otasrs;
|
ocom4.Transaction = otasrs;
|
try
|
{
|
ocom.ExecuteNonQuery();
|
ocom1.ExecuteNonQuery();
|
ocom2.ExecuteNonQuery();
|
ocom3.ExecuteNonQuery();
|
ocom4.ExecuteNonQuery();
|
otasrs.Commit();
|
result = true;
|
}
|
catch (SqlException t)
|
{
|
otasrs.Rollback();
|
result = false;
|
|
}
|
finally
|
{
|
ocom.Dispose();
|
otasrs.Dispose();
|
sqlasrs1.Dispose();
|
sqlasrs1.Close();
|
}
|
return result;
|
}
|
///////-------------------------------从ASRS数据库中执行查询功能返回数据量----------------
|
//public static int ExecASRSSelect1(string sql)
|
//{
|
// int li_count1 = 0;
|
// SqlConnection sqlasrs = new SqlConnection(sqlcon);
|
// sqlasrs.Open();
|
// SqlCommand ocerp = new SqlCommand(sql, sqlasrs);
|
// li_count1 = Convert.ToInt32(ocerp.ExecuteScalar());
|
// ocerp.Dispose();
|
// sqlasrs.Dispose();
|
// sqlasrs.Close();
|
// return li_count1;
|
//}
|
|
/// <summary>
|
/// 根据库位状态代号返回库位状态名称
|
/// </summary>
|
/// <param name="locsts"></param>
|
/// <returns></returns>
|
public static string getlocsts(string locsts)
|
{
|
string locstsname = "";
|
switch (locsts)
|
{
|
case "O":
|
locstsname = "O-空库位";
|
break;
|
case "F":
|
locstsname = "F-在库";
|
break;
|
case "S":
|
locstsname = "S-入库预约中";
|
break;
|
case "R":
|
locstsname = "R-出库预约中";
|
break;
|
case "P":
|
locstsname = "P-拣料/并板/盘点出库预约中";
|
break;
|
case "L":
|
locstsname = "L-拣料库位空载中";
|
break;
|
case "M":
|
locstsname = "M-拣料库位满载中";
|
break;
|
case "Q":
|
locstsname = "Q-拣料/并板/盘点再入库预约中";
|
break;
|
case "X":
|
locstsname = "X-禁用";
|
break;
|
case "D":
|
locstsname = "D-空栈板";
|
break;
|
default:
|
locstsname = "O-空库位";
|
break;
|
}
|
return locstsname;
|
}
|
|
/// <summary>
|
/// 根据工作状态代号得到工作状态名称
|
/// </summary>
|
/// <param name="sts"></param>
|
/// <returns></returns>
|
public static string Getwrksts(string sts)
|
{
|
string wrkstsname = "";
|
switch (sts)
|
{
|
case "1":
|
wrkstsname = "1.生成入库ID";
|
break;
|
case "2":
|
wrkstsname = "2.设备上移动";
|
break;
|
case "3":
|
wrkstsname = "3.堆垛机入库中";
|
break;
|
case "4":
|
wrkstsname = "4.堆垛机入库完成";
|
break;
|
case "5":
|
wrkstsname = "5.入库回报完成";
|
break;
|
//case "6":
|
// wrkstsname = "6.2号堆垛机站到站中";
|
// break;
|
//case "7":
|
// return "7.5站到6站移动中";
|
// break;
|
//case "8":
|
// return "8.7站到8站移动中";
|
// break;
|
//case "9":
|
// return "9.2号堆垛机站到站完成";
|
// break;
|
case "11":
|
wrkstsname = "11.生成出库ID";
|
break;
|
case "12":
|
wrkstsname = "12.堆垛机出库中";
|
break;
|
case "13":
|
wrkstsname = "13.空出库";
|
break;
|
case "14":
|
wrkstsname = "14.堆垛机出库完成";
|
break;
|
case "15":
|
wrkstsname = "15.出库回报完成";
|
break;
|
case "16":
|
wrkstsname = "16.LED指令完成";
|
break;
|
}
|
return wrkstsname;
|
}
|
|
/// <summary>
|
/// 根据IO类型代号得到IO名称
|
/// </summary>
|
/// <param name="sts"></param>
|
/// <returns></returns>
|
public static string Getiotype(string sts)
|
{
|
string iotypename = "";
|
switch (sts)
|
{
|
case "1":
|
iotypename = "1.入库";
|
break;
|
case "6":
|
iotypename = "6.退库";
|
break;
|
case "10":
|
iotypename = "10.空桶入库";
|
break;
|
case "110":
|
iotypename = "110.空桶出库";
|
break;
|
case "101":
|
iotypename = "101.全板出库";
|
break;
|
case "103":
|
iotypename = "103.拣料出库";
|
break;
|
case "104":
|
iotypename = "104.并板出库";
|
break;
|
case "107":
|
iotypename = "107.盘点出库";
|
break;
|
case "53":
|
iotypename = "53.拣料再入库";
|
break;
|
case "57":
|
iotypename = "57.盘点再入库";
|
break;
|
case "54":
|
iotypename = "54.并板再入库";
|
break;
|
}
|
return iotypename;
|
}
|
|
/// <summary>
|
/// 根据拣料站得到再入库堆垛机站点
|
/// </summary>
|
/// <param name="crn"></param>
|
/// <param name="stn"></param>
|
/// <returns></returns>
|
public static int GetRestoreStnByPick(int crn, int stn)
|
{
|
int stnno = 0;
|
switch (crn)
|
{
|
case 1:
|
stnno = 106;
|
break;
|
case 2:
|
stnno = 120;
|
break;
|
|
case 3:
|
stnno = 133;
|
break;
|
|
|
|
|
|
}
|
return stnno;
|
}
|
|
/// <summary>
|
/// 根据站号得到对应吊车站序号
|
/// </summary>
|
/// <param name="stn"></param>
|
/// <returns></returns>
|
public static int GetCrnStnSeq(int stn)
|
{
|
int crnstn = 0;
|
switch (stn)
|
{
|
case 100:
|
crnstn = 1;
|
break;
|
case 200:
|
crnstn = 2;
|
break;
|
case 104:
|
crnstn = 1;
|
break;
|
case 204:
|
crnstn = 2;
|
break;
|
default:
|
crnstn = 0;
|
break;
|
}
|
return crnstn;
|
}
|
|
/// <summary>
|
/// 根据堆垛机入库站号得到站点编号
|
/// </summary>
|
/// <param name="crn">堆垛机号</param>
|
/// <param name="seq">堆垛机站点编号</param>
|
/// <returns>输送机站点编号</returns>
|
public static int GetStnSeqNo(int crn, int seq)
|
{
|
int stnno = 0;
|
switch (crn)
|
{
|
case 1:
|
switch (seq)
|
{
|
case 1:
|
stnno = 104;
|
break;
|
//case 2:
|
// stnno = 104;
|
// break;
|
}
|
break;
|
case 2:
|
switch (seq)
|
{
|
case 1:
|
stnno = 204;
|
break;
|
}
|
break;
|
default:
|
stnno = seq;
|
break;
|
}
|
return stnno;
|
}
|
|
/// <summary>
|
/// 判断字符串是否数字
|
/// </summary>
|
/// <param name="ls_string"></param>
|
/// <returns></returns>
|
public static bool ChkStrtoInt(string ls_string)
|
{
|
bool result = false;
|
int i = 0, i_len = 0;
|
i_len = ls_string.Length;
|
for (i = 0; i < i_len; i++)
|
{
|
if (ls_string[i] >= '0' && ls_string[i] <= '9')
|
// if (Convert.ToInt32(ls_string[i].ToString()) >= 0 && Convert.ToInt32(ls_string[i].ToString()) <= 9)
|
{
|
result = true;
|
}
|
else
|
{
|
result = false;
|
break;
|
}
|
}
|
return result;
|
|
}
|
|
/// <summary>
|
/// 写日志文件
|
/// </summary>
|
/// <param name="Memo">写入内容</param>
|
public static void WriteLogFile(string fileName, string Memo)
|
{
|
DateTime dt = DateTime.Now;
|
string FileName = Application.StartupPath + "\\log\\" + fileName + string.Format("{0:yyyyMMdd}", dt) + ".log";
|
try
|
{
|
if (!Directory.Exists(Application.StartupPath + "\\log"))
|
{
|
Directory.CreateDirectory(Application.StartupPath + "\\log");
|
}
|
|
StreamWriter fs1 = new StreamWriter(FileName, true);//创建写入文件
|
//StreamWriter sw = new StreamWriter(fs1);
|
fs1.WriteLine("【" + DateTime.Now.ToString() + "】" + Memo);//开始写入值
|
|
//sw.Close();
|
fs1.Close();
|
}
|
catch (Exception)
|
{
|
}
|
}
|
|
/// <summary>
|
/// DateTime时间格式转换为Unix时间戳格式
|
/// </summary>
|
/// <param name=”time”></param>
|
/// <returns></returns>
|
public static int ConvertDateTimeInt(System.DateTime time)
|
{
|
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
|
return (int)(time - startTime).TotalSeconds;
|
|
}
|
|
///// <summary>
|
///// 判断工作档中入库资料数量
|
///// </summary>
|
///// <returns></returns>
|
//public static int GetWrkInCount()
|
//{
|
// int result = 1000;
|
// try
|
// {
|
// string sql = "select * from asr_wrk_mast where wrk_sts>0 and wrk_sts<5";
|
// result = Common.ExecAsrsSelect1(sql);
|
// }
|
// catch (Exception)
|
// {
|
// }
|
// return result;
|
//}
|
|
///// <summary>
|
///// 判断工作档中出库资料数量
|
///// </summary>
|
///// <returns></returns>
|
//public static int GetWrkOutCount()
|
//{
|
// int result = 1000;
|
// try
|
// {
|
// string sql = "select * from asr_wrk_mast where wrk_sts>11 and wrk_sts<15";
|
// result = Common.ExecAsrsSelect1(sql);
|
// }
|
// catch (Exception)
|
// {
|
// }
|
// return result;
|
//}
|
|
///// <summary>
|
///// 判断工作档中资料数量
|
///// </summary>
|
///// <returns></returns>
|
//public static int GetWrkCount()
|
//{
|
// int result = 1000;
|
// try
|
// {
|
// string sql = "select * from asr_wrk_mast where wrk_sts<15";
|
// result = Common.ExecAsrsSelect1(sql);
|
// }
|
// catch (Exception)
|
// {
|
// }
|
// return result;
|
//}
|
|
///// <summary>
|
///// 判断库存档中库存资料是否存在
|
///// </summary>
|
///// <returns></returns>
|
//public static int GetStkCount(string boxId)
|
//{
|
// int result = 1000;
|
// try
|
// {
|
// string sql = "select * from asr_loc_mast where boxId='" + boxId + "'";
|
// result = Common.ExecAsrsSelect1(sql);
|
// }
|
// catch (Exception)
|
// {
|
// }
|
// return result;
|
//}
|
|
/// <summary>
|
/// 检查数据库连接是否正常
|
/// </summary>
|
/// <returns></returns>
|
public static bool CheckDbConnect()
|
{
|
bool result = false;
|
SqlConnection conn = new SqlConnection(Common.sqlcon);
|
try
|
{
|
if (conn.State == ConnectionState.Closed)
|
conn.Open();
|
else if (conn.State == ConnectionState.Broken)
|
{
|
conn.Close();
|
conn.Open();
|
}
|
result = true;
|
}
|
catch (Exception em)
|
{
|
//MessageBox.Show("数据库连接失败。" + em.Message, "错误");
|
}
|
finally
|
{
|
conn.Close();
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 检测端口是否占用
|
/// </summary>
|
/// <param name="port"></param>
|
/// <returns></returns>
|
public static bool PortInUse(int port)
|
{
|
bool inUse = false;
|
|
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
|
IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
|
|
foreach (IPEndPoint endPoint in ipEndPoints)
|
{
|
if (endPoint.Port == port)
|
{
|
inUse = true;
|
break;
|
}
|
}
|
return inUse;
|
}
|
|
/// <summary>
|
/// 根据输送机站点获取对应库位号
|
/// </summary>
|
/// <param name="i_stn">堆垛机状态值</param>
|
/// <returns>库位号</returns>
|
public static string GetLocByStn(int i_stn)
|
{
|
string loc_no = "0000000";
|
switch (i_stn)
|
{
|
case 100:
|
loc_no = "0200101";
|
break;
|
case 104:
|
loc_no = "0300101";
|
break;
|
case 200:
|
loc_no = "0400101";
|
break;
|
case 204:
|
loc_no = "0500101";
|
break;
|
default:
|
loc_no = "0000000";
|
break;
|
}
|
return loc_no;
|
}
|
|
/// <summary>
|
/// 根据库位号获取对应输送机站点编号
|
/// </summary>
|
/// <param name="i_stn">堆垛机状态值</param>
|
/// <returns>库位号</returns>
|
public static int GetStnByLoc(string loc_no)
|
{
|
int i_stn = 0;
|
switch (loc_no)
|
{
|
case "0200101":
|
i_stn = 100;
|
break;
|
case "0300101":
|
i_stn = 104;
|
break;
|
case "0400101":
|
i_stn = 200;
|
break;
|
case "0500101":
|
i_stn = 204;
|
break;
|
default:
|
i_stn = 0;
|
break;
|
}
|
return i_stn;
|
}
|
|
#region 堆垛机异常列表
|
/// <summary>
|
/// 根据堆垛机异常码得到异常名称
|
/// </summary>
|
/// <param name="AlarmCode">堆垛机异常码</param>
|
/// <returns>堆垛机异常名称</returns>
|
public static string GetCrnErrorName(int AlarmCode)
|
{
|
string errorName = "";
|
switch (AlarmCode)
|
{
|
case 0:
|
errorName = "";
|
break;
|
case 1:
|
errorName = "主电源断路器断开";
|
break;
|
case 2:
|
errorName = "相位变化或缺相";
|
break;
|
case 3:
|
errorName = "内部 24V 供电异常";
|
break;
|
case 4:
|
errorName = "外部 24V 供电异常";
|
break;
|
case 5:
|
errorName = "24V总断路器异常";
|
break;
|
case 6:
|
errorName = "总交流接触器异常";
|
break;
|
case 7:
|
errorName = "行走抱闸接触器异常";
|
break;
|
case 8:
|
errorName = "起升抱闸接触器异常";
|
break;
|
case 9:
|
errorName = "货叉抱闸接触器异常";
|
break;
|
case 11:
|
errorName = "行走变频器报警";
|
break;
|
case 12:
|
errorName = "起升变频器报警";
|
break;
|
case 13:
|
errorName = "货叉变频器报警";
|
break;
|
case 14:
|
errorName = "行走马达保护器异常";
|
break;
|
case 15:
|
errorName = "起升马达保护器异常";
|
break;
|
case 16:
|
errorName = "货叉马达保护器异常";
|
break;
|
case 18:
|
errorName = "货叉位置错误";
|
break;
|
case 19:
|
errorName = "货叉触发左极限";
|
break;
|
case 20:
|
errorName = "货叉触发右极限";
|
break;
|
case 21:
|
errorName = "载货台货物左后超限";
|
break;
|
case 22:
|
errorName = "载货台货物左前超限";
|
break;
|
case 23:
|
errorName = "载货台货物右后超限";
|
break;
|
case 24:
|
errorName = "载货台货物右前超限";
|
break;
|
case 25:
|
errorName = "载货台货物左坍塌";
|
break;
|
case 26:
|
errorName = "载货台货物左超高";
|
break;
|
case 27:
|
errorName = "行走电机位置值未变动";
|
break;
|
case 28:
|
errorName = "起升电机位置值未变动";
|
break;
|
case 29:
|
errorName = "载货台货物右超高";
|
break;
|
case 30:
|
errorName = "货叉电机位置值未变动";
|
break;
|
case 32:
|
errorName = "载货台货物右坍塌";
|
break;
|
case 33:
|
errorName = "行走激光丢失";
|
break;
|
case 34:
|
errorName = "行走停准失败";
|
break;
|
case 35:
|
errorName = "起升激光丢失";
|
break;
|
case 36:
|
errorName = "起升停准失败";
|
break;
|
case 37:
|
errorName = "货叉测距异常";
|
break;
|
case 38:
|
errorName = "货叉停准失败";
|
break;
|
case 39:
|
errorName = "变频器总线IO通讯断开";
|
break;
|
case 42:
|
errorName = "行走电机运行超时";
|
break;
|
case 43:
|
errorName = "起升电机运行超时";
|
break;
|
case 44:
|
errorName = "货叉电机运行超时";
|
break;
|
case 45:
|
errorName = "载货台安全回路断开";
|
break;
|
case 47:
|
errorName = "柜门急停";
|
break;
|
case 49:
|
errorName = "松绳保护开关触发";
|
break;
|
case 51:
|
errorName = "外部急停或安全门打开";
|
break;
|
case 53:
|
errorName = "相序保护器异常";
|
break;
|
case 54:
|
errorName = "安全继电器异常";
|
break;
|
case 55:
|
errorName = "水平极限开关被触发";
|
break;
|
case 56:
|
errorName = "起升下极限开关触发";
|
break;
|
case 57:
|
errorName = "起升超速保护开关触发";
|
break;
|
case 58:
|
errorName = "起升上极限开关触发";
|
break;
|
case 61:
|
errorName = "放货时货架有货";
|
break;
|
case 62:
|
errorName = "自动模式无任务载货台有货";
|
break;
|
case 63:
|
errorName = "放货后载货台有货";
|
break;
|
case 64:
|
errorName = "取货后载货台无货";
|
break;
|
case 66:
|
errorName = "目标位置未找到";
|
break;
|
case 67:
|
errorName = "输送机不允许取货/放货";
|
break;
|
case 69:
|
errorName = "任务地址错误";
|
break;
|
case 71:
|
errorName = "上一任务未完成警告";
|
break;
|
case 75:
|
errorName = "上位机下发急停";
|
break;
|
case 76:
|
errorName = "电控柜门打开";
|
break;
|
case 85:
|
errorName = "载货台远程IO断开";
|
break;
|
case 87:
|
errorName = "触摸屏急停";
|
break;
|
case 101:
|
errorName = "货叉在中位没有中位开关信号";
|
break;
|
case 102:
|
errorName = "货叉在非中位有中位信号";
|
break;
|
default:
|
errorName = "未知";
|
break;
|
}
|
return errorName;
|
}
|
#endregion
|
|
}
|
}
|