C # Only the class for direct serial port operation is provided. If you operate the parallel port directly, you need to call the API function:
Using system. runtime. interopservices;
String senddata = "^ XA ^ fo50, 80 ^ ADN, 36,20 ^ fdtrw eol2 ^ FS ^ xz"; // zebra printer Command Format
[Dllimport ("kernel32.dll")]
Private Static extern int createfile (
String lpfilename, // the serial port to be opened/parallel port name
Int dwdesiredaccess, // specifies the access method of the port, which is generally set to readable and writable.
Int dwsharemode, // The Sharing Mode of the specified port. The port cannot be shared, so it is set to 0.
Int lpsecurityattributes, // set the Security Attribute of the port. This parameter is not supported in Win9x and should be set to null.
Int dwcreationdisposition, // for serial communication, the creation method can only be open_existing
Int dwflagsandattributes, // specifies the serial port attribute and flag
Int htemplatefile); // for serial communication, the value must be set to null.
[Dllimport ("kernel32.dll")]
Public static extern void writefile (INT comhandle, string senddata, int strlen, ref int Alen, int zero );
[Dllimport ("kernel32.dll")]
Public static extern void closehandle (INT handle );
Int handle = createfile ("LPT1", 0x40000000, 0, 0, 3/** // * open_existing */, 0, 0 );
If (handle! = 0 ){
Writefile (handle, senddata, strlen, ref Alen, 0 );
Closehandle (handle); // note that the printer executes the command only after the parallel port is closed.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.