public bool ErrWmsSendData(byte ins, byte len, List <byte> seqWms, ref string idseq) { lock (senda) { List <byte> SendBuf = new List <byte>(); SendBuf.Add(0xCC); SendBuf.Add(0X00); SendBuf.Add(len); if (idseq.Trim().Length == 0) { if (id > 3000) { id = 10; } idseq = id.ToString(); id++; } byte[] by = WmsCommon.Instance().intToBytes(int.Parse(idseq)); for (int n = by.Length - 1; n >= 0; n--) { SendBuf.Add(by[n]); } SendBuf.Add(ins); for (int i = 0; i < seqWms.Count; i++) { SendBuf.Add(seqWms[i]); } byte xor = SendBuf[0]; for (int i = 1; i < SendBuf.Count; i++) { xor ^= SendBuf[i]; } SendBuf.Add(xor); SendBuf.Add(0x55); if (ins == 0x84) { Log.WriteLog("发送落袋信息给WMS:" + string.Join(",", SendBuf.ToArray())); } return(SendWmsData(SendBuf.ToArray())); } }
public bool SendWmsData(byte[] data) { lock (data) { try { for (int i = 0; i < WmsCommon.Instance().clients.Count;) { if (i < WmsCommon.Instance().clients.Count) { SocketStatus wmssocket = WmsCommon.Instance().clients[i]; if (wmssocket != null) { if (wmssocket.scocKet.Connected) { wmssocket.scocKet.Send(data); // Log.WriteLog(DateTime.Now + "WCS --> WMS:" + data); i++; } else { wmssocket.scocKet.Close(); WmsCommon.Instance().clients.Remove(wmssocket); } } } } return(true); } catch (Exception ex) { Log.WriteLog("发送消息异常" + ex.Message.ToString()); return(false); } // return false; } }