我在vs2005开发的串口程序放到wince5.0上出现如下错误请问是怎么回事?
Data Abort: Thread=838cf520 Proc=82326340 'device.exe'
AKY=00000405 PC=02a91b5c(serial_smdk2440.dll+0x00001b5c) RA=02a9450c(serial_smdk2440.dll+0x0000450c) BVA=06000000 FSR=00000007
RaiseException: Thread=838cf520 Proc=82326340 'device.exe'
AKY=00000405 PC=03f8dfec(coredll.dll+0x0001dfec) RA=802d6038(NK.EXE+0x000d6038) BVA=00000001 FSR=00000001
你调用ReadFile、WriteFile函数读写串口设备时
BOOL ReadFile(
HANDLE hFile,
LPVOID lpBuffer, //必须是有效的指针
DWORD nNumberOfBytesToRead, //必须是有效的大小
LPDWORD lpNumberOfBytesRead, //必须是有效的DWORD变量地址
LPOVERLAPPED lpOverlapped
);
WriteFile、DeviceIoControl函数也是。
我做了form界面用button打开串口就会出现上面的问题,我button程序如下:
private void button2_Click(object sender, EventArgs e)
{
if (!PortOpen)
{
if (Serial.OpenPort("COM1:", 115200, 0, 8, 1))
{
PortOpen = true;
Receive = true;
ThreadPool.QueueUserWorkItem(new WaitCallback(SerialReceive), 0);
button2.Text = "关闭";
}
}
else
{
Receive = false;
Serial.ClosePort();
PortOpen = false;
button2.Text = "打开";
}
}
public void SerialReceive(Object a)
{
byte[] buf;
buf = new byte[1];
int bytesRead = 0;
int i;
while (Receive)
{
if (Serial.Opened)
{
bytesRead = Serial.ReadPort(1, buf);
if (bytesRead > 0)
{
for (i = 0; i < bytesRead; i++)
{
textBoxReceive.Text += Convert.ToChar(buf).ToString();
}
}
Application.DoEvents();
}
}
Thread.Sleep(0);
}
希望高手帮帮忙,请问还需要提供什么?
hComm = CreateFile(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
中的GENERIC_READ 和 GENERIC_WRITE怎么设置常量,应该设为多少?
谢谢我已经解决该问题,如何用vs2005编写串口接收函数???
请问一下你这个问题是怎么解决的,我也遇到同样的问题,谢谢