找回密码
 加入
搜索
查看: 5632|回复: 6

求AU3如何直接LPT端口打印或者如何使用VB的CreateObject

[复制链接]
发表于 2009-10-1 23:26:44 | 显示全部楼层 |阅读模式
本帖最后由 honylan 于 2009-10-8 20:59 编辑

目的:打印小票,(热敏pos打印机)
已经测试的方法:1.使用windows API直接打印会出出现错误,不知道怎么回事,windows里的打印会把打印机的纸认为是A4,所以一打印,导致出来一在长条,突突突地走白纸。
(大概猜测原因是需要指定页面大小和纸型)
2.在官方英文论坛上搜到的几个例子,都有问题。

现在无法使用系统的api 那么只好直接将数据发送到LPT端口。VBS可以很简单实现。
set   objfs=CreateObject("Scripting.FileSystemObject")   
  set objprinter=objfs.CreateTextFile ("LPT1:",true)  
  objprinter.Writeline "要打印的行"


现在问题是如何把上述代码转为AU3或者相关的办法。前提是不要写入VBS文件再调用VBS打印。
我想直接用AU3实现。
我看到过许多dllcall等的,不知道能不能实现.
发表于 2009-10-2 00:17:44 | 显示全部楼层

$objfs = ObjCreate("Scripting.FileSystemObject")
$objprinter = $objfs.CreateTextFile("LPT1:", True)
$objprinter.Writeline("要打印的行")
 楼主| 发表于 2009-10-2 19:16:24 | 显示全部楼层
谢谢,马上试一下
发表于 2009-10-2 21:13:35 | 显示全部楼层
前几天网吧也要打印开机小票,,于是写了下面这个

#Region ;**** 参数创建于 AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=1.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Res_Comment=小票打印工具
#AutoIt3Wrapper_Res_Description=小票打印工具--阿宝
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_LegalCopyright=阿宝
#AutoIt3Wrapper_Run_Obfuscator=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <ACN_String.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("小票打印       程序制作:阿宝", 255, 188, 315, 235)
$Label1 = GUICtrlCreateLabel("输入押金:", 16, 64, 55, 17)
$Label2 = GUICtrlCreateLabel("输入机号:", 16, 103, 55, 17)
$Input1 = GUICtrlCreateInput("", 80, 96, 153, 21,$ES_NUMBER)
GUICtrlSetColor(-1, 0x0000FF)
$Label3 = GUICtrlCreateLabel("网吧名称:", 16, 24, 55, 17)
$Button1 = GUICtrlCreateButton("打  印", 80, 144, 65, 25, 0)
$Button2 = GUICtrlCreateButton("退  出", 169, 143, 65, 25, 0)
$Input2 = GUICtrlCreateInput("10", 80, 56, 153, 21)
GUICtrlSetColor(-1, 0x0000FF)
$Input3 = GUICtrlCreateInput(" XX网络会所", 81, 19, 153, 21)
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

HotKeySet ( "{Enter}" , "okk" )
While 1
        $msg= GUIGetMsg()
        Select
        Case $msg=$Button2 or $msg=$GUI_EVENT_CLOSE
   Exit
Case $msg=$Button1
   $time=@MON &"/"& @MDAY & "/"&@HOUR & ":"&@MIN
   $file = FileOpen("pr.txt", 2)
   If $file = -1 Then
    MsgBox(0, "错误", "pr.txt句柄无法打开")
    Exit
   EndIf
$wbnm=GUICtrlRead($Input3)
$yj=GUICtrlRead($Input2)
$jh=GUICtrlRead($Input1)
if $jh=="" Then
        MsgBox(16,"错误","机号不能为空",3)
        exit
        endif
FileWrite($file, $wbnm & @CRLF& @CRLF)
FileWrite($file, "机号:" &$jh& @CRLF)
FileWrite($file, "押金:"&$yj& "元"& @CRLF)
FileWrite($file, $time)
FileClose($file)
ShellExecute("pr.txt", "", @ScriptDir, "print")
exit
  EndSelect
WEnd
exit

Func okk()
ControlClick ( $Form1, "", $Button1)
EndFunc
发表于 2011-3-30 15:28:52 | 显示全部楼层
很不错!!!风格
发表于 2012-5-17 14:05:08 | 显示全部楼层
#include <EditConstants.au3>
发表于 2014-7-17 15:52:56 | 显示全部楼层
多谢,正好测试下!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 06:19 , Processed in 0.233042 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表