I am programming with vb and have a UWP project using a Raspberry Pi.
When I use a USB to RS485 converter I can use the IsRequestToSendEnabled from SerialDevice to sync communication between the Raspberry and the PLC, but when I try to use the UART, with a TTL to RS485 converter, the IsRequestToSendEnabled is not available.
The following error shows up:
The request is not supported. (Exception from HRESULT: 0x80070032)
And
System.AccessViolationException HResult=0x80004003 Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The UART does not support it? I am no expert in UART, so how do I sync communication frames in Modbus then? The TTL to RS485 is Half-Duplex, I assume I have to sync communication somehow. It does work with a USB to RS485 converter, but I do not want to use it.
Here is a code sample:
Private Async Function ListAvailablePorts() As Task(Of Boolean)
Try
Dim aqs As String = SerialDevice.GetDeviceSelector("UART0") '"UART0") '"COM1")
Dim _portlist As DeviceInformationCollection = Await DeviceInformation.FindAllAsync(aqs, Nothing)
client = Await SerialDevice.FromIdAsync(_portlist(0).Id)
client.ReadTimeout = TimeSpan.FromMilliseconds(1000)
client.WriteTimeout = TimeSpan.FromMilliseconds(1000)
client.BaudRate = 9600
client.Parity = SerialParity.None
client.DataBits = 8
client.StopBits = SerialStopBitCount.One
client.Handshake = SerialHandshake.None ' SerialHandshake.None ' SerialHandshake.XOnXOff ' SerialHandshake.RequestToSend
client.IsRequestToSendEnabled = False ' error here when using UART
client.IsDataTerminalReadyEnabled = False
Return True
Catch ex As Exception
Debug.WriteLine("Error listing ports: " & ex.Message)
Return False
End Try
End Function
The error you are receiving can happen in various use cases. But I'm guessing the device capapability isn't set for serial access.
Make sure to enable the serial communication device capability in the package.appxmanifest.
<Capabilities>
<Capability Name="internetClient" />
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>
</Capabilities>
UWP on Raspberry Pi will not produce a proper SerialDevice.GetDeviceSelector when using
SerialDevice.GetDeviceSelector("COM0")
USB-Serial devices don't show as COM ports on Window IoT Core like they do on Windows 10 Desktop.
Also, if you are attempting to use a serial device OTHER than the onboard UART, or an FTDI serial device, it will not work unless you get drivers for the Pi installed on the Pi. Which is unlikely, as I have yet to find a manufacturer other than FTDI provide drivers for Windows IoT Core. (ala CH340)
The Windows.Devices.SerialCommunication namespace is flaky at best. I am willing to accept it that my troubles are of my own design but with the lack of support it's like pulling teeth to get a solution stable. Every iteration of enhancement provides their own set of difficulties.
Here's what I've learned over the past week on the subject of Serial Communication on the Raspberry Pi.
Here's how I initialize an FTDI USB-Serial device.
var aqs = SerialDevice.GetDeviceSelector();
var devices = await DeviceInformation.FindAllAsync(aqs);
var deviceInfo = devices?.Where(i => i.Name == "FT232R USB UART").FirstOrDefault();
What I did was inspected ALL devices and chose a unique property to select my device. Supposedly, using SerialDevice.GetDeviceSelectorFromUsbVidPid should work, but it did not for me.
User contributions licensed under CC BY-SA 3.0