Esempio n. 1
0
        /// <summary>
        /// 向串口发送指令
        /// </summary>
        /// <param name="id">COM口序号</param>
        /// <param name="mac">无线终端MAC</param>
        /// <param name="addr">卡地址</param>
        /// <param name="func">功能号</param>
        /// <param name="data">参数数组,高字节在前</param>
        /// <param name="TimeOut">等待超时的毫秒数</param>
        public static void SendCMD(int id, short mac, byte addr, byte func, int[] data, int TimeOut)
        {
            byte[] cmd = new byte[8 + data.Length * 4];

            FUNC.GetBytes(mac, out cmd[0], out cmd[1]);

            cmd[2] = Convert.ToByte('W');
            cmd[3] = Convert.ToByte('A');
            cmd[4] = Convert.ToByte('T');
            cmd[5] = addr;
            cmd[6] = func;

            for (int i = 0; i < data.Length; i++)
            {
                byte[] d = FUNC.GetBytes(data[i]);

                cmd[7 + i * 4]  = d[0];
                cmd[8 + i * 4]  = d[1];
                cmd[9 + i * 4]  = d[2];
                cmd[10 + i * 4] = d[3];
            }

            cmd[cmd.Length - 1] = FUNC.CRC8(cmd, 2, cmd.Length - 3);

            for (int i = 0; i < cmd.Length; i++)
            {
                Debug.Write(cmd[i].ToString("X2") + " ");
            }

            SendBytes(id, cmd, TimeOut);
        }
Esempio n. 2
0
        /// <summary>
        /// 读取卡的返回数据
        /// </summary>
        /// <param name="data">基于TCardRecv的子类,用于保存返回数据</param>
        /// <param name="TimeOut">超时的毫秒数</param>
        /// <returns>读取成功返回True,否则返回False</returns>
        public static bool ReadData(int id, TCardRecv data, int TimeOut)
        {
            byte[] buf  = new byte[15];
            string Head = "";
            int    size = 0;

            while (size < buf.Length)
            {
                //if (size > 0) FUNC.Sleep(10);

                int i = ReadBytes(id, buf, size, buf.Length - size, TimeOut);

                if (i == 0)
                {
                    return(false);          //读超时
                }
                size = size + i;

                Debug.WriteLine(string.Format("Card.ReadData:({0}) {1} ", size, FUNC.BytesToString(buf)));

                if (size >= 3)    //超过三字节,判断wat起始标记
                {
                    char[] ch = new char[] { Convert.ToChar(buf[0]), Convert.ToChar(buf[1]), Convert.ToChar(buf[2]) };
                    Head = new string(ch, 0, 3);

                    if (Head.ToLower() != "wat")   //起始字节不是wat,去掉一个字节,继续读取
                    {
                        for (int j = 0; j < size - 1; j++)
                        {
                            buf[j] = buf[j + 1];    //前移一个字节
                        }

                        size = size - 1;
                    }
                }
            }
            ;

            byte c = FUNC.CRC8(buf, 0, 14);

            if (c != buf[14])
            {
                return(false);
            }

            data.Head = Head;
            data.Addr = buf[3];

            for (int i = 0; i < 10; i++)
            {
                data[i] = buf[i + 4];
            }

            return(true);
        }
