/// <summary> /// 抹除所有数据 /// </summary> private void OrderSend_DeleteRecord(int machineID) { byte[] data = { 0xC0, 0x00, 0xE9, 0x00, 0x00, 0x00, 0x00, 0xC1 }; byte[] iMachineID = BitConverter.GetBytes(machineID); data[1] = iMachineID[0]; byte lowCRC; byte highCRC; ReaderGeneral.CRC16_CCITT(data, out highCRC, out lowCRC); data[5] = lowCRC; data[6] = highCRC; try { if (this._SendClient != null) { this._SendClient.Send(data); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取机器时间 /// </summary> public void OrderSend_GetMacTime(int iMachineID) { byte[] arrDataSend = { 0xC0, 0x00, 0xAA, 0x00, 0x00, 0x00, 0xC1 }; byte[] bMacID = BitConverter.GetBytes(iMachineID); arrDataSend[1] = bMacID[0]; byte bLowCRC; byte bHighCRC; ReaderGeneral.CRC16_CCITT(arrDataSend, out bHighCRC, out bLowCRC); arrDataSend[4] = bLowCRC; arrDataSend[5] = bHighCRC; try { if (this._SendClient != null) { this._SendClient.Send(arrDataSend); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取批量数据 /// </summary> private void OrderSend_GetBatchData(int iMachineID) { byte[] arrDataSend = { 0xC0, 0x00, 0x05, 0x00, 0x00, 0x00, 0xC1 }; byte[] bMacID = BitConverter.GetBytes(iMachineID); arrDataSend[1] = bMacID[0]; byte bLowCRC; byte bHighCRC; ReaderGeneral.CRC16_CCITT(arrDataSend, out bHighCRC, out bLowCRC); arrDataSend[4] = bLowCRC; arrDataSend[5] = bHighCRC; try { if (this._SendClient != null) { ReaderGeneral.ConsoleWrite("Begin Send...." + iMachineID.ToString()); if (this._listHistoryIndex.Count > 1024 * 100) { this._listHistoryIndex.Clear(); } this._SendClient.Send(arrDataSend); ReaderGeneral.ConsoleWrite("End Send...." + iMachineID.ToString()); } } catch (Exception ex) { ReaderGeneral.ConsoleWrite(ex.Message); //throw ex; } }
/// <summary> /// 获取数据已上传完毕的回发指令 /// </summary> /// <returns></returns> private string GetUploadedCollectionInstruction(int iMacID) { if (iMacID == 0) { return(null); } string strInst = string.Empty; byte[] data = { 0xC2, 0x00, 0x09, 0x00, 0x00, 0x00, 0xC3 }; byte[] iMachineID = BitConverter.GetBytes(iMacID); data[1] = iMachineID[0]; byte lowCRC; byte highCRC; ReaderGeneral.CRC16_CCITT(data, out highCRC, out lowCRC); data[4] = lowCRC; data[5] = highCRC; string strTmp = BitConverter.ToString(data); string[] arrTmp = strTmp.Split('-'); if (arrTmp.Length != 7) { return(null); } foreach (string strItem in arrTmp) { strInst += strItem; } return(strInst); }
/// <summary> /// 指令发送-批量确定数据 /// </summary> /// <param name="iMacID">机号</param> /// <param name="strRecordIndex">流水号</param> private void OrderSend_ConfirmBatchData(int iMacID, string strRecordIndex) { byte[] arrDataSend = { 0xC0, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0xC1 }; byte[] byMacID = BitConverter.GetBytes(iMacID); arrDataSend[1] = byMacID[0]; int iRecordIndex = Convert.ToInt32(strRecordIndex, 16); byte[] byRecordIndex = BitConverter.GetBytes(iRecordIndex); arrDataSend[4] = byRecordIndex[1]; arrDataSend[5] = byRecordIndex[0]; byte lowCRC; byte highCRC; ReaderGeneral.CRC16_CCITT(arrDataSend, out highCRC, out lowCRC); arrDataSend[6] = lowCRC; arrDataSend[7] = highCRC; try { this.axMSComm05.Output = arrDataSend; Application.DoEvents(); } catch (Exception ex) { throw ex; } }
/// <summary> /// 指令发送-校对读写器时间 /// </summary> /// <param name="strMacID">机号</param> private void OrderSend_ResetTime(string strMacID) { byte[] data = { 0xC0, 0xFF, 0xA9, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1 }; int imacID = 0; if (!string.IsNullOrEmpty(strMacID) && int.TryParse(strMacID, out imacID)) { byte[] bMacID = BitConverter.GetBytes(imacID); data[1] = bMacID[0]; } int year = DateTime.Now.Year - 2000; int month = DateTime.Now.Month; int day = DateTime.Now.Day; int hour = DateTime.Now.Hour; int minute = DateTime.Now.Minute; int second = DateTime.Now.Second; data[4] = BitConverter.GetBytes(year)[0]; data[5] = BitConverter.GetBytes(month)[0]; data[6] = BitConverter.GetBytes(day)[0]; data[7] = BitConverter.GetBytes(hour)[0]; data[8] = BitConverter.GetBytes(minute)[0]; data[9] = BitConverter.GetBytes(second)[0]; byte lowCRC; byte highCRC; ReaderGeneral.CRC16_CCITT(data, out highCRC, out lowCRC); data[11] = lowCRC; data[12] = highCRC; try { this.axMSComm05.Output = data; Application.DoEvents(); } catch (Exception ex) { throw ex; } }
/// <summary> /// 重置机器时间 /// </summary> private void OrderSend_ResetTime(int iMachineID) { byte[] data = { 0xC0, 0xFF, 0xA9, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1 }; byte[] bMacID = BitConverter.GetBytes(iMachineID); data[1] = bMacID[0]; int year = DateTime.Now.Year - 2000; int month = DateTime.Now.Month; int day = DateTime.Now.Day; int hour = DateTime.Now.Hour; int minute = DateTime.Now.Minute; int second = DateTime.Now.Second; data[4] = BitConverter.GetBytes(year)[0]; data[5] = BitConverter.GetBytes(month)[0]; data[6] = BitConverter.GetBytes(day)[0]; data[7] = BitConverter.GetBytes(hour)[0]; data[8] = BitConverter.GetBytes(minute)[0]; data[9] = BitConverter.GetBytes(second)[0]; byte lowCRC; byte highCRC; ReaderGeneral.CRC16_CCITT(data, out highCRC, out lowCRC); data[11] = lowCRC; data[12] = highCRC; try { if (this._SendClient != null) { this._SendClient.Send(data); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 抹除读写器数据 /// </summary> /// <param name="machineID"></param> private void OrderSend_DeleteRecord(int machineID) { byte[] data = { 0xC0, 0x00, 0xE9, 0x00, 0x00, 0x00, 0x00, 0xC1 }; byte[] iMachineID = BitConverter.GetBytes(machineID); data[1] = iMachineID[0]; byte lowCRC; byte highCRC; ReaderGeneral.CRC16_CCITT(data, out highCRC, out lowCRC); data[5] = lowCRC; data[6] = highCRC; try { this.axMSComm05.Output = data; } catch (Exception ex) { throw ex; } }
/// <summary> /// 指令发送-批量获取11条记录 /// </summary> /// <param name="iMachineID">机号</param> public void OrderSend_GetBatchData(int iMachineID) { byte[] arrDataSend = { 0xC0, 0x00, 0x05, 0x00, 0x00, 0x00, 0xC1 }; byte[] bMacID = BitConverter.GetBytes(iMachineID); arrDataSend[1] = bMacID[0]; byte bLowCRC; byte bHighCRC; ReaderGeneral.CRC16_CCITT(arrDataSend, out bHighCRC, out bLowCRC); arrDataSend[4] = bLowCRC; arrDataSend[5] = bHighCRC; try { this.axMSComm05.Output = arrDataSend; Application.DoEvents(); } catch (Exception) { //throw ex; } }
/// <summary> /// 确认批量数据 /// </summary> private void OrderSend_ConfirmBatchData(int iMacID, string strRecordIndex) { byte[] arrDataSend = { 0xC0, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0xC1 }; byte[] byMacID = BitConverter.GetBytes(iMacID); arrDataSend[1] = byMacID[0]; int iRecordIndex = Convert.ToInt32(strRecordIndex, 16); byte[] byRecordIndex = BitConverter.GetBytes(iRecordIndex); arrDataSend[4] = byRecordIndex[1]; arrDataSend[5] = byRecordIndex[0]; byte lowCRC; byte highCRC; ReaderGeneral.CRC16_CCITT(arrDataSend, out highCRC, out lowCRC); arrDataSend[6] = lowCRC; arrDataSend[7] = highCRC; try { if (this._SendClient != null) { this._SendClient.Send(arrDataSend); //DataReceive(); } } catch (Exception ex) { ReaderExceptionEventArgs args = new ReaderExceptionEventArgs(); args.MachineID = iMacID; args.ExceptionObject = ex; args.RecordTime = DateTime.Now; OnReaderException(args); } }