资源描述:
《实现真空荧光屏VFD的显示》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实现真空荧光屏VFD的显示最近接到一个工作任务,就是在Windows平台,通过写串口的方式,实现真空荧光屏VFD的显示。VFD是通过淘宝购来的,随产品附来的只有一份显示屏规格说明及保修卡。如果要写程序实现VFD显示,需要参照产品指令说明。以下是部分指令的说明。第一步:选定需要使用的指令类型。在我的代码里,使用的是EPSONPOS指令类型。相应代码段:BOOLfState;BYTESendBuffer[256];DWORDWrittenLen;SendBuffer[0]=0x01;//CommandType:01-EPSONPOSfState=Write
2、File(m_hCom,(void*)SendBuffer,1,&WrittenLen,NULL);第二步:发送清屏、定位及显示字串等命令。清屏代码段:SendBuffer[0]=0x0C;//0x0C-CleardisplayscreenfState=WriteFile(m_hCom,(void*)SendBuffer,1,&WrittenLen,NULL);清屏代码段:/*[1F24xy]:Movecursortospecifiedposition1≦x(column)≦;1≦y(row)≦*/BYTEposi[16]={0};posi[0]=0x
3、1F;posi[1]=0x24;posi[2]=0x01;posi[3]=0x01;fState=WriteFile(m_hCom,(void*)posi,4,&WrittenLen,NULL);显示字串的代码段memset(SendBuffer,0,sizeof(SendBuffer));if(bCashBox){sprintf((char*)SendBuffer,"Total:");nNumberOfBytes=6;}else{if(bUpdateSubTotal){if(giProductListNum==0){sprintf((char*)Se
4、ndBuffer,"");nNumberOfBytes=0;}else{sprintf((char*)SendBuffer,"SubTotal:");nNumberOfBytes=9;}}else{sprintf((char*)SendBuffer,"Total:");nNumberOfBytes=6;}}if(nNumberOfBytes!=0){fState=WriteFile(m_hCom,(void*)&SendBuffer,nNumberOfBytes,&WrittenLen,NULL);if(!fState)break;}以下是完整功能函数
5、。voidCPosDemoDlgMain::UpdateSubDisp(BOOLbUpdateSubTotal,BOOLbCashBox){BOOLResult=FALSE,fState;volatileHANDLEm_hCom=NULL;//串口句柄COMMTIMEOUTStimeOuts;COMSTATcomState;DCBdcb;BYTESendBuffer[256],posi[16]={0};DWORDWrittenLen,dwErrorFlags;intlen,x,nNumberOfBytes;while(1){//OpenCOMport.
6、m_hCom=CreateFile(gComPortID2,GENERIC_READ
7、GENERIC_WRITE,//enablereadandwrite0,//独占方式NULL,OPEN_EXISTING,//打开而不是创建0,//FILE_ATTRIBUTE_NORMAL
8、FILE_FLAG_OVERLAPPED,//重叠方式NULL);if(m_hCom==INVALID_HANDLE_VALUE)break;SetupComm(m_hCom,2048,2048);//Settimeout.timeOuts.ReadIntervalTimeout
9、=1000;timeOuts.ReadTotalTimeoutMultiplier=500;timeOuts.ReadTotalTimeoutConstant=5000;timeOuts.WriteTotalTimeoutMultiplier=500;timeOuts.WriteTotalTimeoutConstant=5000;if(!SetCommTimeouts(m_hCom,&timeOuts))break;//设置传输参数if(!GetCommState(m_hCom,&dcb))//getparabreak;dcb.BaudRate=_wt
10、ol(gComBaudRate2);dcb.ByteSize=_wtoi(gComDataBi