private byte[] BuildFrame(LaserProtocolMessageType type, LaserProtocolMessageAck ack) { try { byte[] _frame = new byte[FrameLength]; _frame[HeadIndex] = Head; lock(_sync) { _frame[MagicIndex] = ++Magic; } _frame[TypeIndex] = Convert.ToByte(type); Array.Copy(Content, 0, _frame, ContentIndex, ContentLength); Array.Copy(Reserve, 0, _frame, ReserveIndex, ReserveLenth); _frame[AckIndex] = Convert.ToByte(ack); _frame[TailIndex] = Tail; return _frame; } catch (Exception e) { throw new APXExeception(e.Message); } }
public bool SendMessage(LaserProtocolMessageType type, LaserProtocolMessageAck ack, byte[] content, ref byte[] frame) { Content = content; bool isOK = false; try { frame = BuildFrame(type, ack); if (_comm != null) { isOK = _comm.Send(frame, 0, frame.Length); if(isOK) { if(ack == LaserProtocolMessageAck.Initial) { LaserProtocolMessageAck ackTmp = CheckResult(frame, 200); if (ackTmp != LaserProtocolMessageAck.ReceiveConfirm) { return false; } else { return true; } } else { return true; } } else { return false; } } else { return false; } } catch(Exception e) { throw new APXExeception(e.Message); } }