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

Native USB Printing support windows #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gary-gr9
Copy link

@Gary-gr9 Gary-gr9 commented Jul 6, 2023

Implemented native USB Printing support for Windows (should work for linux as well) with complete printer status report back.
No driver install or Virtual Serial Port needed.
Choose printer from list of USB devices and send data straight to the printer like Serial or Network printer.
.Net Standard.
Tested: Epson TM-T82III, Element RW80, Sunmi NT3111, Bixolon E300
Possible fix for Issues : #186 #220 #223

…linux as well) with complete printer status report back.

No driver install or Virtual Serial Port needed.
Choose printer from list of usb devices and send data straight to the printer like Serial or Network printer.
Possible fix for Isuues : lukevp#186 lukevp#220 lukevp#223
public uint pid;
}
private static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this DLL Imports...

I will defer the final decision to @lukevp , but if he is ok with these import, then the PR sounds great.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey all, sorry I missed this. How does this work outside of Windows? This seems like old school COM stuff that's windows / full framework only (not .NET core / .NET standard)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is like USB1, USB2.... Planning to mergue it ???

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukevp I don't think those imports will work outside windows. From experience with Mono back in the day one would need to have corresponding .so files and etc. Nothing straight forward.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, it could be a Windows-only feature, since it seems that only Windows has this issue with USB. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi all,
I developed this feature as a windows only feature, because there wasn't any way of printing to USB printer on Windows without using virtual serial port drivers.
@lukevp As far as I understand Devicefinder.cs doesn't have any other dependency outside .netStandard but yes it only works on windows (finding devices connected).

//keeping separate file streams performs better
//while using 1 file stream printers were having intermittent issues while printing
//your milege may vary
_rfile = File.Open(usbPath, FileMode.Open, FileAccess.Read);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error and cannot findout how to resolve, have you got this error too?
FileStream was asked to open a device that was not a file. For support for devices like 'com1:' or 'lpt1:', call CreateFile, then use the FileStream constructors that take an OS handle as an IntPtr.

}
string path = Marshal.PtrToStringUni(new IntPtr(intPtr2.ToInt64() + 4));

DeviceDetails deviceDetails = GetDeviceDetails(path, intPtr, DeviceInfoData);
Copy link

@Fasjeit Fasjeit Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some devises (non printers) I got System.ComponentModel.Win32Exception (1168) here - GetDeviceDetails(...).

Maybe it will be a good idea to just to skip the problematic ones (try-catch-continue?) and go on instead of throwing an exception and failing to enumerate any of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants