Reputation: 1
I am running an IoT Edge Module on Windows 10 IoT Core on a Minnowboard Turbot. This module needs to read a stream from a USB port. We're using System.Io.Ports (.net standard version that is compatible with our .net core 2.1 code).
I have seen this work on a laptop with Windows 10 pro, but it does not work Windows IoT Core. I can find some sources that state that System.Io.Ports is not supported on IoT Core because of the naming scheme for Usb ports (which must be called COM{x} for SerialPort to work properly. The Readme that comes with the SerialIOPrts sample from Windows IoT Samples (https://go.microsoft.com/fwlink/?linkid=860459) says
"This sample uses standard .NET Core System.IO.Ports APIs to access the serial devices. These APIs only work with serial devices which come named COM{x}. Consequently, this approach is relevant on Windows 10 IoT Enterprise, but not Windows 10 IoT Core."
Has anyone found a way around this? I can probably get it to work on Windows 10 IoT Enterprise but I would really like to prove we can run this module on minimal hardware/os.
Upvotes: 0
Views: 1623
Reputation: 9710
Using System.IO.Ports on Windows IoT Core you can refer to "SerialWin32 Azure IoT Edge module". (Note: These instructions will work on a PC running Windows 10 IoT Enterprise or Windows IoT Core build 17763. Only the x64 architecture is supported currently. Arm32 will come in the future.)
(Not for Azure IoT Edge Module)To access serial device without port name (COMx) on Windows IoT Core you can use Win32 API CreateFile. There is a project template for creating a Win32 console application for Windows IoT Core you can get started.
Here I create a sample using device id to open an serial device and write and read:
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
DWORD errCode = 0;
LPCWSTR pDeviceId = L"\\\\?\\FTDIBUS#VID_0403+PID_6001+A50285BIA#0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73}";
HANDLE serialDeviceHdl = CreateFile(pDeviceId, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (!serialDeviceHdl)
{
errCode = GetLastError();
cout << "Open device failed. Error code: " << errCode << endl;
return 0;
}
DWORD writenSize = 0;
BOOL result = WriteFile(serialDeviceHdl, "hello", 5, &writenSize, NULL);
if (FALSE == result)
{
errCode = GetLastError();
cout << "Write to device failed. Error code: " << errCode << endl;
}
CHAR readBuf[5];
DWORD readSize = 0;
result = ReadFile(serialDeviceHdl, readBuf, 5, &readSize, NULL);
if (FALSE == result)
{
errCode = GetLastError();
cout << "Read from device failed. Error code: " << errCode << endl;
}
}
Device Id you can find, for example, via official sample "SerialUART" - "DeviceInformation.Id".
How to deploy and debug win32 C++ console on Windows IoT Core you can refer to here.
Upvotes: 0