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