private bool SendReqOfflineData(int sectionId, int ownerId, int noteId)
        {
            byte[] ownerByte = ByteConverter.IntToByte(ownerId);

            short length = (short)(5 + 40);

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_OfflineDataRequest)
            .PutShort(length)
            .Put(ownerByte[0])
            .Put(ownerByte[1])
            .Put(ownerByte[2])
            .Put((byte)sectionId)
            .Put((byte)1)
            .PutInt(noteId)
            .PutNull(36)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Change the password of device.
        /// </summary>
        /// <param name="oldPassword">Current password</param>
        /// <param name="newPassword">New password</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetUpPassword(string oldPassword, string newPassword)
        {
            if (oldPassword == null || newPassword == null)
            {
                return(false);
            }

            byte[] oPassByte = Encoding.UTF8.GetBytes(oldPassword);
            byte[] nPassByte = Encoding.UTF8.GetBytes(newPassword);

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PasswordSet)
            .PutShort(32)
            .Put(oPassByte, 16)
            .Put(nPassByte, 16)
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
        /// <summary>
        /// Input password if device is locked.
        /// </summary>
        /// <param name="password">Specifies the password for authentication. Password is a string</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqInputPassword(string password)
        {
            if (password == null)
            {
                return(false);
            }

            if (password.Equals(DEFAULT_PASSWORD))
            {
                return(false);
            }

            byte[] bStrByte = Encoding.UTF8.GetBytes(password);

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PasswordResponse)
            .PutShort(16)
            .Put(bStrByte, 16)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
        private bool SendAddUsingNote(int sectionId, int ownerId, ArrayList noteIds)
        {
            byte[] ownerByte = ByteConverter.IntToByte(ownerId);

            short length = (short)(6 + (noteIds.Count * 4));

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_UsingNoteNotify)
            .PutShort(length)
            .Put((byte)1)
            .Put((byte)noteIds.Count)
            .Put(ownerByte[0])
            .Put(ownerByte[1])
            .Put(ownerByte[2])
            .Put((byte)sectionId);

            foreach (int item in noteIds)
            {
                bf.PutInt(item);
            }

            bf.Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
        private bool SendAddUsingNote(int sectionId, int ownerId)
        {
            byte[] ownerByte = ByteConverter.IntToByte(ownerId);

            short length = 42;

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_UsingNoteNotify)
            .PutShort(length)
            .Put((byte)2)
            .Put((byte)1)
            .Put(ownerByte[0])
            .Put(ownerByte[1])
            .Put(ownerByte[2])
            .Put((byte)sectionId)
            .PutNull(36)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
        /// <summary>
        /// Request to remove offline data in device.
        /// </summary>
        /// <param name="section">The Section Id of the paper</param>
        /// <param name="owner">The Owner Id of the paper</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqRemoveOfflineData(int section, int owner)
        {
            byte[] ownerByte = ByteConverter.IntToByte(owner);

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_OfflineDataRemove)
            .PutShort(12)
            .Put(ownerByte[0])
            .Put(ownerByte[1])
            .Put(ownerByte[2])
            .Put((byte)section)
            .Put((byte)0x00)
            .Put((byte)0x00)
            .Put((byte)0x00)
            .Put((byte)0x00)
            .Put((byte)0x00)
            .Put((byte)0x00)
            .Put((byte)0x00)
            .Put((byte)0x00)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
        private void ParseOneByte(byte data)
        {
            int int_data = (int)(data & 0xFF);

            //int int_data = data;

            if (int_data == PKT_START && isStart)
            {
                //System.Console.WriteLine( "ProtocolParser : PKT_START" );
                counter = 0;
                isStart = false;
            }
            else if (int_data == PKT_END && counter == dataLength + PKT_HEADER_LEN)
            {
                Packet.Builder builder = new Packet.Builder();

                // 커맨드를 뽑는다.
                int cmd = nbuffer.GetByteToInt();

                // 길이를 뽑는다.
                int length = nbuffer.GetShort();

                // 커맨드, 길이를 제외한 나머지 바이트를 컨텐트로 지정
                byte[] content = nbuffer.GetBytes();

                PacketCreated(this, new PacketEventArgs(builder.cmd(cmd).data(content).Build()));

                dataLength = 0;
                counter    = 10;
                nbuffer.Clear();
                isStart = true;
            }
            else if (counter > PKT_MAX_LEN)
            {
                //System.Console.WriteLine( "ProtocolParser : PKT_MAX_LEN" );
                counter    = 10;
                dataLength = 0;
                isStart    = true;
            }
            else
            {
                if (counter == PKT_LENGTH_POS1)
                {
                    lbuffer[0] = data;
                }
                else if (counter == PKT_LENGTH_POS2)
                {
                    //System.Console.WriteLine( "ProtocolParser : PKT_LENGTH_POS2" );
                    lbuffer[1] = data;
                    dataLength = ByteConverter.ByteToShort(lbuffer);
                }

                if (!isStart)
                {
                    nbuffer.Put(data);
                    counter++;
                }
            }
        }
