drv_prn.bas.bak
来自「VB代码」· BAK 代码 · 共 634 行 · 第 1/2 页
BAK
634 行
Attribute VB_Name = "Driver_PrintPort"
Option Explicit
Const c_Mode_EraseChip = &H1
Const c_Mode_WritePGMCode = &H2
Const c_Mode_ReadPGMCode = &H3
Const c_Mode_ReadSignature = &H4
Const c_Mode_LockBit1 = &H5
Const c_Mode_LockBit2 = &H6
Const c_MaxCodeLength = &H800
Dim ucPrintDataPortMemImage As Byte
Dim ucPrintControlPortMemImage As Byte
Dim iCurrentPrintBaseAddress As Integer
Public ucDataBuff(0 To c_MaxCodeLength) As Byte
'Inp and Out declarations for direct port I/O
'in 32-bit Visual Basic 4 programs.
'直接操纵IO口的API函数的说明。
Public Declare Function Inp Lib "inpout32.dll" _
Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib "inpout32.dll" _
Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
'STDZ 制作 2006-12-16
'对底层IO控制的驱动程序进行封装。
'功能介绍:读取IO口1字节
'入口参数:IO端口地址
'返回: 读取到的字节数据。
Public Function InPortByte(ByVal PortAddress As Integer) As Byte
InPortByte = CByte(Inp(PortAddress))
End Function
'功能介绍:写IO口1字节
'入口参数:IO端口地址,待写入端口的1字节数据。
'返回: 读取到的字节数据。
Public Function OutPortByte(ByVal PortAddress As Integer, ByVal ucWriteData As Byte) As Boolean
Dim bReturnResult As Boolean
Call Out(PortAddress, CInt(ucWriteData))
bReturnResult = True
OutPortByte = bReturnResult
End Function
'对PC机打印机口进行控制的底层驱动
'功能介绍:设定当前应用的打印机端口的IO基地址
'入口参数 打印机端口的IO基地址。
'返回: 无
Public Function SetPrintPortBaseAddress(ByVal iPrintPortBaseAddr As Integer) As Boolean
iCurrentPrintBaseAddress = iPrintPortBaseAddr
SetPrintPortBaseAddress = True
End Function
'功能介绍:写1字节数据到打印机的数据口
'入口参数 待写入端口的1字节数据。
'返回: 无
Public Function WriteData_PrintDataPort(ByVal ucWrData As Byte) As Boolean
Dim bReturnValue As Boolean
bReturnValue = OutPortByte(iCurrentPrintBaseAddress, ucWrData)
WriteData_PrintDataPort = bReturnValue
End Function
'功能介绍:写1字节数据到打印机的控制口
'入口参数 待写入端口的1字节数据。
'返回: 无
Public Function WriteData_PrintControlPort(ByVal ucWrData As Byte) As Boolean
Dim bReturnValue As Boolean
bReturnValue = OutPortByte(iCurrentPrintBaseAddress + 2, ucWrData)
WriteData_PrintControlPort = bReturnValue
End Function
'功能介绍:从打印机状态端口读1字节数据
'入口参数 无。
'返回: 读取到的当前状态端口的数据。
Public Function ReadData_PrintStatusPort() As Byte
Dim ucReturnValue As Byte
ucReturnValue = InPortByte(iCurrentPrintBaseAddress + 1)
ReadData_PrintStatusPort = ucReturnValue
End Function
'EPP打印端口扩展应用
'
'
'面向应用的打印机端口控制与状态线操作
'以下是为ST_2051编程器进行的封装。
Public Function InitST2051ProgramDevice() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = &H0
ucPrintControlPortMemImage = &H0B
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
InitST2051ProgramDevice = True
End Function
Public Function ST2051PGM_LoadVpp() As Boolean
Dim bReturnValue As Boolean
ucPrintControlPortMemImage = ucPrintControlPortMemImage And &HFD
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
ST2051PGM_LoadVpp = bReturnValue
End Function
Public Function ST2051PGM_Load5V() As Boolean
Dim bReturnValue As Boolean
ucPrintControlPortMemImage = ucPrintControlPortMemImage And &HFE
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
ST2051PGM_Load5V = bReturnValue
End Function
Public Function ST2051PGM_CloseVpp() As Boolean
Dim bReturnValue As Boolean
ucPrintControlPortMemImage = ucPrintControlPortMemImage Or &H2
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
ST2051PGM_CloseVpp = bReturnValue
End Function
Public Function ST2051PGM_Close5V() As Boolean
Dim bReturnValue As Boolean
ucPrintControlPortMemImage = ucPrintControlPortMemImage Or &H1
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
ST2051PGM_Close5V = bReturnValue
End Function
Function ST2051PGM_SetP33Low() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HEF
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
ST2051PGM_SetP33Low = bReturnValue
End Function
Function ST2051PGM_SetP33High() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H10
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
ST2051PGM_SetP33High = bReturnValue
End Function
Function ST2051PGM_SetP34Low() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HDF
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
ST2051PGM_SetP34Low = bReturnValue
End Function
Function ST2051PGM_SetP34High() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H20
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
ST2051PGM_SetP34High = bReturnValue
End Function
Function ST2051PGM_SetP35Low() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = ucPrintDataPortMemImage And &HBF
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
ST2051PGM_SetP35Low = bReturnValue
End Function
Function ST2051PGM_SetP35High() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H40
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
ST2051PGM_SetP35High = bReturnValue
End Function
Function ST2051PGM_SetP37Low() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = ucPrintDataPortMemImage And &H7F
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
ST2051PGM_SetP37Low = bReturnValue
End Function
Function ST2051PGM_SetP37High() As Boolean
Dim bReturnValue As Boolean
ucPrintDataPortMemImage = ucPrintDataPortMemImage Or &H80
bReturnValue = WriteData_PrintDataPort(ucPrintDataPortMemImage)
ST2051PGM_SetP37High = bReturnValue
End Function
Sub SelectWorkMode(ByVal ucSelectMode As Byte)
Dim bReturnValue As Boolean
Select Case (ucSelectMode)
Case c_Mode_WritePGMCode
bReturnValue = ST2051PGM_SetP33Low()
bReturnValue = ST2051PGM_SetP34High()
bReturnValue = ST2051PGM_SetP35High()
bReturnValue = ST2051PGM_SetP37High()
Case c_Mode_ReadPGMCode
bReturnValue = ST2051PGM_SetP33Low()
bReturnValue = ST2051PGM_SetP34Low()
bReturnValue = ST2051PGM_SetP35High()
bReturnValue = ST2051PGM_SetP37High()
Case c_Mode_LockBit1
bReturnValue = ST2051PGM_SetP33High()
bReturnValue = ST2051PGM_SetP34High()
bReturnValue = ST2051PGM_SetP35High()
bReturnValue = ST2051PGM_SetP37High()
Case c_Mode_LockBit2
bReturnValue = ST2051PGM_SetP33High()
bReturnValue = ST2051PGM_SetP34High()
bReturnValue = ST2051PGM_SetP35Low()
bReturnValue = ST2051PGM_SetP37Low()
Case c_Mode_EraseChip
bReturnValue = ST2051PGM_SetP33High()
bReturnValue = ST2051PGM_SetP34Low()
bReturnValue = ST2051PGM_SetP35Low()
bReturnValue = ST2051PGM_SetP37Low()
Case c_Mode_ReadSignature
bReturnValue = ST2051PGM_SetP33Low()
bReturnValue = ST2051PGM_SetP34Low()
bReturnValue = ST2051PGM_SetP35Low()
bReturnValue = ST2051PGM_SetP37Low()
End Select
End Sub
Function ST2051PGM_SetP32High() As Boolean
Dim bReturnValue As Boolean
ucPrintControlPortMemImage = ucPrintControlPortMemImage And &HF7
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
ST2051PGM_SetP32High = bReturnValue
End Function
Function ST2051PGM_SetP32Low() As Boolean
Dim bReturnValue As Boolean
ucPrintControlPortMemImage = ucPrintControlPortMemImage Or &H8
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
ST2051PGM_SetP32Low = bReturnValue
End Function
'XTAL1与/INT线相连。
Function ST2051PGM_SetXTAL1Low() As Boolean
Dim bReturnValue As Boolean
ucPrintControlPortMemImage = ucPrintControlPortMemImage And &HFB
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
ST2051PGM_SetXTAL1Low = bReturnValue
End Function
Function ST2051PGM_SetXTAL1High() As Boolean
Dim bReturnValue As Boolean
ucPrintControlPortMemImage = ucPrintControlPortMemImage Or &H4
bReturnValue = WriteData_PrintControlPort(ucPrintControlPortMemImage)
ST2051PGM_SetXTAL1High = bReturnValue
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?