Телесистемы
 Разработка, производство и продажа радиоэлектронной аппаратуры
На главную   | Карта сайта | Пишите нам | В избранное
Требуется программист в Зеленограде
- обработка данных с датчиков; ColdFire; 40 тыс.
e-mail:jobsmp@pochta.ru

Телесистемы | Электроника | Конференция «Микроконтроллеры и их применение»

Ответ: (+)..

Отправлено ETM 31 августа 2007 г. 12:45
В ответ на: Нужен совет имеющих опыт писАния драйверов для самодельных устройств ввода/вывода под Винду (+) отправлено Сидоргек 31 августа 2007 г. 11:15

1. Инсталируешь драйвер или непосредственно грузишь в приложении посредством Сервис-менеджера..
Пример функций работы с CМ:
---------------------------
BOOLEAN InstallDriver(IN SC_HANDLE SchSCManager,IN LPCTSTR DriverName,IN LPCTSTR ServiceExe)
{
SC_HANDLE schService;
DWORD err;
// Create a new a service object.
schService = CreateService(SchSCManager, // handle of service control manager database
DriverName, // address of name of service to start
DriverName, // address of display name
SERVICE_ALL_ACCESS, // type of access to service
SERVICE_KERNEL_DRIVER, // type of service
SERVICE_DEMAND_START, // when to start service
SERVICE_ERROR_NORMAL, // severity if service fails to start
ServiceExe, // address of name of binary file
NULL, // service does not belong to a group
NULL, // no tag requested
NULL, // no dependency names
NULL, // use LocalSystem account
NULL // no password for service account
);

if (schService == NULL) {
err = GetLastError();
if (err == ERROR_SERVICE_EXISTS) {
return TRUE;
} else {
printf("CreateService failed! Error = %d \n", err );
return FALSE;
}
}
// Close the service object.
if (schService) {
CloseServiceHandle(schService);
}
// Indicate success.
return TRUE;
}
BOOLEAN RemoveDriver(IN SC_HANDLE SchSCManager,IN LPCTSTR DriverName)
{
SC_HANDLE schService;
BOOLEAN rCode;
// Open the handle to the existing service.
schService = OpenService(SchSCManager,
DriverName,
SERVICE_ALL_ACCESS
);
if (schService == NULL) {
printf("OpenService failed! Error = %d \n", GetLastError());
return FALSE;
}
// Mark the service for deletion from the service control manager database.
if (DeleteService(schService)) {
rCode = TRUE;
} else {
printf("DeleteService failed! Error = %d \n", GetLastError());
rCode = FALSE;
}
// Close the service object.
if (schService) {
CloseServiceHandle(schService);
}
return rCode;
}

BOOLEAN StartDriver(IN SC_HANDLE SchSCManager,IN LPCTSTR DriverName)
{
SC_HANDLE schService;
DWORD err;
// Open the handle to the existing service.
schService = OpenService(SchSCManager,
DriverName,
SERVICE_ALL_ACCESS
);
if (schService == NULL) {
printf("OpenService failed! Error = %d \n", GetLastError());
return FALSE;
}
// Start the execution of the service (i.e. start the driver).
if (!StartService(schService, // service identifier
0, // number of arguments
NULL // pointer to arguments
)) {
err = GetLastError();
if (err == ERROR_SERVICE_ALREADY_RUNNING) {
return TRUE;
} else {
printf("StartService failure! Error = %d \n", err );
return FALSE;
}
}
// Close the service object.
if (schService) {
CloseServiceHandle(schService);
}
return TRUE;

}

BOOLEAN StopDriver(IN SC_HANDLE SchSCManager,IN LPCTSTR DriverName)
{
BOOLEAN rCode = TRUE;
SC_HANDLE schService;
SERVICE_STATUS serviceStatus;
// Open the handle to the existing service.
schService = OpenService(SchSCManager,
DriverName,
SERVICE_ALL_ACCESS
);

if (schService == NULL) {
printf("OpenService failed! Error = %d \n", GetLastError());
return FALSE;
}
// Request that the service stop.
if (ControlService(schService,
SERVICE_CONTROL_STOP,
&serviceStatus
)) {
rCode = TRUE;
} else {
printf("ControlService failed! Error = %d \n", GetLastError() );
rCode = FALSE;
}
// Close the service object.
if (schService) {
CloseServiceHandle (schService);
}
return rCode;
}

2. Открываешь файл по дескриптору устройства
Например:
---------
devH=CreateFile(
DESCRIPTOR,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
3. Работаешь с файлом посредством
ReadFile(...),
WriteFile(...),
DeviceIoControl(...)



Составить ответ | Вернуться на конференцию

Ответы


Отправка ответа
Имя*: 
Пароль: 
E-mail: 
Тема*:

Сообщение:

Ссылка на URL: 
URL изображения: 

если вы незарегистрированный на форуме пользователь, то
для успешного добавления сообщения заполните поле, как указано ниже:
вычтите из двух единицу:

Перейти к списку ответов | Конференция | Раздел "Электроника" | Главная страница | Карта сайта

Rambler's Top100 Рейтинг@Mail.ru
 
Web telesys.ru