【发布时间】:2015-06-29 06:59:00
【问题描述】:
该软件已经为 Windows 编写。我在想什么是在 Linux 中编写它的好方法。直接在 Linux 中或更改 Windows 代码。
案例示例是 National Instruments 的 MCA 8000A 驱动程序here,许多人尝试为 Linux 编写但未成功,例如 here,因为当时嵌入更好,应用程序所需的硬件更少,最终目标是 Raspberry Pi here。
我开始通过将 Windows 文件转换为 Linux 来编写它,但我不确定这是否是好方法。
作者在 MCA 8000A 中使用了一些 Linux 驱动程序变体
适用于 Raspberry Pi 的 MCA 8000A Linux 驱动程序计划
以下代码来自 API 中记录的第一个链接。
他们的 Pmcatest.cpp
#include <windows.h> // Change
#include <stdio.h>
#include "PmcaCom.h"
#include "PmcaErr.h"
static int g_port;
static int g_baudRate;
static int g_gain;
static int g_scale;
static PmcaDeviceType g_device;
static PmcaFlagsType g_flags;
static PmcaStatusType g_status;
static char chBuff[32];
static unsigned long buff[16384];
#define MAX_MEMORY 32768
#define printf0(format) printf(format); fflush(stdout)
#define printf1(format, item) printf(format, item); fflush(stdout)
// command line: test <com port> <baud rate> <device type> <start gain>
// device type 0 - AUTO DETECT, 1 - PMCA 8000, 2 - PMCA 8000A
int main(int argc, char *argv[])
{
...
}
MicroTime.cpp
#if !defined(AFX_MICROTIME_H__495147C7_F0B7_11D1_B62F_9CFF0CC10000__INCLUDED_)
#define AFX_MICROTIME_H__495147C7_F0B7_11D1_B62F_9CFF0CC10000__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
class MicroTimeType
{
LARGE_INTEGER m_startTime;
...
public:
MicroTimeType();
LARGE_INTEGER GetCounter();
...
};
#endif // !defined(AFX_MICROTIME_H__495147C7_F0B7_11D1_B62F_9CFF0CC10000__INCLUDED_)
队列.cpp
#include "windows.h"
#include "Queue.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
QueueType::QueueType()
{
...
}
long QueueType::Put(QueueEntryType *entry)
{
...
}
QueueEntryType *QueueType::Get(void)
{
...
}
QueueEntryType *QueueType::LockedFind(long id)
{
...
}
QueueEntryType *QueueType::Remove(long id)
{
...
}
Windows 配置的其他代码
- Pmcaex.cpp
- Request.cpp
如何在 MCA 8000A 中编写 Linux 驱动程序?
【问题讨论】:
-
如果您相当熟悉 Windows API 并熟悉 Linux API,那么使用 Windows 应用程序作为 Linux 应用程序的基础是合理的。这完全取决于你的能力和经验。据我所知,该设备只是一个串行端口设备,因此生成一个可以工作的接口应该不难(不,我没有提供帮助!)