public int takeMedicine(int guid, string address, int amount) { RequestMessage requestMessage = new RequestMessage(); requestMessage.Length = 0; requestMessage.Guid = ConvertCom.IntToChar4(guid); requestMessage.ShortAddr = ConvertCom.StringToChar4(address); // TKME requestMessage.Command = ConvertCom.StringToChar4("TKME"); requestMessage.Length = requestMessage.setValue(amount); Cache.Guid = 0; Cache.State = EleTagResponseState.NONE; serialCom.write(requestMessage.getMessageByte(), 0, 14 + requestMessage.Length); // 最长等待时间10s,循环判断时间间隔10ms int count = 1000; while (count > 0) { if (Cache.Guid == guid && (Cache.State == EleTagResponseState.TAKING || Cache.State == EleTagResponseState.TAKING_ERROR)) { count = 0; } Thread.Sleep(10); count--; } return(0); }
/// <summary> /// 查询确认 /// </summary> /// <param name="guid"></param> private void ExecuteQueryAck(int guid) { //1 获取通信地址 AddressMapping mapping = addressMappingDAL.findMappingByGuid(guid); if (mapping == null) { return; } RequestMessage requestMessage = new RequestMessage(); requestMessage.Length = 0; requestMessage.Guid = ConvertCom.IntToChar4(guid); requestMessage.ShortAddr = ConvertCom.StringToChar4(mapping.Addr); // LTME requestMessage.Command = ConvertCom.StringToChar4("LTME"); requestMessage.Length = requestMessage.setValue(12); serialCom.write(requestMessage.getMessageByte(), 0, 14 + requestMessage.Length); }
/// <summary> /// 补药确认 /// </summary> /// <param name="guid"></param> private void ExecuteAddAck(int guid) { //1 获取通信地址 AddressMapping mapping = addressMappingDAL.findMappingByGuid(guid); if (mapping == null) { return; } RequestMessage requestMessage = new RequestMessage(); requestMessage.Length = 2; requestMessage.Guid = ConvertCom.IntToChar4(guid); requestMessage.ShortAddr = ConvertCom.StringToChar4(mapping.Addr); // AKAD requestMessage.Command = ConvertCom.StringToChar4("AKAD"); requestMessage.Value[0] = 'O'; requestMessage.Value[1] = 'K'; serialCom.write(requestMessage.getMessageByte(), 0, 14 + requestMessage.Length); }
/// <summary> /// 补药 /// </summary> /// <param name="medicine"></param> /// <param name="amount"></param> /// <returns> /// 0 成功 /// 1 药盒的通信地址不存在 /// 2 /// </returns> public int addMedicine(Medicine medicine, int amount) { //1 获取通信地址 AddressMapping mapping = addressMappingDAL.findMappingByGuid(medicine.Address.Guid); if (mapping == null) { return(1); } RequestMessage requestMessage = new RequestMessage(); requestMessage.Length = 0; requestMessage.Guid = ConvertCom.IntToChar4((int)medicine.Id); requestMessage.ShortAddr = ConvertCom.StringToChar4(mapping.Addr); // "ADME" requestMessage.Command = ConvertCom.StringToChar4("ADME"); requestMessage.Length = requestMessage.setValue(amount); Cache.Guid = 0; Cache.State = EleTagResponseState.NONE; serialCom.write(requestMessage.getMessageByte(), 0, 14 + requestMessage.Length); // 等待成消息返回 // 最长等待时间10s,循环判断时间间隔10ms int count = 1000; while (count > 0) { if (Cache.Guid == (int)medicine.Id && (Cache.State == EleTagResponseState.ADDING || Cache.State == EleTagResponseState.ADDING_ERROR)) { count = 0; } Thread.Sleep(10); count--; } return(0); }