Raspberry pi Raspberry Pi3和使用rs232 TTL转换器的windows IOT Uart0通信

Raspberry pi Raspberry Pi3和使用rs232 TTL转换器的windows IOT Uart0通信,raspberry-pi,serial-port,raspberry-pi3,windows-10-iot-core,ttl,Raspberry Pi,Serial Port,Raspberry Pi3,Windows 10 Iot Core,Ttl,我正在使用安装了Windows 10 IOT的raspberry Pi3。。。 我正在尝试用Rs232 TTL转换器设备与我的树莓通信,该设备使用4根电线插入:1根连接到VCC,1根连接到GND,2根连接到TX和RX。 这是我现在使用的RS232-TTL: 此转换器通过串行电缆插入我的计算机COM2。 这是我的序列号的代码 private async void initSeriale() { string nomePorta = "UART0"; //MODDAT

我正在使用安装了Windows 10 IOT的raspberry Pi3。。。 我正在尝试用Rs232 TTL转换器设备与我的树莓通信,该设备使用4根电线插入:1根连接到VCC,1根连接到GND,2根连接到TX和RX。 这是我现在使用的RS232-TTL: 此转换器通过串行电缆插入我的计算机COM2。 这是我的序列号的代码

private async void initSeriale()
    {
        string nomePorta = "UART0";     //MODDATO

        string acquisito = SerialDevice.GetDeviceSelector(nomePorta);

        var mieiDispo = await DeviceInformation.FindAllAsync(acquisito, null);

        if(mieiDispo.Count == 0)
        {
            textBox.Text = "No device found!";
            return;
        }

        dispositivo = await SerialDevice.FromIdAsync(mieiDispo[0].Id);

        textBox.Text = dispositivo.PortName;
        try
        {
            dispositivo.WriteTimeout = TimeSpan.FromMilliseconds(1000);
            dispositivo.ReadTimeout = TimeSpan.FromMilliseconds(1000);
            dispositivo.BaudRate = 9600;
            dispositivo.DataBits = 8;
            dispositivo.Parity = SerialParity.None;
            dispositivo.StopBits = SerialStopBitCount.One;
            dispositivo.IsRequestToSendEnabled = true;

            textBox.Text += " Is configured";
        } catch
        {
            textBox.Text += " Error";
        }

        scriviStatistiche();
    }
当我使用下面的代码发送一些数据时,它不起作用

private async void leggiSeriale(SerialDevice disp)
    {
        CancellationTokenSource ReadCancellationTokenSource = new CancellationTokenSource();
        CancellationToken token = ReadCancellationTokenSource.Token;
        try
        {
            var dataReaderObject = new DataReader(disp.InputStream);

            while (true)
            {
                await ReadAsync(ReadCancellationTokenSource.Token, dataReaderObject);
            }

        }
        catch
        {

        }

    }

    private async Task ReadAsync(CancellationToken cancellationToken, DataReader reader)
    {

        Task<UInt32> loadAsyncTask;

        uint ReadBufferLength = 1024;

        cancellationToken.ThrowIfCancellationRequested();

        reader.InputStreamOptions = InputStreamOptions.Partial;

        loadAsyncTask = reader.LoadAsync(ReadBufferLength).AsTask(cancellationToken);

        uint bytesRead = await loadAsyncTask;
        if (bytesRead > 0)
        {
            textBox1.Text = reader.ReadString(bytesRead);
            textBox.Text = "bytes letti con successo!";
        }
    }

    private async void button2_Click(object sender, RoutedEventArgs e)
    {
        var dataWriteObject = new DataWriter(dispositivo.OutputStream);

        await WriteAsync(dataWriteObject);

        dataWriteObject.DetachStream();
        dataWriteObject = null;
    }

    private async Task WriteAsync(DataWriter x)
    {
        Task<uint> storeAsyncTask;

        x.WriteString(textBox.Text);

        storeAsyncTask = x.StoreAsync().AsTask();

    }

    private void button_Click_1(object sender, RoutedEventArgs e)
    {
        leggiSeriale(dispositivo);
    }
private async void leggiSeriale(串行设备显示)
{
CancellationTokenSource ReadCancellationTokenSource=新的CancellationTokenSource();
CancellationToken token=ReadCancellationTokenSource.token;
尝试
{
var dataReaderObject=新的DataReader(disp.InputStream);
while(true)
{
等待ReadAsync(ReadCancellationTokenSource.Token,dataReaderObject);
}
}
抓住
{
}
}
专用异步任务ReadAsync(CancellationToken CancellationToken,DataReader reader)
{
任务加载异步任务;
uint ReadBufferLength=1024;
cancellationToken.ThrowIfCancellationRequested();
reader.InputStreamOptions=InputStreamOptions.Partial;
loadAsyncTask=reader.LoadAsync(ReadBufferLength).AsTask(cancellationToken);
uint bytesRead=等待加载异步任务;
如果(字节读取>0)
{
textBox1.Text=reader.ReadString(bytesRead);
Text.Text=“bytes letti con successo!”;
}
}
专用异步无效按钮2\u单击(对象发送方,路由目标)
{
var dataWriteObject=newdatawriter(dispositivo.OutputStream);
等待写入同步(dataWriteObject);
dataWriteObject.DetachStream();
dataWriteObject=null;
}
专用异步任务WriteAsync(DataWriter x)
{
任务库;任务库;
x、 WriteString(textBox.Text);
storeAsyncTask=x.StoreAsync().AsTask();
}
私有无效按钮\u单击\u 1(对象发送者,路由目标)
{
leggiSeriale(dispositivo);
}
为了编译和调试代码,我正在使用Visual Studio 2015社区。
我做错了什么?

“在下面它不起作用”——这是一个无用的总结,而您应该提供失败的描述或症状。“我做错了什么?”——您没有清楚地说明您对硬件和软件功能的测试情况。这是一种最坏的情况吗?当您尝试调试代码时,您甚至不知道串行链接硬件是否能够成功传输数据?您的
initserial()
WriteAsync()
方法没有问题。你到底有什么问题?我解决了,问题是电缆。我更换了电缆,现在它工作得很好,谢谢你必须将设备的TX端口连接到Raspberry Pi上的RX端口