C# 从并口到串口写入数据

C# 从并口到串口写入数据,c#,c++,winapi,serial-port,parallel-port,C#,C++,Winapi,Serial Port,Parallel Port,我们编写了一个程序,将简单数据从LPT1发送到RS232C。基本上,LPT到串行转换电缆用于将两台机器连接在一起。程序在将数据写入并行端口时没有问题,但在串行端没有收到任何数据 我想知道这样的交流在基本层面上是可能的,还是我写的程序不正确 DataSender写入LPT1 #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { HANDLE m_hCommPort = ::CreateFile( "LPT1",

我们编写了一个程序,将简单数据从LPT1发送到RS232C。基本上,LPT到串行转换电缆用于将两台机器连接在一起。程序在将数据写入并行端口时没有问题,但在串行端没有收到任何数据

我想知道这样的交流在基本层面上是可能的,还是我写的程序不正确

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;

}
从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();
    }
}

如何知道将数据写入并行端口没有问题?第一个程序是否暂停,输出是什么?程序不暂停。WriteFile返回true,其中包含写入的字节长度,所以我假设它正在工作,大约每秒有多少行?并更好地描述LPT到串行转换电缆。里面有一块电子设备,对吗?用发光二极管?它是如何供电的?对于电缆,请检查下图: