版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、實(shí)現(xiàn)真空熒光屏VFD的顯示最近接到一個(gè)工作任務(wù),就是在Windows平臺(tái),通過(guò)寫(xiě)串口的方式,實(shí)現(xiàn)真空熒光屏VFD的顯示。VFD是通過(guò)淘寶購(gòu)來(lái)的,隨產(chǎn)品附來(lái)的只有一份顯示屏規(guī)格說(shuō)明及保修卡。如果要寫(xiě)程序?qū)崿F(xiàn)VFD顯示,需要參照產(chǎn)品指令說(shuō)明。以下是部分指令的說(shuō)明。第一步:選定需要使用的指令類(lèi)型。在我的代碼里,使用的是EPSON POS指令類(lèi)型。相應(yīng)代碼段:BOOL fState;BYTE SendBuffer256;DWORD WrittenLen;SendBuffer0 = 0x01; /Command Type: 01 - EPSON POSfState = WriteFile(m_hCom,
2、 (void*)SendBuffer, 1, &WrittenLen, NULL);第二步:發(fā)送清屏、定位及顯示字串等命令。清屏代碼段:SendBuffer0 = 0x0C; /0x0C - Clear display screen fState = WriteFile(m_hCom, (void*)SendBuffer, 1, &WrittenLen, NULL);清屏代碼段:/* 1F 24 x y : Move cursor to specified position 1x(column) ; 1y(row) */BYTE posi16=0;posi0 = 0x1F;po
3、si1 = 0x24;posi2 = 0x01;posi3 = 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,
5、NULL); if (!fState) break; 以下是完整功能函數(shù)。void CPosDemoDlgMain:UpdateSubDisp(BOOL bUpdateSubTotal, BOOL bCashBox)BOOL Result = FALSE, fState;volatile HANDLE m_hCom=NULL;/ 串口句柄COMMTIMEOUTS timeOuts;COMSTAT comState;DCB dcb; BYTE SendBuffer256, posi16=0;DWORD WrittenLen, dwErrorFlags; int len, x, nNumberOf
6、Bytes;while(1)/ Open COM port.m_hCom = CreateFile(gComPortID2,GENERIC_READ|GENERIC_WRITE,/ enable read and write0,/ 獨(dú)占方式NULL,OPEN_EXISTING,/ 打開(kāi)而不是創(chuàng)建0, /FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,/ 重疊方式NULL);if (m_hCom = INVALID_HANDLE_VALUE)break;SetupComm(m_hCom, 2048, 2048);/ Set timeout.timeOuts.
7、ReadIntervalTimeout = 1000;timeOuts.ReadTotalTimeoutMultiplier = 500;timeOuts.ReadTotalTimeoutConstant = 5000;timeOuts.WriteTotalTimeoutMultiplier = 500;timeOuts.WriteTotalTimeoutConstant = 5000;if (!SetCommTimeouts(m_hCom, &timeOuts)break;/ 設(shè)置傳輸參數(shù)if (!GetCommState(m_hCom, &dcb)/ get parabre
8、ak;dcb.BaudRate = _wtol(gComBaudRate2);dcb.ByteSize = _wtoi(gComDataBit2);if (_wcsicmp(gComParity2, L"none")=0)dcb.Parity = NOPARITY;else if (_wcsicmp(gComParity2, L"odd")=0)dcb.Parity = ODDPARITY;else if (_wcsicmp(gComParity2, L"odd")=0)dcb.Parity = EVENPARITY;if (_wcs
9、icmp(gComStopBit2, L"1") =0)dcb.StopBits = ONESTOPBIT;else if (_wcsicmp(gComStopBit2, L"2") =0)dcb.StopBits = TWOSTOPBITS;if (!SetCommState(m_hCom, &dcb)/ set parabreak;PurgeComm(m_hCom, PURGE_TXCLEAR | PURGE_RXCLEAR);/ 清除發(fā)送、接收緩沖區(qū)ClearCommError(m_hCom, &dwErrorFlags, &
10、;comState);/ 清除錯(cuò)誤 SendBuffer0 = 0x01; /Command Type: 01 - EPSON POS fState = WriteFile(m_hCom, (void*)SendBuffer, 1, &WrittenLen, NULL);if (!fState)break; SendBuffer0 = 0x0C; /0x0C - Clear display screen fState = WriteFile(m_hCom, (void*)SendBuffer, 1, &WrittenLen, NULL);if (!fState)break; /
11、* 1F 24 x y : Move cursor to specified position 1x(column) 20 ; 1y(row) 2 */ posi0 = 0x1F; posi1 = 0x24; posi2 = 0x01; posi3 = 0x01; fState = WriteFile(m_hCom, (void*)posi, 4, &WrittenLen, NULL);if (!fState)break; memset(SendBuffer, 0, sizeof(SendBuffer); if(bCashBox) sprintf(char*)SendBuffer, &
12、quot;Total:"); nNumberOfBytes = 6; else if(bUpdateSubTotal) if(giProductListNum = 0) sprintf(char*)SendBuffer, ""); nNumberOfBytes = 0; else sprintf(char*)SendBuffer, "SubTotal:"); nNumberOfBytes = 9; else sprintf(char*)SendBuffer, "Total:"); nNumberOfBytes = 6; if
13、(nNumberOfBytes != 0) fState = WriteFile(m_hCom, (void*)&SendBuffer, nNumberOfBytes, &WrittenLen, NULL); if (!fState) break; memset(SendBuffer, 0, sizeof(SendBuffer); if(bCashBox) sprintf(char*)SendBuffer, "%d.%02d", gTotalPrice/100, gTotalPrice%100); else if(bUpdateSubTotal) if(gi
14、ProductListNum = 0) strcpy(char*)SendBuffer, ""); else strcpy(char*)SendBuffer, m_sSubTotalBuf); else sprintf(char*)SendBuffer, "%d.%02d", gTotalPrice/100, gTotalPrice%100); len = strlen(char*)SendBuffer); x = 20 - len; /set display position posi0 = 0x1F; posi1 = 0x24; posi2 = to
15、Hex(x); posi3 = 0x01; fState = WriteFile(m_hCom, (void*)posi, 4, &WrittenLen, NULL);if (!fState)break; /display cashfState = WriteFile(m_hCom, (void*)&SendBuffer, len, &WrittenLen, NULL);if (!fState)break; /= row 2 = /set display position (row 2) posi0 = 0x1F; posi1 = 0x24; posi2 = 0x01;
16、 posi3 = 0x02; fState = WriteFile(m_hCom, (void*)posi, 4, &WrittenLen, NULL);if (!fState)break; memset(SendBuffer, 0, sizeof(SendBuffer); if(bCashBox) sprintf(char*)SendBuffer, "Cash Change:"); fState = WriteFile(m_hCom, (void*)&SendBuffer, 12, &WrittenLen, NULL); else if(bUpda
17、teSubTotal) sprintf(char*)SendBuffer, "Total:"); fState = WriteFile(m_hCom, (void*)&SendBuffer, 6, &WrittenLen, NULL); else sprintf(char*)SendBuffer, "Payment:"); fState = WriteFile(m_hCom, (void*)&SendBuffer, 8, &WrittenLen, NULL); if (!fState)break; memset(SendB
18、uffer, 0, sizeof(SendBuffer); if(bCashBox) if (m_Payment < gTotalPrice) sprintf(char*)SendBuffer, "-%d.%02d", (gTotalPrice - m_Payment)/100, (gTotalPrice - m_Payment)%100); else sprintf(char*)SendBuffer, "%d.%02d", (m_Payment - gTotalPrice)/100, (m_Payment - gTotalPrice)%100); else if(bUpdateSubTotal) sprintf(char*)SendBuffer, "%d.%02d", gTotalPrice/100, gTo
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 店鋪轉(zhuǎn)讓合同文本
- 珍視婚姻拒絕出軌
- 補(bǔ)充合同的書(shū)寫(xiě)范本
- 煉油廠管件購(gòu)銷(xiāo)合同
- 全面運(yùn)維服務(wù)合同范本
- 軟件選購(gòu)合同示例
- 酒店用品購(gòu)買(mǎi)協(xié)議
- 陶瓷截止閥采購(gòu)合同
- 水泥磚買(mǎi)賣(mài)協(xié)議模板
- 土石方施工項(xiàng)目作業(yè)勞務(wù)分包合同
- 臨床骨質(zhì)疏松患者護(hù)理查房
- 新媒體與社會(huì)性別 知到智慧樹(shù)網(wǎng)課答案
- 醫(yī)療技術(shù)臨床應(yīng)用管理檔案(姓名+工號(hào))
- 大班健康活動(dòng)《不吃三無(wú)食品》
- 婦科醫(yī)生進(jìn)修匯報(bào)課件
- 年產(chǎn)20萬(wàn)噸鎂合金項(xiàng)目可行性研究報(bào)告
- (高清版)WST 360-2024 流式細(xì)胞術(shù)檢測(cè)外周血淋巴細(xì)胞亞群指南
- 2024年甘肅省隴南市中考二模地理試題
- 教師資格證面試結(jié)構(gòu)化面試
- 經(jīng)濟(jì)學(xué)思維方式智慧樹(shù)知到期末考試答案2024年
- 健康睡眠與幸福人生智慧樹(shù)知到期末考試答案2024年
評(píng)論
0/150
提交評(píng)論