More migration
This commit is contained in:
parent
c171f2a316
commit
3394e70767
@ -16,3 +16,4 @@ GetOverlappedResult
|
|||||||
ClearCommError
|
ClearCommError
|
||||||
GetCommProperties
|
GetCommProperties
|
||||||
WIN32_ERROR
|
WIN32_ERROR
|
||||||
|
GetHandleInformation
|
@ -35,5 +35,6 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Windows.SDK.Win32Metadata" Version="61.0.15-preview" />
|
<PackageReference Include="Microsoft.Windows.SDK.Win32Metadata" Version="61.0.15-preview" />
|
||||||
|
<PackageReference Include="System.Memory" Version="4.5.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -257,11 +257,10 @@ public partial class SerialPort : IDisposable
|
|||||||
CheckResult();
|
CheckResult();
|
||||||
_writeCount = toSend.GetLength(0);
|
_writeCount = toSend.GetLength(0);
|
||||||
|
|
||||||
fixed (byte* ptr = toSend)
|
|
||||||
fixed (NativeOverlapped* ptrOl = &_ptrUwo)
|
fixed (NativeOverlapped* ptrOl = &_ptrUwo)
|
||||||
{
|
{
|
||||||
uint sent;
|
uint sent;
|
||||||
if (PInvoke.WriteFile(_hPort, ptr, (uint)_writeCount, &sent, ptrOl))
|
if (PInvoke.WriteFile(_hPort, toSend.AsSpan(), &sent, ptrOl))
|
||||||
{
|
{
|
||||||
_writeCount -= (int)sent;
|
_writeCount -= (int)sent;
|
||||||
}
|
}
|
||||||
@ -460,17 +459,16 @@ public partial class SerialPort : IDisposable
|
|||||||
|
|
||||||
private unsafe void ReceiveThread()
|
private unsafe void ReceiveThread()
|
||||||
{
|
{
|
||||||
byte* buf = stackalloc byte[1];
|
byte[] buffer = new byte[1];
|
||||||
|
|
||||||
AutoResetEvent sg = new(false);
|
AutoResetEvent sg = new(false);
|
||||||
NativeOverlapped ov = new() { EventHandle = sg.SafeWaitHandle.DangerousGetHandle() };
|
NativeOverlapped ov = new() { EventHandle = sg.SafeWaitHandle.DangerousGetHandle() };
|
||||||
|
|
||||||
COMM_EVENT_MASK eventMask = 0;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
COMM_EVENT_MASK eventMask = 0;
|
||||||
|
|
||||||
if (!PInvoke.SetCommMask(_hPort,
|
if (!PInvoke.SetCommMask(_hPort,
|
||||||
COMM_EVENT_MASK.EV_RXCHAR | COMM_EVENT_MASK.EV_TXEMPTY | COMM_EVENT_MASK.EV_CTS |
|
COMM_EVENT_MASK.EV_RXCHAR | COMM_EVENT_MASK.EV_TXEMPTY | COMM_EVENT_MASK.EV_CTS |
|
||||||
COMM_EVENT_MASK.EV_DSR
|
COMM_EVENT_MASK.EV_DSR
|
||||||
@ -540,7 +538,7 @@ public partial class SerialPort : IDisposable
|
|||||||
uint gotBytes;
|
uint gotBytes;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!PInvoke.ReadFile(_hPort, buf, 1, &gotBytes, &ov))
|
if (!PInvoke.ReadFile(_hPort, buffer, &gotBytes, &ov))
|
||||||
{
|
{
|
||||||
if (Marshal.GetLastWin32Error() == (int)WIN32_ERROR.ERROR_IO_PENDING)
|
if (Marshal.GetLastWin32Error() == (int)WIN32_ERROR.ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
@ -555,7 +553,7 @@ public partial class SerialPort : IDisposable
|
|||||||
|
|
||||||
if (gotBytes == 1)
|
if (gotBytes == 1)
|
||||||
{
|
{
|
||||||
OnRxChar(buf[0]);
|
OnRxChar(buffer[0]);
|
||||||
}
|
}
|
||||||
} while (gotBytes > 0);
|
} while (gotBytes > 0);
|
||||||
}
|
}
|
||||||
@ -593,8 +591,7 @@ public partial class SerialPort : IDisposable
|
|||||||
|
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
{
|
{
|
||||||
uint f;
|
if (!Win32Com.GetCommModemStatus(_hPort.DangerousGetHandle(), out uint f))
|
||||||
if (!Win32Com.GetCommModemStatus(_hPort.DangerousGetHandle(), out f))
|
|
||||||
{
|
{
|
||||||
throw new CommPortException("IO Error [005]");
|
throw new CommPortException("IO Error [005]");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user