예제 #1
0
        void OnDataReceived(string serialData)
        {
            if (rdata.Count > 50)
            {
                rdata.Clear();
            }
            byte[] sendBytes = Encoding.ASCII.GetBytes(serialData);
            // ILiveDebug.Instance.WriteLine("485Length:" + sendBytes.Length.ToString() + "data:" + ILiveUtil.ToHexString(sendBytes));
            ILiveDebug.Instance.WriteLine("TPCDebug:" + ILiveUtil.ToHexString(sendBytes));

            try
            {
                foreach (var item in sendBytes)
                {
                    rdata.Add(item);
                    if (item == 0x0D && rdata.Count > 5)
                    {
                        this.ProcessData();
                    }
                }
            }
            catch (Exception ex)
            {
                ILiveDebug.Instance.WriteLine(ex.Message);

                // throw;
            }
        }
예제 #2
0
        /// <summary>
        /// 设置第二路调光亮度
        /// </summary>
        /// <param name="p">亮度 0-255</param>
        public void SetDim2(int p)
        {
            byte[] sendBytes = this.BuildCMD((byte)addr, 0xA2, 0x02, 0x00, (byte)p);
            ILiveDebug.Instance.WriteLine("DIM2" + ILiveUtil.ToHexString(sendBytes));
            string cmd = Encoding.GetEncoding(28591).GetString(sendBytes, 0, sendBytes.Length);

            this.port.Send(cmd);
            this.Status.Dim2 = p;
            Thread.Sleep(500);
        }
예제 #3
0
        private void Relay8SW8(int address, int port1, int port2, bool states)
        {
            /*
             * 1 B2 协议头
             * 2 00 设备类型
             * 3 1-99 设备编号
             * 4 A1 功能
             * 5 00-FF
             *  00 选中 0 路
             *  FF 选中 8 路
             *  通道 5-12
             * 6
             *  00-FF
             *  00 选中 0 路
             *  FF 选中 8 路
             *  通道 1-4
             * 7 00 选中通道关 01 选中通道开 02 选中通道反 通道状态
             * 8 Check 校验和高位(2-7 位校验)
             * 9 Check 校验和低位 10 2B 协议尾
             */
            // byte[] checkarr1 = new byte[2];
            // this.ConvertIntToByteArray(address + port1 + port1 + 162, ref checkarr1);
            byte[] checkarr1 = BitConverter.GetBytes(address + port1 + port2 + 162);
            byte[] checkarr2 = BitConverter.GetBytes(address + port1 + port2 + 161);
            // this.ConvertIntToByteArray(address + port1 + port1 + 161, ref checkarr2);

            byte[] sendBytes = new byte[] { 0xB2, (byte)address, 0xA1, (byte)port1, (byte)port2, 0x00, checkarr2[0], 0x2B };
            if (states)
            {
                sendBytes = new byte[] { 0xB2, (byte)address, 0xA1, (byte)port1, (byte)port2, 0x01, checkarr1[0], 0x2B };
            }
            ILiveDebug.Instance.WriteLine("Relay:" + ILiveUtil.ToHexString(sendBytes));
            string cmd = Encoding.GetEncoding(28591).GetString(sendBytes, 0, sendBytes.Length);

            this.port.Send(cmd);
            Thread.Sleep(500);
        }
예제 #4
0
 void port_NetDataReceived(INetPortDevice device, NetPortSerialDataEventArgs args)
 {
     ILiveDebug.Instance.WriteLine("lightrec:" + ILiveUtil.ToHexString(Encoding.GetEncoding(28591).GetBytes(args.SerialData)));
 }