Пример #1
0
        private int[] CheckPaperStatus()
        {
            try
            {
                string sVid = txtVID.Text;
                int    iVid = Int32.Parse(sVid, NumberStyles.HexNumber);
                string sPid = txtPID.Text;
                int    iPid = Int32.Parse(sPid, NumberStyles.HexNumber);

                byte[] byteArray = new byte[3];
                byteArray[0] = 0x10;
                byteArray[1] = 0x04;
                byteArray[2] = 4;

                byte[] read = USB.WriteAndRead(iVid, iPid, byteArray);

                if (read == null || read.Length == 0)
                {
                    return new int[] { 500, 500 }
                }
                ;

                int[] ret = new int[2] {
                    0, 0
                };
                var bit2 = (read[0] & (1 << 2)) != 0; // Near End
                var bit3 = (read[0] & (1 << 3)) != 0; // Near End
                var bit5 = (read[0] & (1 << 5)) != 0; // Out of Paper
                var bit6 = (read[0] & (1 << 6)) != 0; // Out of Paper

                if (bit2 || bit3)
                {
                    ret[0] = 1;
                }
                if (bit5 || bit6)
                {
                    ret[1] = 1;
                }

                return(ret);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        private string CheckA4PrinterStatus()
        {
            try
            {
                string sVid = txtVID.Text;
                int    iVid = Int32.Parse(sVid, NumberStyles.HexNumber);
                string sPid = txtPID.Text;
                int    iPid = Int32.Parse(sPid, NumberStyles.HexNumber);

                byte[] byteArray = new byte[3];
                byteArray[0] = 0x10;
                byteArray[1] = 0x04;
                byteArray[2] = 4;

                byte[] read = USB.WriteAndRead2(iVid, iPid, byteArray);

                return(GetString(read));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }