0

C# 言語を使用した .net コンパクト フレームワークを使用して、Windows CE で FTP プログラムを開発しようとしました。しかし、この2日間、私は答えを得ていません

私は次のことをしました

  1. RAS Dial 2 を使用して GPRSwininet.dllに接続します。FTP に接続するための機能をインポートしました。

しかし、InternetConnect 関数は常にエラーコードをスローします12031

わかりました、もう少し情報を共有しますか、これを調べてください

実は他社のMDT装置を使用しています。彼らは、OpenGPRS のいくつかの初期タスクを実行する dll を提供しており、彼らのマニュアルに従って、約 30 秒の遅延を設定する必要があります。

その後、いくつかの AT コマンドを発行する必要があり、最終的に RAS ダイヤル API を使用して接続できます。

その部分は次のとおりです

  public static bool TestRAS()
        {
            int hModem;
            COMMTIMEOUTS tm = new COMMTIMEOUTS();
            DCB dcb = new DCB();

           Console.WriteLine("Begin test RAS");
            IO_OpenGprsPower(false);
            System.Threading.Thread.Sleep(1000);
            IO_OpenGprsPower(true);

            //open serial port
            Console.WriteLine("Open gprs port(COM7:) ");
            hModem = CreateFile("COM7:", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
            if (hModem == -1)
            {
                Console.WriteLine("Error, End test RAS ");
                return false;
            }
            //set time out
            tm.ReadIntervalTimeout = 10;
            tm.ReadTotalTimeoutConstant = 10;
            tm.ReadTotalTimeoutMultiplier = 0;
            tm.WriteTotalTimeoutConstant = 5000;
            tm.WriteTotalTimeoutMultiplier = 0;
            if (!SetCommTimeouts(hModem, ref tm))
            {
                CloseHandle(hModem);
                Console.WriteLine("Error..End test RAS");
                return false;
            }
            //set state
            if (!GetCommState(hModem, ref dcb))
            {
                CloseHandle(hModem);
                Console.WriteLine("Error..End test RAS");
                return false;
            }
            dcb.BaudRate = 115200;
            dcb.StopBits = 0;
            dcb.Parity = 0;
            dcb.ByteSize = 8;
            if (!SetCommState(hModem, ref dcb))
            {
                CloseHandle(hModem);
                Console.WriteLine("Error..End test RAS");
                return false;
            }
            Console.WriteLine("OK..");

            //wait gprs module to register to network
            Console.WriteLine("Wait gprs module start ");
            for (int i = 30; i >= 0; i--)
            {
                 Console.WriteLine("Wait.." + i.ToString());
                System.Threading.Thread.Sleep(1000);
            }

            int iRet = 0;
            byte[] objBytes = new byte[1024];
            string strData;
            byte[] objAtCmd;

            //config context
            Console.WriteLine("Config gprs context");
            objAtCmd = System.Text.Encoding.ASCII.GetBytes("AT\r\n");
            WriteFile(hModem, objAtCmd, objAtCmd.Length, ref iRet, 0);
            System.Threading.Thread.Sleep(1000);
            ReadFile(hModem, objBytes, 1024, ref iRet, 0);
            objAtCmd = System.Text.Encoding.ASCII.GetBytes("AT\r\n");
            WriteFile(hModem, objAtCmd, objAtCmd.Length, ref iRet, 0);
            System.Threading.Thread.Sleep(1000);
            ReadFile(hModem, objBytes, 1024, ref iRet, 0);
            strData = System.Text.Encoding.ASCII.GetString(objBytes, 0, iRet);
            if (strData.IndexOf("OK") < 0)
            {
                CloseHandle(hModem);
                Console.WriteLine("AT error.. End test RAS");
                return false;
            }

            objAtCmd = System.Text.Encoding.ASCII.GetBytes("AT+CFUN=1\r\n");
            WriteFile(hModem, objAtCmd, objAtCmd.Length, ref iRet, 0);
            System.Threading.Thread.Sleep(1000);
            ReadFile(hModem, objBytes, 1024, ref iRet, 0);
            strData = System.Text.Encoding.ASCII.GetString(objBytes, 0, iRet);
            if (strData.IndexOf("OK") < 0)
            {
                CloseHandle(hModem);
                Console.WriteLine("AT+CFUN=1 error.. End test RAS");
                return false;
            }

            objAtCmd = System.Text.Encoding.ASCII.GetBytes("AT+COPS?\r\n");
            WriteFile(hModem, objAtCmd, objAtCmd.Length, ref iRet, 0);
            System.Threading.Thread.Sleep(1000);
            ReadFile(hModem, objBytes, 1024, ref iRet, 0);
            strData = System.Text.Encoding.ASCII.GetString(objBytes, 0, iRet);
            if (strData.IndexOf("OK") < 0)
            {
                CloseHandle(hModem);
                Console.WriteLine("AT+COPS? error.. End test RAS");
                return false;
            }

            //you can replace  isp.cingular with your local APN
           // objAtCmd = System.Text.Encoding.ASCII.GetBytes("AT+CGDCONT=1,\"IP\",\"bsnlnet\"\r\n");
            objAtCmd = System.Text.Encoding.ASCII.GetBytes("AT+CGDCONT=1,\"IP\",\"internet\"\r\n");
            Console.WriteLine("AT+CGDCONT=1,\"IP\",\"internet\"\r\n");
            WriteFile(hModem, objAtCmd, objAtCmd.Length, ref iRet, 0);
            System.Threading.Thread.Sleep(1000);
            ReadFile(hModem, objBytes, 1024, ref iRet, 0);
            strData = System.Text.Encoding.ASCII.GetString(objBytes, 0, iRet);
            Console.WriteLine(strData);
            if (strData.IndexOf("OK") < 0)
            {
                CloseHandle(hModem);
                Console.WriteLine("AT+CGDCONT=1 error..End test RAS");
                return false;
            }

            objAtCmd = System.Text.Encoding.ASCII.GetBytes("AT+CGATT=1\r\n");
            Console.WriteLine("AT+CGATT=1");
            WriteFile(hModem, objAtCmd, objAtCmd.Length, ref iRet, 0);
            System.Threading.Thread.Sleep(30000);
            ReadFile(hModem, objBytes, 1024, ref iRet, 0);
            strData = System.Text.Encoding.ASCII.GetString(objBytes, 0, iRet);
            Console.WriteLine(strData);
            if (strData.IndexOf("OK") < 0)
            {
                CloseHandle(hModem);
                Console.WriteLine("AT+CGATT=1 error.. End test RAS");
                return false;
            }
            CloseHandle(hModem);

            //begin set dial parameters
            Console.WriteLine("Begin dial.Please wait..");
            int iSize = 2 + RAS_MaxEntryName + 1 + RAS_MaxPhoneNumber + 1 +
                RAS_MaxCallbackNumber + 1 + UNLEN + 1 + PWLEN + 1 + DNLEN + 1;
            char[] paras = new char[iSize];
            for (int i = 0; i < iSize; i++)
                paras[i] = (char)0;
            iSize = iSize * 2;
            //RASDIALPARAMS.dwSize
            paras[0] = (char)(iSize & 0xFFFF);
            paras[1] = (char)((iSize >> 16) & 0xFFFF);

            //RASDIALPARAMS.szEntryName

            paras[2] = 'G';

            paras[3] = 'p';

            paras[4] = 'r';

            paras[5] = 's';

            paras[6] = 'M';

            paras[7] = 'o';

            paras[8] = 'd';

            paras[9] = 'e';

            paras[10] = 'm';



            string username = "";

            string password = "";

            char[] charUserName;

            charUserName = username.ToCharArray();

            char[] charPassword;

            charPassword = password.ToCharArray();

            char[] charPhone;

            charPhone = "*99***1#".ToCharArray();



            for (int i = 0; i < charPhone.Length; i++)
            {

                paras[22 + i] = charPhone[i];

            }



            for (int i = 0; i < username.Length; i++)
            {

                paras[200 + i] = charUserName[i];

            }



            for (int i = 0; i < password.Length; i++)
            {

                paras[457 + i] = charPassword[i];

            }

            //Start to dial
            IO_DisableRASDialUserNamePasswordVerifyDialog();
            int hRasConn = 0;
            if (RasDial(0, null, paras, 0, 0, ref hRasConn) != 0)
            {
                Console.WriteLine("Dial error");
                if (hRasConn != 0)
                    RasHangUp(hRasConn);
               Console.WriteLine("End test RAS");
                return false;
            }
            Console.WriteLine("Dial ok");

            //get ip address
            Console.WriteLine("Get IP addr ");
            iSize = 2 + 2 + RAS_MaxIpAddress + 1;
            char[] rasIp = new char[iSize];
            for (int i = 0; i < iSize; i++)
                paras[i] = (char)0;
            iSize = iSize * 2;
            //RASPPPIP.dwSize
            rasIp[0] = (char)(iSize & 0xFFFF);
            rasIp[1] = (char)((iSize >> 16) & 0xFFFF);

            iRet = iSize;
            if (RasGetProjectionInfo(hRasConn, 0x8021, rasIp, ref iRet) != 0)
            {
                Console.WriteLine("Error");
                RasHangUp(hRasConn);
                Console.WriteLine("End test RAS");
                return false;
            }
            for (int i = 0; i < RAS_MaxIpAddress + 1; i++)
            {
                if (rasIp[2 + 2 + i] == (char)0)
                    break;
                 Console.WriteLine(rasIp[2 + 2 + i].ToString());
            }


            Console.WriteLine("End RAS Test");
            //try
            //{
            //    Process.Start("IExplore.exe", "@http://www.google.co.in");
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}
           // RasHangUp(hRasConn);
            return true;
        }

