0
votes

I have a UWP app which receives data over USB from a micro controller and logs the data to a database. I have a second WPF application which also gets some data from a separate micro controller and I want to log that data as well. To do this I would like to send data from the WPF application to the UWP app and log the data together. I am trying to design to the fastest log speed of 50ms between logs. Both application are run on the same computer.

I have been using this as my main resource so far: https://docs.microsoft.com/en-us/windows/uwp/communication/interprocess-communication

I have tried TCP/UDP but ran into the issue that UWP can not use localhost loopback.
I looked into name pipes but it seems UWP does not support named pipes outside its application package.

It seems like app service is the direction I want to be heading however I am unsure how that would work. The examples I have seen make it seem like app service is just some code that can be called by another application but doesn't interact with its host application. I would need the service to pipe the data into the UWP application.

My other thought was maybe there is a way I could run the database logger as an application service and receiver data from both the UWP and WPF applications. It would need to log at fixed intervals using the latest values that each application supplied and support some kind of Start() and Stop() interface.

Is app service the right direction? Are there other options? If it is the right option how does the host application send or get data from the app service?

Its getting close to the point where I feel like I either need to port my UWP app to WPF or use a virtual com port to communicate between the applications.

2

2 Answers

1
votes

App service can achieve the communication between wpf and uwp application, when you run these applications and want to transfer data, you can create the AppServiceConnection object and connect uwp application in wpf, then you can communicate between wpf and uwp app. For example, take the following code as an example, passing the AppServiceName you declared in your uwp project's manifest to the AppServiceName of AppServiceConnection and passing the PackageFamilyName of your uwp app. Then opening the connection to the endpoint for the app service. By subscribing the RequestReceived event to communicate.

in WPF app,

private void Button_Click(object sender, RoutedEventArgs e)
{
    connection = new AppServiceConnection();
    connection.AppServiceName = "CommunicationService";
    connection.PackageFamilyName = "Microsoft.AppServiceBridge_8wekyb3d8bbwe";
    connection.RequestReceived += Connection_RequestReceived;

    connection.OpenAsync();
        
}

For more details about how to configue in your uwp project, you can refer to this official sample.

In addition, after connecting, you can call AppServiceConnection.SendMessageAsync() method to send data to wpf. When the wpf app receives data, it will trigger RequestReceived event, you can get the data by using args.Request.Message and call the args.Request.SendResponseAsync method to send data to uwp app.

0
votes

Follow this guide by StefanWick. The method describes for desktop extension but will work the same for extenal apps too.