Exemplo n.º 1
0
        private void Bep82USBRecv()
        {
            if (null == bepIn82)
            {
                return;
            }

            int len = 1024 * 48;

            byte[] recv = new byte[len];
            bepIn82.TimeOut  = 300;
            bepIn82.XferSize = 1024 * 48;
            try
            {
                while (isConnect)
                {
                    len  = 1024 * 48;
                    recv = new byte[len];
                    if (bepIn82.XferData(ref recv, ref len))
                    {
                        //这里的len是实际读到的数据长度,recv只是一个buffer,所以Buffer中的数据不一定全部是收到的数据。
                        recvDatas.Add(recv.Take(len).ToArray <byte>());
                    }
                }
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorLog(ex, "Beq83USBRecv");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 收包这里不做分包合并,每一包都触发委托处理
        /// 在委托里面根据需要进行合包,分包信息在Header里面有,所以委托参数从Msg改为Packet,
        /// </summary>
        /// <param name="data">skt收到的报文字节</param>
        /// <param name="pkt">返回的自定义Packet类型对象</param>
        /// <returns>是否接收正确 0表示正常, 非0表示异常</returns>
        private int RecvOnePkt(byte[] data, out Packet pkt)
        {
            //Console.WriteLine("RecvOnePkt:");
            //Console.WriteLine("PktSN = " + pkt.Header.PktSN.ToString());
            //Console.WriteLine("MsgSn = " + pkt.Header.MsgSn.ToString());
            //Console.WriteLine("MsgType = 0x" + pkt.Header.MsgType.ToString("x"));
            //Console.WriteLine("MsgLen = " + pkt.Header.MsgLen.ToString());
            //Console.WriteLine("TotalMsgLen = " + pkt.Header.TotalMsgLen.ToString());

            pkt = new Packet(data);

            if (pkt.Data.Length < pkt.Header.MsgLen + Header.Length)
            {
                NLogHelper.DebugLog("pkt.Length<pkt.MsgLen + pkt.headerLen");
                return(-1);
            }

            if (pkt.Msg.Length < pkt.Header.TotalMsgLen)
            {
                NLogHelper.DebugLog("msg.data.Length < pkt.TotalMsgLen");
                return(-2);
            }

            return(0);   // rcv done
        }
Exemplo n.º 3
0
        /// <summary>
        /// 写一行数据
        /// </summary>
        /// <param name="data">要写入的数据数据 每一列是一个元素</param>
        public void WirteLine(string[] data)
        {
            try
            {
                using (StreamWriter sw = new StreamWriter(path, true))
                {
                    string s = string.Empty;
                    foreach (var d in data)
                    {
                        s = s + d + ",";
                    }
                    sw.WriteLine(s);

                    double size = sw.BaseStream.Position / 1024.0 / 1024.0;//单位MB
                    if (size > MaxzSize)
                    {
                        this.path = path.Replace($"({page})", $"({++page})");
                    }
                }
            }
            catch (IOException ex)
            {
                NLogHelper.ErrorLog(ex, "WriteLine");
            }
        }
Exemplo n.º 4
0
        private void UsbDevices_DeviceRemoved(object sender, EventArgs e)
        {
            isConnect = false;
            USBEventArgs usbEvent = e as USBEventArgs;

            //Console.WriteLine(usbEvent.FriendlyName.ToString() + " Removed");
            NLogHelper.DebugLog(usbEvent.FriendlyName.ToString() + " Removed");
            MessageBox.Show(usbEvent.FriendlyName.ToString() + " Removed");
        }
Exemplo n.º 5
0
        private int USBSend(byte[] data)
        {
            if (null == bepOut)
            {
                return(0);
            }

            int len = data.Length;

            if (bepOut.XferData(ref data, ref len))
            {
                Console.WriteLine($"Send One Msg MsgType:0x{BitConverter.ToInt32(data, 36):X2}");
                NLogHelper.DebugLog($"Send One Msg MsgType:0x{BitConverter.ToInt32(data, 36):X2}");
            }

            return(len);
        }