Esempio n. 3
0
        static void SendToScreen1()
        {
            for (int i = 0; i < list.Count; i++)
            {
                Led led = list[i];

                if ((led.IP == "") || (led.IP == "0.0.0.0") || (!led.IsConnected) || (led.state == 0))
                {
                    continue;
                }

                switch (led.state)
                {
                case 10:
                    Close1(i);
                    continue;

                case 11:
                    Open1(i);
                    break;
                }

                LedCommon.DLL_MakeRoot((int)LedCommon.eRootType.ROOT_PLAY, (int)LedCommon.eScreenType.SCREEN_COLOR);
                LedCommon.DLL_AddLeaf(1000);

                LedCommon.RECT r;
                r.left   = 0;
                r.top    = 0;
                r.right  = 256;
                r.bottom = 256;

                int dc = led.mdc.ToInt32();

                LedCommon.DLL_AddWindow(dc, 256, 256, ref r, 1, 8, 1);

                try
                {
                    LedCommon.DLL_LED_SendToScreen(led.dev, led.Addr, led.IP, (ushort)6666);
                }
                catch (Exception e)
                {
                    FUNC.Sleep(100);
                    Close1(i);

                    FUNC.Sleep(100);
                    Open1(i);

                    throw new Exception("SendToScreen(" + i.ToString() + ") Error:" + e.Message);
                }

                FUNC.Sleep(20);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 向串口发送指令
        /// </summary>
        /// <param name="id">COM口序号</param>
        /// <param name="addr">卡地址</param>
        /// <param name="func">功能号</param>
        /// <param name="data">参数,高字节在前</param>
        /// <param name="TimeOut">等待超时的毫秒数</param>
        public static void SendCMD(int id, byte addr, byte func, int data, int TimeOut)
        {
            byte[] cmd = new byte[10];
            byte[] d   = FUNC.GetBytes(data);

            cmd[0] = Convert.ToByte('W');
            cmd[1] = Convert.ToByte('A');
            cmd[2] = Convert.ToByte('T');
            cmd[3] = addr;
            cmd[4] = func;
            cmd[5] = d[0];
            cmd[6] = d[1];
            cmd[7] = d[2];
            cmd[8] = d[3];
            cmd[9] = FUNC.CRC8(cmd, 0, 9);

            SendBytes(id, cmd, TimeOut);
        }
Esempio n. 5
0
        static void SendToScreen3()
        {
            for (int i = 0; i < list.Count; i++)
            {
                Led led = list[i];

                if ((led.IP == "") || (led.IP == "0.0.0.0") || (!led.IsConnected) || (led.state == 0))
                {
                    continue;
                }

                switch (led.state)
                {
                case 10:
                    Close3(i);
                    continue;

                case 11:
                    Open3(i);
                    break;
                }


                try
                {
                    LedDll.LedSend((byte)(i + 1), led.bmp);
                }

                catch (Exception e)
                {
                    FUNC.Sleep(100);
                    Close3(i);

                    FUNC.Sleep(100);
                    Open3(i);

                    throw new Exception("SendToScreen(" + i.ToString() + ") Error:" + e.Message);
                }

                FUNC.Sleep(20);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 向串口发送指令
        /// </summary>
        /// <param name="id">COM口序号</param>
        /// <param name="addr">卡地址</param>
        /// <param name="func">功能号</param>
        /// <param name="data">参数数组,高字节在前</param>
        /// <param name="TimeOut">等待超时的毫秒数</param>
        public static void SendCMD(int id, byte addr, byte func, int[] data, int TimeOut)
        {
            byte[] cmd = new byte[6 + data.Length * 4];
            cmd[0] = Convert.ToByte('W');
            cmd[1] = Convert.ToByte('A');
            cmd[2] = Convert.ToByte('T');
            cmd[3] = addr;
            cmd[4] = func;

            for (int i = 0; i < data.Length; i++)
            {
                byte[] d = FUNC.GetBytes(data[i]);

                cmd[5 + i * 4] = d[0];
                cmd[6 + i * 4] = d[1];
                cmd[7 + i * 4] = d[2];
                cmd[8 + i * 4] = d[3];
            }

            cmd[cmd.Length - 1] = FUNC.CRC8(cmd, 0, cmd.Length - 1);

            SendBytes(id, cmd, TimeOut);
        }
Esempio n. 7
0
        /// <summary>
        /// 读取卡的返回数据
        /// </summary>
        /// <param name="id">串口ID</param>
        /// <param name="data">基于TCardRecv的子类,用于保存返回数据</param>
        /// <returns>读取成功返回True,否则返回False</returns>
        protected bool ReadData(int id, TCardRecv data)
        {
            byte[] buf = new byte[15];

            int i = ReadBytes(id, buf, 15);

            if (i != 15)
            {
                return(false);
            }

            byte c = FUNC.CRC8(buf, 0, 14);

            if (c != buf[14])
            {
                return(false);
            }

            char[] ch = new char[] { Convert.ToChar(buf[0]), Convert.ToChar(buf[1]), Convert.ToChar(buf[2]) };
            data.Head = new string(ch, 0, 3);


            if (data.Head.ToLower() != "wat")
            {
                return(false);
            }

            for (i = 0; i < 10; i++)
            {
                data[i] = buf[i + 4];
            }

            data.Addr = buf[3];

            return(true);
        }
Esempio n. 8
0
 /// <summary>
 /// ToString()方法重载
 /// </summary>
 /// <returns>以字符串方式返回数组内容</returns>
 public override String ToString()
 {
     return(FUNC.BytesToString(Data));
 }