http://group.eeworld.net/aawolf_mobile/topic/2aa41dba-eefc-4bc4-8232-ed1191c645b0.aspx
我遇的问题和帖子里面的一样。问题在:CommSend这边没有反应了。代码如下:
(原帖问题解决了但没有给出解决方法。请各路高手帮忙)
//////////////////////////////////////////////////////////////////
public const string DLLName = "SunCf.dll";
[DllImport(DLLName, EntryPoint="CommOpen")]
public static extern int CommOpen(int comNumber);
[DllImport(DLLName,EntryPoint="CommClose")]
public static extern int CommClose();
[DllImport(DLLName,EntryPoint="CommTmOut")]
public static extern int CommTmOut(int count);
[DllImport(DLLName,EntryPoint="CommSend")]
public static extern int CommSend(String function,String data);
[DllImport(DLLName,EntryPoint="CommRece")]
public static extern int CommRece(String function,String data);
private void button1_Click(object sender, EventArgs e)
{
string id = "";
string data = "";
if (CommOpen(6) == 1)
{
CommTmOut(500);
CommSend("A1", "");
if (CommRece(id, data) == 1)
txtId.Text = id + " " + data;
else
{
MessageBox.Show("读取ID失败,请检查设备");
}
CommClose();
}
else
{
MessageBox.Show("PDA端口无法打开");
}
}
设备提供商除了提供这个.dll文件外,还提供了两个.h文件:
////////////////////////////////////////////////////////////////////////////////////////
//
// SunCf.h used for SunCf.dll
//
//
////////////////////////////////////////////////////////////////////////////////////////
extern "C" __declspec(dllexport) int __stdcall CommOpen(int com_number);
extern "C" __declspec(dllexport) int __stdcall CommClose();
extern "C" __declspec(dllexport) int __stdcall CommTmOut(int count);
extern "C" __declspec(dllexport) int __stdcall CommSend(char *function, char *data);
extern "C" __declspec(dllexport) int __stdcall CommRece(char *function, char *data);
/*-------------------------------------------------------
SunCfEVC.h
this header file is used for writing evc program
--------------------------------------------------------*/
#ifndef _SunCfEVC_H
#define _SunCfEVC_H
typedef int (_stdcall pfnCommOpen) (int);
typedef int (_stdcall pfnCommClose) ();
typedef int (_stdcall pfnCommTmOut) (int);
typedef int (_stdcall pfnCommSend) (char *,char *);
typedef int (_stdcall pfnCommRece) (char *,char *);
#endif
//////////////////////////////////
看样子最后问题还是,
从
extern "C" __declspec(dllexport) int __stdcall CommSend(char *function, char *data);
到
CommSend("A1", "");
函数在C#里是这么定义的: [DllImport(SunCf.dll,EntryPoint="CommSend")]
public static extern int CommSend(String function,String data);
参数的问题。要么报NotSupportException,要么就没有反应。其他函数,CommOpen(6);CommClose(); 都是正常的。问题应该在这个参数的问题上。大家给点意见吧!!!