C++ Linux: OpenPrinter equivalent
C++ Linux: OpenPrinter equivalent
我使用Qt.我需要直接写一些文本到我的打印机。在windows上,我可以使用winapi OpenPrinter和WritePrinter来做到这一点,但我需要这个代码在linux上运行,但我在linux上找不到这个函数OpenPrinter。我知道我可以像这样直接写入linux/dev/usb/lpx文件:
char *dev = "/dev/usb/lp0";
int printerfile = open(dev, O_RDWR | O_NOCTTY | O_NDELAY) ;
if (printerfile < 0)
{
cout << "Failed to open "<<dev;
exit(-1);
}
string str = "test 12345";
write(printerfile,str.c_str(),str.length());
但这需要设备路径,如/dev/usb/lp0,我只能从Qt中获得打印机名称,如EPSON LX-300+。
您可以尝试通过命令
了解更多关于Linux操作系统附加打印机的信息:[udevadm info -q all -n /dev/usb/lp0]
输出如下:
-------------
P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-
1.2:1.0/usbmisc/lp0
N: usb/lp0
E: DEVNAME=/dev/usb/lp0
E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-
1.2:1.0/usbmisc/lp0
E: MAJOR=180
E: MINOR=0
E: SUBSYSTEM=usbmisc
E: UDEV_LOG=3
-------------
相关文章:
- C++ equivalent to Java Map getOrDefault?
- Poco::Net::FTPClientSession 在 open() 方法上挂起 129 秒,如果 ftp 主机不存
- Equivalent of OpenCv c++ api Vec2f,norm, acos in emgucv csha
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- POSIX open() 挂在 SMB 共享上
- Win32 equivalent of getgid
- C++:std::ofstream 方法 open() 在第二次迭代时擦除打开的 ifstream 文件
- Visual Studio "fatal error LNK1104: cannot open file"未使用或包含的库
- vfprintf_unlocked() equivalent?
- C++ 错误检查 fstream open() 命令和一般字符串流错误处理
- What is the std::chrono::time_point equivalent of std::numer
- AVX equivalent for _mm_movelh_ps
- python equivalent of std::chrono::steady_clock::now();
- VS 2017 C++ - "cannot open source file 'sqlite3.h' "
- 在VS 15.7.5中,悬停在Open CV 3.4.1Mat上仍然冻结
- 计算着色器Open GL ES的多个输入
- 从生成文件编译错误:"Unable to open output file" ..."No such file or directory"
- Open GL ES 3.1 的计算着色器的最小工作示例
- C++ Equivalent of Java Map<String, Object>
- TrackPopupMenu equivalent in OS X