Пример #8
0
        private bool Send(ByteUtil bf)
        {
            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
        /// <summary>
        /// Request the status of pen.
        /// If you requested, you can receive result by PenCommV1Callbacks.onReceivedPenStatus method.
        /// </summary>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqPenStatus()
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PenStatusRequest)
            .PutShort(0)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
Пример #10
0
        /// <summary>
        /// Request the status of pen.
        /// If you requested, you can receive result by PenCommV1Callbacks.onReceivedPenStatus method.
        /// </summary>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqPenStatus()
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PenStatusRequest)
            .PutShort(0)
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
Пример #11
0
        /// <summary>
        /// Sets the value of the pen's sensitivity property that controls the force sensor of pen.
        /// </summary>
        /// <param name="level">the value of sensitivity. (0~4, 0 means maximum sensitivity)</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetupPenSensitivity(short level)
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PenSensitivity)
            .PutShort(2)
            .PutShort(level)
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
        /// <summary>
        /// Sets the value of the pen's sensitivity property that controls the force sensor of pen.
        /// </summary>
        /// <param name="level">the value of sensitivity. (0~4, 0 means maximum sensitivity)</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetupPenSensitivity(short level)
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PenSensitivity)
            .PutShort(2)
            .PutShort(level)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
        /// <summary>
        /// Requests the list of Offline data.
        /// </summary>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqOfflineDataList()
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_OfflineNoteList)
            .PutShort(1)
            .Put((byte)0x00)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
        /// <summary>
        /// Sets the value of the auto shutdown time property that if pen stay idle, shut off the pen.
        /// </summary>
        /// <param name="minute">minute of maximum idle time, staying power on (0~)</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetupPenAutoShutdownTime(short minute)
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_AutoShutdownTime)
            .PutShort(2)
            .PutShort(minute)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
Пример #15
0
        /// <summary>
        /// Sets the value of the auto shutdown time property that if pen stay idle, shut off the pen.
        /// </summary>
        /// <param name="minute">minute of maximum idle time, staying power on (0~)</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetupPenAutoShutdownTime(short minute)
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_AutoShutdownTime)
            .PutShort(2)
            .PutShort(minute)
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
Пример #16
0
        /// <summary>
        /// Requests the list of Offline data.
        /// </summary>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqOfflineDataList()
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_OfflineNoteList)
            .PutShort(1)
            .Put((byte)0x00)
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
        /// <summary>
        /// Sets the hover mode.
        /// </summary>
        /// <param name="enable">true if you want to enable hover mode, otherwise false.</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        private bool ReqSetupHoverMode(bool enable)
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_HoverOnOff)
            .PutShort(1)
            .Put((byte)(enable ? 1 : 0))
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
        /// <summary>
        /// Sets the status of the auto power on property that if write the pen, turn on when pen is down.
        /// </summary>
        /// <param name="seton">true if you want to use, otherwise false.</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetupPenAutoPowerOn(bool enable)
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_AutoPowerOnSet)
            .PutShort(1)
            .Put((byte)(enable ? 1 : 0))
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
Пример #19
0
        /// <summary>
        /// Sets the status of the beep property.
        /// </summary>
        /// <param name="enable">true if you want to listen sound of pen, otherwise false.</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetupPenBeep(bool enable)
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_BeepSet)
            .PutShort(1)
            .Put((byte)(enable ? 1 : 0))
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
Пример #20
0
        /// <summary>
        /// Sets the available notebook type
        /// </summary>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqAddUsingNote()
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_UsingNoteNotify)
            .PutShort(2)
            .Put((byte)3)
            .Put((byte)0)
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
        /// <summary>
        /// Sets the available notebook type
        /// </summary>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqAddUsingNote()
        {
            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_UsingNoteNotify)
            .PutShort(2)
            .Put((byte)3)
            .Put((byte)0)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
        /// <summary>
        /// Change the password of device.
        /// </summary>
        /// <param name="oldPassword">Current password</param>
        /// <param name="newPassword">New password</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetUpPassword(string oldPassword, string newPassword)
        {
            if (oldPassword == null || newPassword == null)
            {
                return(false);
            }

            if (oldPassword.Equals(DEFAULT_PASSWORD))
            {
                return(false);
            }
            if (newPassword.Equals(DEFAULT_PASSWORD))
            {
                return(false);
            }

            if (oldPassword.Equals(string.Empty))
            {
                oldPassword = DEFAULT_PASSWORD;
            }
            if (newPassword.Equals(string.Empty))
            {
                newPassword = DEFAULT_PASSWORD;
            }

            byte[] oPassByte = Encoding.UTF8.GetBytes(oldPassword);
            byte[] nPassByte = Encoding.UTF8.GetBytes(newPassword);

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PasswordSet)
            .PutShort(32)
            .Put(oPassByte, 16)
            .Put(nPassByte, 16)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
        /// <summary>
        /// Sets the color of pen ink.
        /// If you want to change led color of pen, you should choose one among next preset values.
        ///
        /// violet = 0x9C3FCD
        /// blue = 0x3c6bf0
        /// gray = 0xbdbdbd
        /// yellow = 0xfbcb26
        /// pink = 0xff2084
        /// mint = 0x27e0c8
        /// red = 0xf93610
        /// black = 0x000000
        /// </summary>
        /// <param name="rgbcolor">integer type color formatted 0xRRGGBB</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqSetupPenColor(int rgbcolor)
        {
            byte[] cbyte = ByteConverter.IntToByte(rgbcolor);

            byte[] nbyte = new byte[] { cbyte[0], cbyte[1], cbyte[2], (byte)0x01 };

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PenColorSet)
            .PutShort(4)
            .Put(nbyte, 4)
            .Put((byte)0xC1);

            bool result = Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(result);
        }
