Hello;
I want to access to printer port/parallel port in a windows machine.
I am trying to use the unsafe package to write/read at the LPT1 to 3 addresses
const (
// Physical addresses of Parallel port
LTP1_BASE = 0x00000408
LTP2_BASE = 0x0000040A
LTP3_BASE = 0x0000040C
LTP4_BASE = 0x0000040E
// Physical addresses of Parallel port
LTP1_ADDRESS = 0x0378
LTP2_ADDRESS = 0x0278
// Where to read/write the data (I/O)
LTP1_DATAPORT = LTP1_BASE + 0x0
LTP2_DATAPORT = LTP2_BASE + 0x0
LTP3_DATAPORT = LTP3_BASE + 0x0
LTP4_DATAPORT = LTP4_BASE + 0x0
// Status of the port (Read ONLY)
LTP1_STATUS = LTP1_BASE + 0x1
LTP2_STATUS = LTP2_BASE + 0x1
LTP3_STATUS = LTP3_BASE + 0x1
LTP4_STATUS = LTP4_BASE + 0x1
// Control Port (I/O)
LTP1_CONTROL = LTP1_BASE + 0x2
LTP2_CONTROL = LTP2_BASE + 0x2
LTP3_CONTROL = LTP3_BASE + 0x2
LTP4_CONTROL = LTP4_BASE + 0x2
)
I have trouble to convert this integers to unsafe pointers
lpt_data = []*uint32{
(*uint32)(unsafe.Pointer(LTP1_DATAPORT)),
(*uint32)(unsafe.Pointer(LTP2_DATAPORT)),
(*uint32)(unsafe.Pointer(LTP3_DATAPORT)),
(*uint32)(unsafe.Pointer(LTP4_DATAPORT)),
}
package main
import ( "fmt" "syscall" "unicode/utf16")
func main() { fmt.Println("Hello World!")
InpOutDll, err := syscall.LoadLibrary("inpoutx64.dll") if err != nil { fmt.Println("Error Loading inpout64 dll, ", err) } defer func() { syscall.FreeLibrary(InpOutDll) }()
PAddressOut32, err := syscall.GetProcAddress(syscall.Handle(InpOutDll), "Out32") if err != nil { fmt.Println("Error getting ProcAdress Out32, ", err) } PAddressInp32, err := syscall.GetProcAddress(syscall.Handle(InpOutDll), "Inp32") if err != nil { fmt.Println("Error getting ProcAdress Inp32, ", err) } //Returns TRUE if the InpOut driver was opened successfully IsInpOutDriverOpen, err := syscall.GetProcAddress(syscall.Handle(InpOutDll), "IsInpOutDriverOpen") if err != nil { fmt.Println("Error getting ProcAdress IsInpOutDriverOpen, ", err) }
IsOpen, _, callErr := syscall.Syscall(uintptr(IsInpOutDriverOpen), 0, 0, 0, 0) if callErr != 0 { fmt.Println("Error in ProcAdress IsInpOutDriverOpen! ", callErr) }
if uint16(IsOpen) == 1 { _, _, callErr := syscall.Syscall(uintptr(PAddressOut32), 1, uintptr(890), uintptr(0), 0) if callErr != 0 { fmt.Println("Error in LTP Write! ", callErr) } Word, _, callErr := syscall.Syscall(uintptr(PAddressInp32), 0, uintptr(890), 0, 0) if callErr != 0 { fmt.Println("Error in LTP Read! ", callErr) } else { fmt.Println("Data in is ", Word)
} } else { fmt.Println("InpOut driver wasn't opened successfully!") }}