|
<訂正・補足>
前回、画像サイトに上げた写真で、自分では間違いをしてないのに 訂正する必要があります。上段の写真は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; } |

>
- コンピュータとインターネット
>
- コンピュータ
>
- ソフトウェア





