void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 //txtLogFolder = WFNetLib.aspNetFunc.GetRootPath(); WFNetLib.ADO.SQLServerOP.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ApplicationServices"].ToString(); ESLQueueDataDBOption.deleteAll(); bRun = true; Thread t = new Thread(ESLWork.ESLPass); t.Start(); KeyDataQueueDataDBOption.deleteAll(); Thread t1 = new Thread(KeyDataWork.KeyDataWorkThread); t1.Start(); Thread t2 = new Thread(ClearHPassLog.ClearHPassLogThread); t2.Start(); WFNetLib.Log.TextLog.AddTextLog("web Start", Global.txtLogFolder + "workLog.txt", true); }
protected void Page_Load(object sender, EventArgs e) { string DeviceID, pass, sTime; string ret = webAPIFunc.GetRetString(ErrType.UnkownErr); try { DeviceID = Request.QueryString["DeviceID"]; pass = Request.QueryString["pass"]; sTime = Request.QueryString["sTime"]; //信息|用户id|实验id,实验名,实验室; if (string.IsNullOrEmpty(DeviceID) || string.IsNullOrEmpty(pass))//没有这两个变量 { ret = webAPIFunc.GetRetString(ErrType.MissParam); Response.Write(ret); return; } if (DeviceInfoDataDBOption.Get(DeviceID) == null) { ret = webAPIFunc.GetRetString(ErrType.NoRegDevice); Response.Write(ret); return; } DataTable dt = ESLRecodeDataDBOption.DataTableSelect(pass); if (dt.Rows.Count == 0) { if (sTime == "-1")//新的查询 { int que = ESLQueueDataDBOption.GetIndex(pass); if (que == -1)//新的查询 { ESLQueueData d = new ESLQueueData(); d.Pass = pass; d.DeviceID = DeviceID; d.IP = WFNetLib.aspNetFunc.getIp(); ESLQueueDataDBOption.Insert(d); que = ESLQueueDataDBOption.GetIndex(pass); ret = webAPIFunc.GetRetString(2, que.ToString() + "|" + d.sTime.ToString()); // ret = "2," + que.ToString(); // ret += "," + d.sTime.ToString(); if (ESLWork.bCalc == false) { ESLWork.autoResetEvent.Set(); } } else { ret = "3," + que.ToString(); } } else { dt = ESLWorkLogDataDBOption.DataTableSelect(pass, WFNetLib.aspNetFunc.getIp(), DeviceID, sTime); if (dt.Rows.Count != 0) { ret = "-4,"; } else { int que = ESLQueueDataDBOption.GetIndex(pass); if (que == -1)//新的查询 { ESLQueueData d = new ESLQueueData(); d.Pass = pass; d.DeviceID = DeviceID; d.IP = WFNetLib.aspNetFunc.getIp(); ESLQueueDataDBOption.Insert(d); que = ESLQueueDataDBOption.GetIndex(pass); ret = webAPIFunc.GetRetString(2, que.ToString() + "|" + d.sTime.ToString()); // ret = "2," + que.ToString(); // ret += "," + d.sTime.ToString(); if (ESLWork.bCalc == false) { ESLWork.autoResetEvent.Set(); } } else { ret = "3," + que.ToString(); } } } } else { ret = "1,"; // for (int i = 0; i < dt.Rows.Count; i++) // { ret += dt.Rows[0]["Ret"];// +","; // } } } catch (System.Exception ex) { ret = webAPIFunc.GetRetString(ErrType.UnkownErr);//"-100," + ex.Message; TextLog.AddTextLog("Unkown:" + ex.Message, Global.txtLogFolder + "ESLPass.txt", true); } Response.Write(ret); }
public static void ESLPass() { UInt32 numBytesRead = 0; int retryMax = 10; int retry = retryMax; while (Global.bRun) { bCalc = false; autoResetEvent.WaitOne(); bCalc = true; while (true) { bool bOK = false; ESLQueueData eq = ESLQueueDataDBOption.GetFirst(); if (eq == null) { break; } ESLWorkLogData elog = new ESLWorkLogData(); elog.Pass = eq.Pass; elog.IP = eq.IP; elog.sTime = eq.sTime; elog.DeviceID = eq.DeviceID; try { byte[] bPass = WFNetLib.StringFunc.StringsFunction.strToHexByte(eq.Pass, ""); byte[] rxbuf = new byte[100]; retry = retryMax; while (retry != 0) { retry--; try { UInt32 ftdiDeviceCount = 0; FTDI.FT_STATUS ftStatus = FTDI.FT_STATUS.FT_OK; FTDI myFtdiDevice = new FTDI(); // ftStatus = myFtdiDevice.GetNumberOfDevices(ref ftdiDeviceCount); // if (ftStatus != FTDI.FT_STATUS.FT_OK) // { // continue; // } // if (ftdiDeviceCount == 0) // { // continue; // } // FTDI.FT_DEVICE_INFO_NODE[] ftdiDeviceList = new FTDI.FT_DEVICE_INFO_NODE[ftdiDeviceCount]; // ftStatus = myFtdiDevice.GetDeviceList(ftdiDeviceList); // if (ftStatus == FTDI.FT_STATUS.FT_OK) // { // bool bFind = false; // for (int i = 0; i < ftdiDeviceCount;i++ ) // { // if (ftdiDeviceList[i].SerialNumber.ToString() == "001054") // { // ftStatus = myFtdiDevice.OpenBySerialNumber(ftdiDeviceList[i].SerialNumber.ToString()); // if (ftStatus != FTDI.FT_STATUS.FT_OK) // { // //continue; // break; // } // bFind = true; // break; // } // } // if(!bFind) // continue; // } // else // { // continue; // } ftStatus = myFtdiDevice.OpenBySerialNumber("DA00UTH1"); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } ftStatus = myFtdiDevice.ResetDevice(); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } ftStatus = myFtdiDevice.SetBaudRate(300); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } ftStatus = myFtdiDevice.SetTimeouts(30000, 30000); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } byte[] txbuf = new byte[100]; txbuf[0] = 0xf0; ftStatus = myFtdiDevice.Write(txbuf, 1, ref numBytesRead); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } Thread.Sleep(200); txbuf[0] = 0x30; txbuf[1] = 0x00; for (int i = 0; i < 8; i++) { txbuf[2 + i] = bPass[i]; } txbuf[10] = WFNetLib.Verify.GetVerify_byteSum(txbuf, 10); ftStatus = myFtdiDevice.Write(txbuf, 11, ref numBytesRead); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } ftStatus = myFtdiDevice.Read(rxbuf, 11, ref numBytesRead); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } ftStatus = myFtdiDevice.Close(); if (ftStatus != FTDI.FT_STATUS.FT_OK) { continue; } if (rxbuf[2] == 0x80 && rxbuf[3] == 0x00 && rxbuf[4] == 0x00 && rxbuf[5] == 0x00 && rxbuf[6] == 0x00 && rxbuf[7] == 0x00 && rxbuf[8] == 0x00 && rxbuf[9] == 0x00) { Thread.Sleep(5000); continue; } if (rxbuf[2] == 0x00 && rxbuf[3] == 0x00 && rxbuf[4] == 0x00 && rxbuf[5] == 0x00 && rxbuf[6] == 0x00 && rxbuf[7] == 0x00 && rxbuf[8] == 0x00 && rxbuf[9] == 0x00) { Thread.Sleep(5000); continue; } bOK = true; break; } catch { } } if (bOK) { ESLRecodeData esl = new ESLRecodeData(); esl.Pass = eq.Pass; esl.Ret = WFNetLib.StringFunc.StringsFunction.byteToHexStr(rxbuf, 2, 8, ""); ESLRecodeDataDBOption.Insert(esl); elog.Ret = esl.Ret; } else { elog.Ret = "err"; } ESLWorkLogDataDBOption.Insert(elog); ESLQueueDataDBOption.delete(eq.Pass, eq.IP, eq.DeviceID, eq.sTime.ToString()); } catch (System.Exception ex) { elog.Ret = "err"; ESLWorkLogDataDBOption.Insert(elog); ESLQueueDataDBOption.delete(eq.Pass, eq.IP, eq.DeviceID, eq.sTime.ToString()); TextLog.AddTextLog("Thread_Unkown:" + ex.Message, Global.txtLogFolder + "ESLPass.txt", true); } } } }