Exemplo n.º 1
0
        public bool Open(string ip, int port)
        {
            try
            {
                var header = new PtpIpHeader();

                _client = new TcpClient();
                //_client.SendTimeout = 0;
                //_client.ReceiveTimeout = 0;
                _client.Connect(ip, port);
                _inerStream = _client.GetStream();

                Write(new InitCommandRequest());
                InitCommandAck res = (InitCommandAck)Read();

                _eventclient = new TcpClient();
                _eventclient.Connect(ip, port);

                _eventinerStream = _eventclient.GetStream();

                WriteEvent(new InitEventRequest(res.SessionId));
                header.Read(_eventinerStream);

                header.Length = 8;
                header.Type   = (uint)PtpIpContainerType.Ping;
                WriteEvent(header);

                header.Read(_eventinerStream);
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
 public CmdRequest(uint code, uint datatype = 1)
 {
     TransactionID = PtpIpProtocol.TransactionId++;
     Header = new PtpIpHeader();
     Header.Type = (uint) PtpIpContainerType.Cmd_Request;
     Code = code;
     DataType = datatype;
 }
Exemplo n.º 3
0
 public void WriteEvent(PtpIpHeader container)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         container.Write(ms);
         _eventinerStream.Write(ms.ToArray(), 0, (int)ms.Length);
     }
 }
Exemplo n.º 4
0
 public CmdRequest(uint code, uint datatype = 1)
 {
     TransactionID = PtpIpProtocol.TransactionId++;
     Header        = new PtpIpHeader();
     Header.Type   = (uint)PtpIpContainerType.Cmd_Request;
     Code          = code;
     DataType      = datatype;
 }
Exemplo n.º 5
0
 public void Write(PtpIpHeader header)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         header.Write(ms);
         _inerStream.Write(ms.ToArray(), 0, (int)ms.Length);
         _inerStream.Flush();
     }
 }
Exemplo n.º 6
0
 public IPtpIpCommand Read(StillImageDevice.TransferCallback callback=null)
 {
     var header = new PtpIpHeader();
     header.Read(_inerStream);
     switch ((PtpIpContainerType) header.Type)
     {
         case PtpIpContainerType.Init_Command_Request:
             break;
         case PtpIpContainerType.Init_Command_Ack:
             var initcommand = new InitCommandAck() {Header = header};
             initcommand.Read(_inerStream);
             return initcommand;
         case PtpIpContainerType.Init_Event_Request:
             break;
         case PtpIpContainerType.Init_Event_Ack:
             break;
         case PtpIpContainerType.Init_Fail:
             break;
         case PtpIpContainerType.Cmd_Request:
             break;
         case PtpIpContainerType.Cmd_Response:
             var cmdresp = new CmdResponse() {Header = header};
             cmdresp.Read(_inerStream);
             return cmdresp;
         case PtpIpContainerType.Event:
             break;
         case PtpIpContainerType.Start_Data_Packet:
             var stardatares = new StartDataPacket() {Header = header};
             stardatares.Read(_inerStream);
             return stardatares;
         case PtpIpContainerType.Data_Packet:
             var data = new DataPacket() {Header = header};
             data.Read(_inerStream);
             return data;
         case PtpIpContainerType.Cancel_Transaction:
             break;
         case PtpIpContainerType.End_Data_Packet:
             var enddata = new EndDataPacket() {Header = header};
             enddata.Read(_inerStream, callback);
             return enddata;
         case PtpIpContainerType.Ping:
             break;
         case PtpIpContainerType.Pong:
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     return null;
 }
Exemplo n.º 7
0
        public override void Write(Stream s)
        {
            Guid = Guid.NewGuid();
            Name = "DCC V1.00";

            Header        = new PtpIpHeader();
            Header.Type   = 1;
            Header.Length = (uint)(8 + 16 + ((Name.Length + 1) * 2) + 4);
            Header.Write(s);
            s.Write(Guid.ToByteArray(), 0, 16);
            s.Write(Encoding.Unicode.GetBytes(Name), 0, Name.Length * 2);
            s.WriteByte(0);
            s.WriteByte(0);
            //version 1.0
            s.WriteByte(0);
            s.WriteByte(0);
            s.WriteByte(1);
            s.WriteByte(0);
        }
        public override void Write(Stream s)
        {
            Guid = Guid.NewGuid();
            Name = "DCC V1.00";

            Header = new PtpIpHeader();
            Header.Type = 1;
            Header.Length = (uint) (8 + 16 + ((Name.Length + 1)*2)+4);
            Header.Write(s);
            s.Write(Guid.ToByteArray(), 0, 16);
            s.Write(Encoding.Unicode.GetBytes(Name), 0, Name.Length*2);
            s.WriteByte(0);
            s.WriteByte(0);
            //version 1.0
            s.WriteByte(0);
            s.WriteByte(0);
            s.WriteByte(1);
            s.WriteByte(0);
        }
Exemplo n.º 9
0
        public bool Open(string ip, int port)
        {
            try
            {
                var header = new PtpIpHeader();

                _client = new TcpClient();
                //_client.SendTimeout = 0;
                //_client.ReceiveTimeout = 0;
                _client.Connect(ip, port);
                _inerStream = _client.GetStream();

                Write(new InitCommandRequest());
                InitCommandAck res = (InitCommandAck)Read();

                _eventclient = new TcpClient();
                _eventclient.Connect(ip, port);

                _eventinerStream = _eventclient.GetStream();

                WriteEvent(new InitEventRequest(res.SessionId));
                header.Read(_eventinerStream);

                header.Length = 8;
                header.Type = (uint) PtpIpContainerType.Ping;
                WriteEvent(header);
               
                header.Read(_eventinerStream);

            }
            catch (Exception e)
            {
                Log.Error(e);
                return false;
            }
            return true;
        }
Exemplo n.º 10
0
 public BaseCmd()
 {
     Header = new PtpIpHeader();
 }
Exemplo n.º 11
0
 public void WriteEvent(PtpIpHeader container)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         container.Write(ms);
         _eventinerStream.Write(ms.ToArray(), 0, (int)ms.Length);
     }
 }
