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