📄 phantomeppsrl.c
字号:
//////////////////////////////////////////////////////////////////
//
// PhantomEPPSRL.c - C file
//
// This file was generated using the RTX Device Driver Wizard.
//
//////////////////////////////////////////////////////////////////
#include "PhantomEPPSrl.h"
#include "PhantomEPPSrlAPI.h"
#include "RtDriver.h"
#define NO_ERRORS 0
#define ERROR_OCCURED -1
//
//Global Variables
//
UCB ucb;
HANDLE hDriver;
RINGBUFFER receiveRingBuffer;
RINGBUFFER transmitRingBuffer;
//
// MsgAndExit: Output error message and terminate the program
// with exit code 1.
//
void
MsgAndExit(
wchar_t *msg //input: message to print to screen
)
{
RtWprintf(L"Error: %s (0x%X)\n", msg, RtGetLastError());
RtExitProcess(1);
}
//
// Main: Opens a Parallel port, reads and writes to the Parallel port
// and then Closes the Parallel port
//
int
_cdecl
wmain (
int argc,
wchar_t **argv,
wchar_t **envp
)
{
DWORD status;
ULONG StackSize = 0; //default stack size
DWORD dwFlags = 0; // No flags
hDriver = NULL;
//
// Setup UART Control Block
//
ucb.baseAddress = ( PUCHAR )EPP_PORT;// base port address
ucb.istHandle = NULL; // handle to interrupt service thread
ucb.intVector = 0x0c; // interrupt vector
ucb.irq = EPP_IRQ; // IRQ level
ucb.inBuffer = &receiveRingBuffer; // pointer to input ringbuffer
ucb.outBuffer = &transmitRingBuffer;// pointer to output ringbuffer
ucb.fifoSize = FIFO_SIZE; // size of FIFO
ucb.receiveISTActive = 0; // receive interrupt pending
ucb.transmitISTActive = 0; // transmit Interrupt pending
ucb.flowControl = 0; // flow control
ucb.lastError = 0; // last reported error
ucb.errorCount = 0; // count of errors
ucb.m_DeviceNumber = 0;
ucb.m_DeviceIndex = 0;
ucb.m_nFileCount = 0;
ucb.m_SignalEventHandle = NULL;
ucb.m_SignalEventObject = NULL;
ucb.m_SignalEventCount = 0;
ucb.m_SoftwareTimerEnabled = FALSE;
ucb.m_SoftwareTimer = NULL;
ucb.m_SoftwareTimerDPC = NULL;
ucb.m_ParPortAllocated = FALSE;
ucb.m_ParPortInterruptAllocated = FALSE;
ucb.m_PPT_BYTE_PRESENT = FALSE;
ucb.m_PPT_1284_3_PRESENT = FALSE;
ucb.m_PPT_ECP_PRESENT = FALSE;
ucb.m_PPT_EPP_32_PRESENT = FALSE;
ucb.m_PPT_EPP_PRESENT = FALSE;
ucb.m_RegistryEnableInterruptsChanged = FALSE;
ucb.m_ChannelMask = 0;
ucb.m_EnableSoftwareWatchdog = FALSE;
ucb.m_TimeoutTimer = NULL;
ucb.m_TimeoutDPC = NULL;
ucb.m_TimeoutEvent = NULL;
ucb.m_TimeoutCount = FALSE;
ucb.m_IsClose = TRUE;
status = STATUS_SUCCESS;
//
// Setup create parallel port for use
//
status = DriverCreateDevice();
if( status != STATUS_SUCCESS )
{
MsgAndExit( L"Failed to open Parallel port" );
}
//
// Register the driver.
//
hDriver = RtdDriverRegister(
"\\RtDevice\\PhantomEPP", // Driver name
DriverDeviceControl, // Dispatch routine
StackSize,
RT_PRIORITY_MAX - 6, // Dispatch thread priority
RTD_MAX_BUFFFER, // Maximum buffer size
dwFlags
);
if (hDriver==NULL)
{
//printf("Failed to register PhantomEPP driver (error=%d).\n", GetLastError());
//if (GetLastError() == ERROR_ALREADY_EXISTS)
// printf("Driver by this name is already loaded.\n");
return ERROR_OCCURED;
}
//
// Suspend this thread forever (wait for the driver to be killed). On other
// drivers this thread could perform asynchronous background processing, or
// wait for some notification to unload and then use the RtdDriverUnregister
// function.
//
// NOTE: The driver library is structured so that when applications or drivers
// terminate without calling close or unregister, the system will cleanup
// all IPC objects.
//
for (;;)
SuspendThread( GetCurrentThread());
return NO_ERRORS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -