Ejemplo n.º 1
0
        private bool WaitForStatus(XSVFCommands waitFor, int waitTime = 1, int maxTries = 100, bool throwErr = true)
        {
            Main.SendDebug("Waiting for status {0}", waitFor);
            var          tries  = maxTries;
            XSVFCommands status = 0;

            while (status != waitFor && tries > 0)
            {
                Thread.Sleep(waitTime);
                byte[] ret;
                SendCMD(XSVFCommands.XSVFPoll, 0xC0, 2, out ret);
                status = (XSVFCommands)ret[0];
                tries--;
                Main.SendDebug("Status: {0} Cycle: {1}", status, Math.Abs(tries - maxTries));
                if (status != XSVFCommands.XSVFError || waitFor == XSVFCommands.XSVFError)
                {
                    continue;
                }
                if (!throwErr)
                {
                    Main.SendDebug("Error code: {0}", (XSVFException.XSVFErrors)ret[1]);
                    return(false);
                }
                throw new XSVFException(ret[1]);
            }
            if (tries <= 0)
            {
                throw new TimeoutException();
            }
            return(true);
        }
Ejemplo n.º 2
0
        private void SendCMD(XSVFCommands cmd, byte type, short buflen, out byte[] buf)
        {
            CheckDeviceState();
            Main.SendDebug("Sending CMD: {0}", cmd);
            var packet = new UsbSetupPacket(type, (byte)cmd, 0, 0, buflen);

            buf = new byte[buflen];
            var gch = GCHandle.Alloc(buf, GCHandleType.Pinned);
            int sent;

            Device.ControlTransfer(ref packet, gch.AddrOfPinnedObject(), buf.Length, out sent);
            gch.Free();
        }
Ejemplo n.º 3
0
        private void SendCMD(XSVFCommands cmd, byte type, IList <byte> buf)
        {
            CheckDeviceState();
            switch (buf.Count)
            {
            case 1:
                Main.SendDebug("Sending CMD: {0} {1}", cmd, (XSVFCommands)buf[0]);
                break;

            default:
                Main.SendDebug("Sending CMD: {0}", cmd);
                break;
            }
            var packet = new UsbSetupPacket(type, (byte)cmd, 0, 0, 0);
            int sent;

            Device.ControlTransfer(ref packet, buf, buf.Count, out sent);
        }
Ejemplo n.º 4
0
 private bool WaitForStatus(XSVFCommands waitFor, int waitTime = 1, int maxTries = 100, bool throwErr = true)
 {
     Main.SendDebug("Waiting for status {0}", waitFor);
     var tries = maxTries;
     XSVFCommands status = 0;
     while(status != waitFor && tries > 0) {
         Thread.Sleep(waitTime);
         byte[] ret;
         SendCMD(XSVFCommands.XSVFPoll, 0xC0, 2, out ret);
         status = (XSVFCommands) ret[0];
         tries--;
         Main.SendDebug("Status: {0} Cycle: {1}", status, Math.Abs(tries - maxTries));
         if(status != XSVFCommands.XSVFError || waitFor == XSVFCommands.XSVFError)
             continue;
         if(!throwErr) {
             Main.SendDebug("Error code: {0}", (XSVFException.XSVFErrors) ret[1]);
             return false;
         }
         throw new XSVFException(ret[1]);
     }
     if(tries <= 0)
         throw new TimeoutException();
     return true;
 }
Ejemplo n.º 5
0
 private void SendCMD(XSVFCommands cmd, byte type, short buflen, out byte[] buf)
 {
     CheckDeviceState();
     Main.SendDebug("Sending CMD: {0}", cmd);
     var packet = new UsbSetupPacket(type, (byte) cmd, 0, 0, buflen);
     buf = new byte[buflen];
     var gch = GCHandle.Alloc(buf, GCHandleType.Pinned);
     int sent;
     Device.ControlTransfer(ref packet, gch.AddrOfPinnedObject(), buf.Length, out sent);
     gch.Free();
 }
Ejemplo n.º 6
0
 private void SendCMD(XSVFCommands cmd, byte type, IList<byte> buf)
 {
     CheckDeviceState();
     switch(buf.Count) {
         case 1:
             Main.SendDebug("Sending CMD: {0} {1}", cmd, (XSVFCommands) buf[0]);
             break;
         default:
             Main.SendDebug("Sending CMD: {0}", cmd);
             break;
     }
     var packet = new UsbSetupPacket(type, (byte) cmd, 0, 0, 0);
     int sent;
     Device.ControlTransfer(ref packet, buf, buf.Count, out sent);
 }