Esempio n. 1
0
        //private string ipAddress = "139.199.160.173";
        public void OpenRemoteBox(string serialNumber, string orderNo, string warehouseIndexs, byte type = 0x01)
        {
            try
            {
                if (string.IsNullOrEmpty(serialNumber))
                {
                    throw new Exception("序列号无效");
                }
                if (string.IsNullOrEmpty(warehouseIndexs))
                {
                    throw new Exception("货箱序号无效");
                }
                if (string.IsNullOrEmpty(orderNo))
                {
                    orderNo = "999999999999999";
                }
                var    list      = warehouseIndexs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(o => int.Parse(o)).ToList();
                byte[] byte_open = new byte[12] {
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };
                for (int i = 0; i < list.Count; i++)
                {
                    byte_open[list[i]] = 0x01;
                }

                byte[] order_no       = Encoding.UTF8.GetBytes(orderNo);
                byte[] ping           = Encoding.UTF8.GetBytes(serialNumber);
                byte[] commandByteArr = TcpClientHelper.GetSendMulty(ping, byte_open, order_no, type);
                var    commandStr     = Converts.GetTPandMac(commandByteArr);
                LogHelper.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ";发送的开箱命令:" + commandStr);
                //SocketException exception;
                //定义一个套接字监听
                socketclient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                //获取文本框中的IP地址
                IPAddress address = IPAddress.Parse(ipAddress);
                //将获取的IP地址和端口号绑定在网络节点上
                IPEndPoint point = new IPEndPoint(address, port);
                socketclient.Connect(point);
                socketclient.Send(commandByteArr);
                var resultStr = string.Empty;
                socketclient.Close();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 2
0
        public Dictionary <string, string> OpenRemoteBox(string serialNumber, string orderNo, string warehouseIndexs, byte type = 0x01)
        {
            if (string.IsNullOrEmpty(serialNumber))
            {
                throw new Exception("序列号无效");
            }
            if (string.IsNullOrEmpty(warehouseIndexs))
            {
                throw new Exception("货箱序号无效");
            }
            var list = warehouseIndexs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(o => int.Parse(o)).ToList();

            byte[] byte_open = new byte[12] {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };
            for (int i = 0; i < list.Count; i++)
            {
                byte_open[list[i]] = 0x01;
            }
            var dic = new Dictionary <string, string>();

            byte[] order_no = Encoding.UTF8.GetBytes(orderNo);
            byte[] ping     = Encoding.UTF8.GetBytes(serialNumber);
            //byte[] commandByteArr = TcpClientHelper.GetSendMulty(ping, byte_open, 0x02);
            byte[] commandByteArr = TcpClientHelper.GetSendMulty(ping, byte_open, order_no, type);
            var    commandStr     = Converts.GetTPandMac(commandByteArr);

            //SocketException exception;
            //定义一个套接字监听
            socketclient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //获取文本框中的IP地址
            IPAddress address = IPAddress.Parse(ipAddress);
            //将获取的IP地址和端口号绑定在网络节点上
            IPEndPoint point = new IPEndPoint(address, port);

            socketclient.Connect(point);
            socketclient.Send(commandByteArr);
            var resultStr = string.Empty;

            socketclient.Close();
            dic["success"] = "成功";
            return(dic);
        }
Esempio n. 3
0
 //EF0332110B150E1C3401383631383533303332303036363033030303000300000000000000130000000000000500060B03FA
 public static byte[] ToCommand(BoxModel model)
 {
     LogHelper.WriteLog(DateTime.Now.ToString("HH:mm:ss") + "需要拼接的命令:" + JsonConvert.SerializeObject(model));
     byte[] macByte = Encoding.UTF8.GetBytes(model.FormatMac);
     return(TcpClientHelper.GetSendMulty(macByte, model.State));
 }