数据格式为:1位起始位+8位数据位+1位校验位(当发送地址为1,命令为0)+1停止位
那为大哥给个例子谢谢!
上次的100分已经结帐,可是我还是不明白,咳....
那为大哥给个例子谢谢!
上次的100分已经结帐,可是我还是不明白,咳....
解决方案 »
- VC++使用NTKO文档组件的问题
- 关于dll源代码中对文件操作的问题
- 在线等待:OLE程序初始化失败,请确认OLE库版本是否正确.
- 十万火急!!区域选择 我是菜鸟,请大侠多多指教啊!
- 把IE里的一个url超链接拖到自己窗口里,如何知道这个赵链接的url?
- vs2008里用MFC开发网页控制程序,用了webbrowser控件为什么没有GetDocument()方法
- 运行时出错 0x7c812afb 处未处理的异常: Microsoft C++ 异常: 内存位置 0x0011f194 处的 cv::Exception。
- 如果更改CButton的背景色,SetBkColor没起作用
- 这样的错误如何解决?大家帮忙!
- 请问:在学习ATL之前,有没有必要对MFC有很深的了解?
- 帮助
- 何如广播ASF文件啊,不使用编码嚣和徵软的MEDIA SERVER
unsigned short _inpw( unsigned short port );port:Port numberRequired Header:<conio.h>将得到的结果(0x1111111111111)移位分解即可
int PASCAL in_data(int com_port)
{
int c;
do {
c = _inp(com_port + 5);
if (c & 1) {return _inp(com_port);}
} while (c & 1);
}
出错提示:
warning C4715: 'in_data' : not all control paths return a value
那为大哥指点一二吧!
(这两个函数事实上在NT的环境下不支持)。
我还真没学过C,你能帮我该一下吗(不好意思)。
98440622(都是VC惹的祸) :能给我个用createfile和read/writefile的程序吗?Email:[email protected]
谢谢!
我个人认为用_inp好些,不过用Createfile方式也行,方便!
一段Createfile方式的代码
:com=CreateFile(portname,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(fcom==INVALID_HANDLE_VALUE)
{
dwError=GetLastError();
//return dwError;
}
GetCommState(fcom,&dcb);
switch(portsetting){
case 0:
dcb.BaudRate=4800;
break;
case 1:
dcb.BaudRate=9600;
break;
case 2:
dcb.BaudRate=19200;
break;
case 3:
dcb.BaudRate=38400;
break;
default:
dcb.BaudRate=9600;
break;
}
dcb.Parity='n';
dcb.ByteSize=8;
dcb.StopBits=1;
SetCommState(fcom,&dcb);
GetCommTimeouts(fcom,&cto);
cto.ReadIntervalTimeout=20;
cto.ReadTotalTimeoutConstant=20;
cto.ReadTotalTimeoutMultiplier=200;
cto.WriteTotalTimeoutConstant=0;
cto.WriteTotalTimeoutMultiplier=0;
SetCommTimeouts(fcom,&cto);
//写端口
if(WriteFile(fcom,"\x1b\x40\x1c\x26",4,&dw,NULL)==0){//写失败
CloseHandle(fcom);
ret=Get_Status(NULL,portname,portsetting);
if(ret)
return -2;
else return -1;
}
if(WriteFile(fcom,printdata,strlen(printdata),&dw,NULL)==0){//写失败
CloseHandle(fcom);
ret=Get_Status(NULL,portname,portsetting);
if(ret)
return -2;
else return -1;
}
if(dw!=strlen(printdata)){
CloseHandle(fcom);
return -3;
int PASCAL in_data(int com_port)
{
int c;
do {
c = _inp(com_port + 5);
if (c & 1) {return _inp(com_port);}
} while (c & 1);
return 1;
}
加一个返回值就不会有WARING了,
还有_inp不能在NT和2000下使用,并且这个不是用来编串口程序的!
但是如果用Createfile能对8250A(串口芯片)的寄存器设置吗,例如如果你和单片机用方式三通信,就需要把COM1(1016/0X3F8)+3(LCR)
但是如果用Createfile能对8250A(串口芯片)的寄存器设置吗,例如如果你和单片机用方式三通信,就需要把COM1(1016/0X3F8)+3(LCR寄存器)的Bits 3, 4 ,5位进行设置(当发送地址是设为:101;其它为:111)。
另外用_inp()接收数据时,当你的发送数据大于127(小于255)时,得到是一个负数,因为这时候最高位为1,这也让我很麻烦,需要在程序中判断,如果小于0,则加2,不知有什么简单的方法?
另外在编译DLL的时候出现:
Creating library Release/com.lib and object Release/com.exp
LINK : warning LNK4089: all references to "SHELL32.dll" discarded by /OPT:REF
LINK : warning LNK4089: all references to "comdlg32.dll" discarded by /OPT:REFcom.dll - 0 error(s), 2 warning(s)
在DEBUG下不会出现。