使用VB.Net 打开钱箱

本文介绍了一种通过特定命令控制钱箱开启的方法,并提供了两种实现途径:一种是使用 C# 进行串口通信直接发送命令,另一种是通过文件打印的方式间接发送指令。文章详细解释了命令格式及其参数意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



        
'****打开钱箱控制命令说明**************************************
        'ESC   p   m   t1   t2   钱箱命令   
        '格式:   ASCII:ESC   p   m   t1   t2   
        '     十进制:27   112   m   t1   t2   
        '   十六进制:1B   70   m   t1   t2   
        '说明:
        '    在钱箱连接器上输出由t1,t2决定的钱箱开启脉冲,要求t2≥t1。   
        '    m=0,48   在钱箱pin2上输出。   
        '    m=1,49   在钱箱pin5上输出。   
        '注意:
        '   开启时间为t1*2ms   
        '   关断时间为t2*2ms   
        '   如果t2<t1,打印机处理t2=t1×2ms;   
        '   如果t2<50,打印机内部将t2设为50。
        '*************************************************************

 

方式1:

Option Strict Off
Option Explicit On
Imports System.IO
Imports System.Runtime.InteropServices

Friend Class Form1
    
Inherits System.Windows.Forms.Form

    
Public Const GENERIC_WRITE = &H40000000
    
Public Const OPEN_EXISTING = 3
    
Public Const FILE_SHARE_WRITE = &H2

    
Dim LPTPORT As String
    
Dim hPort As Integer

    
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _
    
ByVal lpFileName As StringByVal dwDesiredAccess As Integer, _
    
ByVal dwShareMode As Integer, _
    
<MarshalAs(UnmanagedType.Struct)> ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
    
ByVal dwCreationDisposition As IntegerByVal dwFlagsAndAttributes As Integer, _
    
ByVal hTemplateFile As IntegerAs Integer

    
Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As IntegerAs Integer
    
Dim retval As Integer
    
<StructLayout(LayoutKind.Sequential)> Public Structure SECURITY_ATTRIBUTES
        
Private nLength As Integer
        
Private lpSecurityDescriptor As Integer
        
Private bInheritHandle As Integer
    
End Structure


    
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles  Command1.Click
        
Dim SA As SECURITY_ATTRIBUTES
        
Dim outFile As FileStream, hPortP As IntPtr

        LPTPORT 
= "LPT1"
        hPort 
= CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 00)

        hPortP 
= New IntPtr(hPort) 'convert Integer to IntPtr 
        outFile = New FileStream(hPortP, FileAccess.Write) 'Create FileStream using Handle 

        
Dim fileWriter As New StreamWriter(outFile)
        fileWriter.Write(
Chr(7))
        fileWriter.Flush()
        fileWriter.Close()
        outFile.Close()
        retval 
= CloseHandle(hPort)
    
End Sub

End Class

 

方式2:

            Dim intFileNo As Integer = FreeFile()
            
FileOpen(1"c:escapes.txt", OpenMode.Output)
            
PrintLine(1Chr(27& "p" & Chr(0& Chr(25& Chr(250))
            
FileClose(1)
            
Shell("print /d:COM1 c:escapes.txt", vbNormalFocus)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值