Пример #24
0
        /// <summary>
        /// Input password if device is locked.
        /// </summary>
        /// <param name="password">Specifies the password for authentication. Password is a string</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqInputPassword(string password)
        {
            if (password == null)
            {
                return(false);
            }

            byte[] bStrByte = Encoding.UTF8.GetBytes(password);

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_PasswordResponse)
            .PutShort(16)
            .Put(bStrByte, 16)
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
Пример #25
0
        /// <summary>
        /// Sets the available notebook type
        /// </summary>
        /// <param name="section">The Section Id of the paper</param>
        /// <param name="owner">The Owner Id of the paper</param>
        /// <returns>true if the request is accepted; otherwise, false.</returns>
        public bool ReqAddUsingNote(int section, int owner)
        {
            byte[] ownerByte = ByteConverter.IntToByte(owner);

            ByteUtil bf = new ByteUtil();

            bf.Put((byte)0xC0)
            .Put((byte)Cmd.P_UsingNoteNotify)
            .PutShort(6)
            .Put((byte)2)
            .Put((byte)1)
            .Put(ownerByte[0])
            .Put(ownerByte[1])
            .Put(ownerByte[2])
            .Put((byte)section)
            .Put((byte)0xC1);

            PenController.PenClient.Write(bf.ToArray());

            bf.Clear();
            bf = null;

            return(true);
        }
Пример #26
0
        public void Put(byte[] buff, int size)
        {
            byte[] test = new byte[size];

            //Array.Copy( buff, 0, test, 0, size );
            //System.Console.WriteLine( "Read Buffer : {0}", BitConverter.ToString( test ) );
            //System.Console.WriteLine();

            for (int i = 0; i < size; i++)
            {
                if (buff[i] == Const.PK_STX)
                {
                    // packet start
                    mBuffer = new ByteUtil();

                    IsEscape = false;
                }
                else if (buff[i] == Const.PK_ETX)
                {
                    // end of packet
                    Packet.Builder builder = new Packet.Builder();

                    int cmd = mBuffer.GetByteToInt();

                    string cmdstr = Enum.GetName(typeof(Cmd), cmd);

                    int result_size = cmdstr != null && cmdstr.EndsWith("RESPONSE") ? 1 : 0;

                    int result = result_size > 0 ? mBuffer.GetByteToInt() : -1;

                    int length = mBuffer.GetUShort();

                    byte[] data = mBuffer.GetBytes();

                    //System.Console.WriteLine( "length : {0}, data : {1}", length, data.Length );

                    builder.cmd(cmd)
                    .result(result)
                    .data(data);

                    //System.Console.WriteLine( "Read Packet : {0}", BitConverter.ToString( data ) );
                    //System.Console.WriteLine();

                    mBuffer.Clear();
                    mBuffer = null;

                    PacketCreated(this, new PacketEventArgs(builder.Build()));

                    IsEscape = false;
                }
                else if (buff[i] == Const.PK_DLE)
                {
                    if (i < size - 1)
                    {
                        mBuffer.Put((byte)(buff[++i] ^ 0x20));
                    }
                    else
                    {
                        IsEscape = true;
                    }
                }
                else if (IsEscape)
                {
                    mBuffer.Put((byte)(buff[i] ^ 0x20));

                    IsEscape = false;
                }
                else
                {
                    mBuffer.Put(buff[i]);
                }
            }
        }