FTP 部分については、wininet.dll 関数を使用してライブラリを開発しました。

FTP をオープンする関数は次のとおりです。

 public void Open()
        {
            if (String.IsNullOrEmpty(_host)) throw new ArgumentNullException("Host");

            _hInternet = WININET.InternetOpen(
                "FTPLibTest",
                WININET.INTERNET_OPEN_TYPE_DIRECT,
                null,
                null,
                0);

            if (_hInternet == IntPtr.Zero)
            {
                Error();
            }

            uint uintFlags = 0;
            WININET.InternetGetConnectedState(ref uintFlags, 0);
            if (uintFlags > 0)
            {
                Console.WriteLine("Internet Connected");
            }
        }

FTPにログインする機能:

public void Login(string username, string password)
        {
            if (username == null) throw new ArgumentNullException("username");
            if (password == null) throw new ArgumentNullException("password");
            {

            }
            _hConnect = WININET.InternetConnect(_hInternet,
                _host,
                _port,
                username,
                password,
                WININET.INTERNET_SERVICE_FTP,
                134217728,
                IntPtr.Zero);

            if (_hConnect == IntPtr.Zero)
            {
                Error();
            }


        }

この関数から、12031のエラーが発生しました

WININET は、すべての dllimports を配置するクラスです

4

0 に答える 0