ここから本文です
ブログを始めました・・・

書庫全体表示

<訂正・補足>
前回、画像サイトに上げた写真で、自分では間違いをしてないのに
訂正する必要があります。上段の写真はFM-7からデータを送信して
windows7で受信した時の状態です。ですので操作の順序としては
中段 → 下段  → 上段 になります。因みにアップロードの順です。

今回の内容を書いてる最中に住んでるマンションで小火が発生して
2時間程中断しました。昨年は真夜中の地震、いろいろとあります。

・windows用のソフトの作成手順
1)ドライバーの入手は下で Virtual COM Port Drivers
https://www.ftdichip.com/Drivers/VCP.htm
その後解凍しインストールして下さい
CDM21228_Setup.zip

2)Support → Software Examples → Code Examples
ここにある Visual C++ の Example 5 を使います。

3)Visual Studio はインストールしてることを前提にして
サンプルコードと比較し #ifdef #else #endif を使って
訂正して下さい。なおFM-7側のソフトは手直ししてません。
使い方やドライバーや環境の違い等については次回に。

#ifdef SHUJI_AKITA2001

<この部分が自分が追加したコード>

#else

<この部分がサンプルコード>

#endif    


#define FT245RL_BROCK 64
#define FT245RL_BROCK2 16
#define SHUJI_AKITA2001

/********************************************************/
// Writing data to the USB to UART converter
/********************************************************/

    DWORD dwwritten = 0;
    char data_out[12] = "HELLO WORLD";
    DWORD w_data_len = 12;
            
#ifdef SHUJI_AKITA2001

    char cdir[255];

    unsigned char buf[512];
    unsigned char send_buf[1024];
    FILE* file;
    int i;
    int len;
    errno_t error;

    GetCurrentDirectory(255, cdir);
    printf(" fopen_s  1 %s\n", cdir);
    printf(" fopen_s  2 %s\n", argv[1]);

    if (2 == argc) {
        // file = fopen(argv[1], "rb");
        error = fopen_s(&file, argv[1], "rb");
        if (error != 0) {
            CloseHandle(hCommPort);
            printf(" fopen_s error 3 %s\n", argv[1]);
            return -2;
        }

        printf("%s SEND STARAT\n", argv[1]);

        fseek(file, 0, SEEK_SET);
        do {
            len = fread(buf, 1, FT245RL_BROCK, file);
            if (0 == len)  
                break;
            printf("fread %0d\n", len);
            for (i = 0; i < FT245RL_BROCK; i++) {
                send_buf[2 * i + 1] = buf[i];  //     下位7ビットはそのままコピー
                send_buf[2 * i] = buf[i] >> 1; //     上位7ビットは1ビット右シフトしコピー

            }

            fSuccess = WriteFile(hCommPort, &send_buf, len*2, &dwwritten, NULL);

        } while (FT245RL_BROCK == len);

        fclose(file);

        printf("%s SEND END\n", argv[1]);
    }

#else

        fSuccess = WriteFile(hCommPort, &data_out, w_data_len, &dwwritten, NULL);
        if (!fSuccess)         {
            dwErr = GetLastError();
            printf("Write Failed \n", GetLastError());
            return (4);
        }    
        printf("bytes written = %d\n", dwwritten);

#endif    

/********************************************************/
//Reading data from the USB to UART converter
/********************************************************/
        // buf[256];
        DWORD dwRead, dwRead2;

#ifdef SHUJI_AKITA2001    
 // 受信処理ループ
 
        // file = fopen("sirial_20181105.dat", "wb");
        error = fopen_s(&file, "sirial_20190620.dat", "wb");
        if (error != 0) {            
            CloseHandle(hCommPort);
            printf("fopen error 4 \n");
            return -4;
        }

        for (;;) {
            ReadFile(hCommPort, buf, FT245RL_BROCK2, &dwRead, NULL);
            if (0 < dwRead) {
                fwrite(buf, 1, dwRead, file);
                // fflush(file);

                for (i = 0; i < (int)dwRead; i++)
                    printf("%02X", buf[i]);
       
                printf("\n");

            }

            if( (0 == dwRead ) || (0 > dwRead)) {
            
                    ReadFile(hCommPort, buf, 16, &dwRead2, NULL);
                    if (0 < dwRead2) {
                        fwrite(buf, 1, dwRead2, file);
                        for (i = 0; i < (int)dwRead2; i++)
                            printf("%02X", buf[i]);
                    }
                

                break;

            }

            


        }

        fclose(file);
            
#else

    memset(buf,0,256);


    if (ReadFile(hCommPort, buf, w_data_len, &dwRead, NULL))
        printf("data read = %s\n", buf);

#endif
/********************************************************/
//Closing the device at the end of the program
/********************************************************/

    CloseHandle(hCommPort);

    getchar();
    return 0;

}

shuji_akita2001
shuji_akita2001
男性 / O型
人気度
Yahoo!ブログヘルプ - ブログ人気度について
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

最新のコメント最新のコメント

すべて表示

Yahoo!からのお知らせ

よしもとブログランキング

もっと見る
本文はここまでですこのページの先頭へ

[PR]お得情報

ふるさと納税サイト『さとふる』
実質2000円で特産品がお手元に
11/30までキャンペーン実施中!
ふるさと納税サイト『さとふる』
お米、お肉などの好きなお礼品を選べる
毎日人気ランキング更新中!
数量限定!イオンおまとめ企画
「無料お試しクーポン」か
「値引きクーポン」が必ず当たる!

その他のキャンペーン

みんなの更新記事