Exemplo n.º 12
0
 public void Write(PtpIpHeader header)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         header.Write(ms);
         _inerStream.Write(ms.ToArray(), 0, (int)ms.Length);
         _inerStream.Flush();
     }
 }
Exemplo n.º 13
0
 public BaseCmd()
 {
     Header = new PtpIpHeader();
 }
Exemplo n.º 14
0
        public IPtpIpCommand Read(StillImageDevice.TransferCallback callback = null)
        {
            var header = new PtpIpHeader();

            header.Read(_inerStream);
            switch ((PtpIpContainerType)header.Type)
            {
            case PtpIpContainerType.Init_Command_Request:
                break;

            case PtpIpContainerType.Init_Command_Ack:
                var initcommand = new InitCommandAck()
                {
                    Header = header
                };
                initcommand.Read(_inerStream);
                return(initcommand);

            case PtpIpContainerType.Init_Event_Request:
                break;

            case PtpIpContainerType.Init_Event_Ack:
                break;

            case PtpIpContainerType.Init_Fail:
                break;

            case PtpIpContainerType.Cmd_Request:
                break;

            case PtpIpContainerType.Cmd_Response:
                var cmdresp = new CmdResponse()
                {
                    Header = header
                };
                cmdresp.Read(_inerStream);
                return(cmdresp);

            case PtpIpContainerType.Event:
                break;

            case PtpIpContainerType.Start_Data_Packet:
                var stardatares = new StartDataPacket()
                {
                    Header = header
                };
                stardatares.Read(_inerStream);
                return(stardatares);

            case PtpIpContainerType.Data_Packet:
                var data = new DataPacket()
                {
                    Header = header
                };
                data.Read(_inerStream);
                return(data);

            case PtpIpContainerType.Cancel_Transaction:
                break;

            case PtpIpContainerType.End_Data_Packet:
                var enddata = new EndDataPacket()
                {
                    Header = header
                };
                enddata.Read(_inerStream, callback);
                return(enddata);

            case PtpIpContainerType.Ping:
                break;

            case PtpIpContainerType.Pong:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(null);
        }