Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update serial_windows.go #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions serial_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func setCommState(h syscall.Handle, baud int, databits byte, parity Parity, stop
}

r, _, err := syscall.Syscall(nSetCommState, 2, uintptr(h), uintptr(unsafe.Pointer(&params)), 0)
if r == 0 {
if r == 0 || err != syscall.Errno(0) {
return err
}
return nil
Expand Down Expand Up @@ -259,15 +259,15 @@ func setCommTimeouts(h syscall.Handle, readTimeout time.Duration) error {
timeouts.ReadTotalTimeoutConstant = uint32(timeoutMs)

r, _, err := syscall.Syscall(nSetCommTimeouts, 2, uintptr(h), uintptr(unsafe.Pointer(&timeouts)), 0)
if r == 0 {
if r == 0 || err != syscall.Errno(0) {
return err
}
return nil
}

func setupComm(h syscall.Handle, in, out int) error {
r, _, err := syscall.Syscall(nSetupComm, 3, uintptr(h), uintptr(in), uintptr(out))
if r == 0 {
if r == 0 || err != syscall.Errno(0) {
return err
}
return nil
Expand All @@ -276,15 +276,15 @@ func setupComm(h syscall.Handle, in, out int) error {
func setCommMask(h syscall.Handle) error {
const EV_RXCHAR = 0x0001
r, _, err := syscall.Syscall(nSetCommMask, 2, uintptr(h), EV_RXCHAR, 0)
if r == 0 {
if r == 0 || err != syscall.Errno(0) {
return err
}
return nil
}

func resetEvent(h syscall.Handle) error {
r, _, err := syscall.Syscall(nResetEvent, 1, uintptr(h), 0, 0)
if r == 0 {
if r == 0 || err != syscall.Errno(0) {
return err
}
return nil
Expand All @@ -297,7 +297,7 @@ func purgeComm(h syscall.Handle) error {
const PURGE_RXCLEAR = 0x0008
r, _, err := syscall.Syscall(nPurgeComm, 2, uintptr(h),
PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR, 0)
if r == 0 {
if r == 0 || err != syscall.Errno(0) {
return err
}
return nil
Expand All @@ -306,7 +306,7 @@ func purgeComm(h syscall.Handle) error {
func newOverlapped() (*syscall.Overlapped, error) {
var overlapped syscall.Overlapped
r, _, err := syscall.Syscall6(nCreateEvent, 4, 0, 1, 0, 0, 0, 0)
if r == 0 {
if r == 0 || err != syscall.Errno(0) {
return nil, err
}
overlapped.HEvent = syscall.Handle(r)
Expand All @@ -319,7 +319,7 @@ func getOverlappedResult(h syscall.Handle, overlapped *syscall.Overlapped) (int,
uintptr(h),
uintptr(unsafe.Pointer(overlapped)),
uintptr(unsafe.Pointer(&n)), 1, 0, 0)
if r == 0 {
if r == 0 || err != syscall.Errno(0) {
return n, err
}

Expand Down