0

LPT1からRS232Cに簡単なデータを送るプログラムを書きました。基本的に、LPT からシリアルへの変換ケーブルは、2 台のマシンを接続するために使用されます。プログラムはパラレル ポートにデータを書き込む問題はありませんが、シリアル側では何も受信されません。

そのようなコミュニケーションが基本的なレベルで可能かどうか、またはプログラムを間違って作成したかどうか疑問に思っています。

DataSender (LPT1 への書き込み)

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{

        HANDLE m_hCommPort = ::CreateFile( "LPT1",
       GENERIC_READ|GENERIC_WRITE,  // access ( read and write)
       0,                           // (share) 0:cannot share the
                                    // COM port
       0,                           // security  (None)
       OPEN_EXISTING,               // creation : open_existing
       FILE_FLAG_OVERLAPPED,        // we want overlapped operation
       0                            // no templates file for
                                    // COM port...
       );


        if(m_hCommPort) {
            printf("OK\n");
        }
        char data[] = "123481278349789\r\n";
        DWORD dwSize = strlen(data);
        DWORD dwBytesWritten;
        DWORD dwBytesRead;

        while(true) {

        if(WriteFile (m_hCommPort,data,dwSize,&dwBytesWritten ,0)) {
            printf("sended: %d\n", dwBytesWritten);
        } else {
            printf("send fail: %d\n", dwBytesWritten);
        }

        printf("send done\n");

        int i;
        scanf("%d", &i);
        }
        return 0;

}

DataReceiver (COM3 から受信)

class Program
{
    static void Main(string[] args)
    {
        SerialPort sendingPort = new SerialPort("COM3", 9600);
        try
        {
            sendingPort.Open();
            char c = (char)sendingPort.ReadChar();

            Console.WriteLine("Readed:" + c);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }


        Console.ReadKey();
    }
}
4

0 に答える 0