Пример #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);
        }
Пример #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;
 }
Пример #3
0
 public void WriteEvent(PtpIpHeader container)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         container.Write(ms);
         _eventinerStream.Write(ms.ToArray(), 0, (int)ms.Length);
     }
 }
Пример #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;
 }
Пример #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();
     }
 }
Пример #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;
 }
Пример #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);
        }
Пример #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;
        }
Пример #10
0
 public BaseCmd()
 {
     Header = new PtpIpHeader();
 }
Пример #11
0
 public void WriteEvent(PtpIpHeader container)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         container.Write(ms);
         _eventinerStream.Write(ms.ToArray(), 0, (int)ms.Length);
     }
 }
Пример #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();
     }
 }
Пример #13
0
 public BaseCmd()
 {
     Header = new PtpIpHeader();
 }
Пример #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);
        }