locked
UWP C# UART RS485 Polling Issue RRS feed

  • Question

  • Hi, I have my UART for RS485 using a FTDI USB to 485 cable connected to Raspberry Pi on Windows IoT Core. I set a dispatchertimer at every 1second to transmit polling to respective field devices. I am able to tx and rx the 485 data with no problem. However, after the polling loop to about 20 times it just crash and exited the debug mode. I used try & catch to trap the exception but could not get it. However, i manage to read the error message at the debug output pane - The program [0xBB0] PwD.exe' has exited with code -1073741811 (0xc000000d).

    I am not sure what caused the problem and where did I do wrong?

    Please help. Thanks.

    private void PollTimer_Tick(object sender, object e)
        {
            if (pollCounter <= maxDevice)
            {
                var a = pollCounter | 0x80;
                pollCounter++;
    
                TxAdr = Convert.ToByte(a);
                TxCmd = TxPoll;
    
                TxPollCard();
    
            }
            else pollCounter = 0;
        }
    
     private async void TxPollCard()
        {
            if (serialPort != null)
            {
                List<byte> data = new List<byte>();
    
                data.Add(TxHeader);
                data.Add(TxAdr);
                data.Add(TxCmd);
    
                TxChkSum = 0;
                foreach (byte a in data)
                {
                    TxChkSum += a;
                }
    
                TxChkSum = (byte)(TxChkSum - 0x80);
                data.Add(TxChkSum);
    
                try
                {
                    // Create the DataWriter object and attach to OutputStream
                    dataWriteObject = new DataWriter(serialPort.OutputStream);
    
                    dataWriteObject.WriteBytes(data.ToArray());
    
                    Task<UInt32> storeAsyncTask;
                    // Launch an async task to complete the write operation
                    storeAsyncTask = dataWriteObject.StoreAsync().AsTask();
    
                    UInt32 bytesWritten = await storeAsyncTask;
                    
                    dataWriteObject.DetachBuffer();
                }
                catch (Exception ex)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        MainStatusDisplay.Text = ex.Message;
                    });
                }
    
            }
            else
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    MainStatusDisplay.Text = "No UART port found";
                });
            }
        }




    • Edited by mylim Wednesday, November 11, 2020 7:42 AM
    • Moved by CoolDadTx Wednesday, November 11, 2020 2:59 PM Not C# related
    Wednesday, November 11, 2020 7:25 AM

All replies

  • Hi mylim,

    Thank you for posting here.

    Since this thread is related to UWP, so I suggest that you can ask this question in Microsoft Q&A.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 11, 2020 8:47 AM
  • Thanks.
    Wednesday, November 11, 2020 9:50 AM