请教c#串口通信问题
请高手指点,现在做一个中考报名读卡的程序,用到五岳鑫公司的omr读卡机,公司提供了一个dll,调用其中的方法读卡,c#该怎么从其中读取数据呢?我是初学者,读取数据时,总是出错,请叫高手指点。我[DllImport("omrvfapi.dll")] //调用非托管的dll
static extern short OMR_Initialize(string nComNo, long nBaudRate);
[DllImport("omrvfapi.dll")]
static extern short OMR_LoadFmtFile(string filename);
[DllImport("omrvfapi.dll")]
static extern void OMR_ClrFmtBuf();
[DllImport("omrvfapi.dll")]
static extern void OMR_Exit();
[DllImport("omrvfapi.dll")]
static extern void OMR_StartReadPaper(int mode);
[DllImport("omrvfapi.dll")]
static extern int OMR_GetReadResult();
[DllImport("omrvfapi.dll")]
static extern void OMR_StopReadPaper();
[DllImport("omrvfapi.dll")]
static extern int OMR_GetResultString(ref string buffer);
[DllImport("omrvfapi.dll")]
static extern int OMR_GetLastError();
[DllImport("omrvfapi.dll")]
static extern void OMR_GetErrorString(int errno, ref string buf);
[DllImport("omrvfapi.dll")]
static extern int OMR_SetShiftValue(int value);
[DllImport("omrvfapi.dll")]
static extern int OMR_GetShiftValue();
[DllImport("omrvfapi.dll")]
static extern int OMR_SetLocValue(int vlue);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string ls_port=this.comboBox1.Text.Trim();
int ll_baud = Convert.ToInt32(this.textBox1.Text.Trim());
int li_result = OMR_Initialize(ls_port, ll_baud);
if (li_result < 0)
{
MessageBox.Show("初始化失败", "错误", MessageBoxButtons.OK);
return;
}
OMR_ClrFmtBuf();
string ls_fmtfile = this.textBox2.Text.Trim();
if ((OMR_LoadFmtFile(ls_fmtfile)) <= 0)
{
MessageBox.Show("装载格式描述文件错误!", "OMR 系统信信息错误",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
OMR_SetShiftValue(9);
OMR_StartReadPaper(0); //mode=0 正常走纸; mode=1 快速走纸;
while (readstatus == "reading")
{
int ET_CODE = OMR_GetReadResult();
if (ET_CODE == 0)
continue;
else if (ET_CODE == 1)
{
string ls_result = new string(' ', 2048);
int length = OMR_GetResultString(ref ls_result);
//string result=ls_result.ToString();
string result1 = ls_result.Substring(1, length);
//***-------在以下位置添加读入结果的处理代码------***
textBox3.AppendText(result1);
//***-------在以上位置添加读入结果的处理代码------***
OMR_StartReadPaper(0);
}
}
--------------------编程问答-------------------- --------------------编程问答-------------------- 能说的详细点吗
补充:.NET技术 , C#