2016-01-25 34 views
-1

我編程C(ANSI C)一個POS(銷售點)方法的位標誌參數如何工作(Ansi C/C)?

我有這個功能

GetString(uchar *str,uchar mode,uchar minlen,uchar maxlen) 

是像readln但在POS

APImode參數是一樣的東西D1,D2,D3 ......

但在(API的)的例子,我有這個

if(!GetString(buf, 0x26, 0, 10)) 
{ 
buf[buf[0]+1]=0; amt=atol(buf+1); 
} else { 
/* user press CANCEL button */ } 

那麼,什麼是介乎值爲0x26(參數mode在功能)和 二進制數或位標誌,甚至,我不知道,十六進制的關係。

在API那裏有另一件事說明mode輸入參數

1. Input mode definition: (priority order is bit3>bit4>bit5, and mode&0x38≠0); 
2. When inputting, the digit will be displayed on the screen in turns as plaintext or cryptograph (according to bit3). 
3. The initial cursor position is determined by ScrGotoxy(x, y). 
4. If bit7 of mode =1, then this function could bring initial digit string, and the string is displayed on initial cursor position as input digit string. 
5. Output string does not record and contain function keys. 
6. Press CLEAR button, if it is plaintext display, then CLEAR is considered as BACKSPACE key; if it is cryptograph display, then CLEAR is considered as the key to clear all contents. 
7. Use function key to switch to Capital mode. S80 uses Alpha key to select the corresponding character on a key, however SP30 uses UP and Down key, and T52 uses ―#‖ key, T620 uses key F2. 
8. In MT30, the switch method between uppercase, lowercase and number characters is to keep pressing 

回答

1

page you linked中有8位標誌指定。在你的例子中,你有十六進制值0x26這是二進制值00100110。這指定了8位標誌,其中3(D1,D2,D5)被置位,5(D0,D3,D4,D6,D7)清零。如果你引用你的表格鏈接(這是一個圖形,所以我不能粘貼它),它告訴你GetString自變量mode指示函數的行爲,對於8位標誌集合(1)中的每一個,或清除(0)。

例如D2設置爲1表示左對齊

組合各個標誌給出一個二進制數,在您的示例中,該數字作爲十六進制數0x26傳遞。

+0

我知道我的英語不好...但是,爲什麼我的問題有-2點:c我恐怕會失去我在stackOverflow中的帳戶,你們真的幫我 –

1

的D1,D2,D3 ... D7是比特。我想它被用作一個標誌。由於它只有1個字節,所以它有8種可能的狀態,它們都可以組合在一起。

0x26是十進制38或二進制

00100110 

這意味着D1,D2,D5被設置和人的其它D的則不是。

+0

我該如何使用它? –

+1

閱讀位標誌。這是一個單字節,可以設置8個選項,你可以有組合 –

+0

好吧,我會這樣做。但爲什麼是0x26?當在API中說這個值是針對某個或另一個模式的?我只能看到例子中的0x26。在函數中,只需說D1,D2,D6? –

0

這將幫助你,我定義了一個宏來操縱D7位,這是根據文檔是ENTER模式的位。

以與其他模式相同的方式繼續。

// bits manipulation 
// idx stand for bit index 

#define CHECK_BIT(var,idx)    ((var >> idx) & 1) 
#define SET_BIT(var,idx,n)    (var ^= (-(n?1:0)^var) & (1 << idx)) 


// helping macros 

// check if Enter mode is set D7 is used 
#define IS_ENTER_MODE_SET(mode)   CHECK_BIT(mode,7) 

// set Enter mode to opt (true,false) 
#define SET_ENTER_MODE (mode,opt)  SET_BIT(mode,7,opt)