jcurl / RJCP.DLL.SerialPortStream

SerialPortStream is an independent implementation of System.IO.Ports.SerialPort and SerialStream for better reliability and maintainability. Default branch is 2.x and now has support for Mono with help of a C library.
Microsoft Public License
624 stars 197 forks source link

Remote peer could not receive the data send from RaspberryPi(based on Debian stretch) via SerialPortStream #59

Closed shaojun closed 6 years ago

shaojun commented 6 years ago

Hi, thanks for the great work. I'm using a USB to TTL with CP2102 chip. this is via lsusb: Bus 001 Device 009: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light

I've build your lib in my Pi, and then added the output file into my .NET Core 2.1 application, the application finally can run, and it even can listed the available serial port via SerialPortStream.GetPortNames(), what I get is /dev/ttyUSB0. I want do sth more:

public void Test()
{
    SerialPortStream comPort = new SerialPortStream("/dev/ttyUSB0", 9600, 8, Parity.Odd, StopBits.One)
            {
                ReadTimeout = 5000,
                WriteTimeout = 5000
            };
    comPort.DataReceived += Port_DataReceived;
    comPort.Open();
    //pesudo code, send 0x5020FA every 1 second.
    timer.Fire(()=>{
        comPort.Write(new byte[]{0x50, 0x20,0xFA});
        logger.Debug("Msg send");
    }, 1000);
}
private void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    var buffer = new List<byte>();
    while (this.comPort.BytesToRead > 0)
    {
        var readByte = this.comPort.ReadByte();
        logger.Debug("RAW read: 0x" + readByte.ToString("X").PadLeft(2, '0'));                    
    }
}

by running this app, I can see the UsbToTtl's led for TX is blinking as expected. for the remote peer side(a PC), I've opened a RS232 port, and connected PC Rx UsbToTtl's Tx, I noticed either I always received the E5, B7, and if I connected the PC Tx to UsbToTtl's Rx, the UsbToTtl's rx led will keep on, and will hang the Pi to death though I never send anything from PC, any idea?