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 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.º 3
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);
        }