Tuesday, September 28, 2010

Credit "to bear the blame," Who back?


Some time ago, I saw major domestic media have reported that the central bank put into use personal credit information database, but in most media reports have described has a plot, Mr. Wang is a place for non-payment of Guangdong Development Bank Credit card annual fee was added in the personal credit database, a bad record, no knowledge of his purchase of agricultural bank loan was rejected.

Similarly, because a friend recently I apply for CITIC Industrial Bank's credit card was refused, and also because of his bad credit record. Through memories, Then he remembered who was in the Guangdong Development Bank to help friends who work for the completion of issuing process over a broad mandate issued credit card, apply for credit cards, said the first year annual fee waiver for the second year, if not paid do not want to continue to use annual fee you can. However, after more than a year without receiving any calls, text messaging, e-mail notice shall pay an annual fee of the case, the Guangdong Development Bank will be directly sent a reminder of the lawyer's letter, This the second year that do not pay annual fee does not work, and has been the payment date ... ... although very happy things finally settled, it is clear that, by banks to add in the personal credit history in a bad record into the aftermath of the incident.

In accordance with the central bank's statement, the national network of individual credit database, whether the future can even pay their individual water, electricity and gas charges are included in the scope of credit history, credit history and personal financial activities will play an increasingly important role. The central bank's super-scale CRM system, number of people covered, the breadth of applications is beyond doubt. However, I work in the financial system through a friend understand that the personal credit database of features is not perfect, and now can not distinguish between malicious and good debt arrears. That is, for a person with intent to defraud, one because of his bad memory and forget to pay a fee and a bank staff as a result of negligence or dereliction of duty in arrears without the knowledge of who they personally credit history credit database may even be the same. If the individual credit database, can only record a delinquent act and no delinquent behavior, can not record the reasons for arrears and assessment is malicious or non-malicious, then functions of this CRM system is also equivalent to a simple notebook, Moreover, some bank staff may not fulfill this obligation in accordance with the workflow (for example, the amount of notification bill, charge date, mortgage or car loan interest rate increases as a result of whether the monthly payment adjustments), then the person probably just made a scapegoat The copies of the.

The author believes that individual credit database, the mind should be put into use in the financial activities of the individual's actual behavior to determine a person's credit rating. However, due to the imperfections of the system, coupled with still no one able to bank credit, service records, assessment, and standardized system of bank staff working attitude, methods can determine your credit rating, and also we can do is frequently used as soon as the card is not all the write-off in the future no more free to work in a bank to help students and friends to complete the task card, after all, more than one card, the more a pair of hands affect your credit record.






Recommended links:



MKV to VOB



Backup And Restore Directory



"Border Land" Skill Tree Rules Of Operation And Processing Point



Domain name will be the first time Chinese and other non-Latin alphabet and opening support 11 LANGU



suzhou school of music pos systems pos touch tea



American professional experts: seven double the efficiency and salary Tips



Carried out in the end to P2P: the story ABOUT the Jxta (2)



3GP to MPEG



Unihub To Come from behind



Hong Kong PCCW Privatization Commission will vote by sealed-depth inquiry



How to draw background IMAGE CAknGrid



2005 Fun WORKPLACE



Hot Dial Up And Connection Tools



AVI To IPod



Friday, September 17, 2010

Actual serial communication


Program did not write the article for a long time, and recently to compile a serial communication terminal program busy for nearly a month, was found in the Win32 API has a lot of communication problems, and many other serial communications in the article did not Turning to the issue, talk about where to concentrate. This is not a comprehensive how to write a serial communication program, but rather to discuss some practical problems.

1 Select the means of communication - synchronous or asynchronous

As in the "Serial communications in Microsoft Win32" and other articles mentioned, synchronization (NonOverLapped) approach is a relatively simple way to write code to be significantly less than the length of the asynchronous (OverLapped) way, I began to write synchronization the whole routine, to work in normal Windows98, Windows2000, but later tested and found to receive normal, but the one to send data, the program will stop there, because synchronization mode should be is if there is a communication Api in operation, another One will block until the completion of an operation, so when reading the data when the thread stay in WaitCommEvent, WriteFile stopped there. I tested my hands all the examples of serial communication program, found that all the procedures for using the synchronization mode Windows 2000 does not work correctly under all of this I could not find a solution, was found on the site in Iczelion article referred to under NT and 9x serial communication processing is different, simply do not expect to under NT or Windows 2000 while using synchronous mode send and receive data and I have to use asynchronous mode to the communication routines to re-write it again.

Therefore, the recommendations on this issue is: If the program is only intended to work in Win9x, the sake of simplicity, you can write programs using synchronous mode, if the program intends to work in the NT, you can then use the asynchronous mode must be written.

2 Win32 Communications API Bug one --- CommConfigDialog

CommConfigDialog is built into the system serial port settings dialog box pops up the API, we are set in the Device Manager dialog box is the serial port parameters, use the API without first opening the port, it is not for an already open port, but only the contents of the DCB is completed to the dialog box, press the OK when the results after the deposit back to the input DCB data structure, as when set to the serial port on the results, that is, you had to do.

CommCinfigDialog defined as follows:

BOOL CommConfigDialog (

LPTSTR lpszName, / / pointer to device name string
HWND hWnd, / / handle to window
LPCOMMCONFIG lpCC / / pointer to comm. Configuration structure
);

However, the use of found, the dialog box can sometimes, sometimes not get out, the final summing up the experience of the problem structure in COMMCONFIG dwSize field, COMMCONFIG defined as follows:

typedef struct _COMM_CONFIG (
DWORD dwSize;
WORD wVersion;
WORD wReserved;
DCB dcb;
DWORD dwProviderSubType;
DWORD dwProviderOffset;
DWORD dwProviderSize;
WCHAR wcProviderData [1];
) COMMCONFIG, * LPCOMMCONFIG;

In the parameters, wVersion to fill 100h, dwProviderSubType to fill one, but can not fill sizeof COMMCONFIG dwSize, I found that if a certain ratio should be set dwSize to sizeof COMMCONFIG dialog box out, so I used the code defines a large enough buffer for the address structure:

_CommConfigDialog Proc
local @ stCC [256]: BYTE

pushad
invoke RtlZeroMemory, addr @ stCC, sizeof @ stCC
mov (COMMCONFIG ptr @ stCC). dwSize, 256
mov (COMMCONFIG ptr @ stCC). wVersion, 100h
mov (COMMCONFIG ptr @ stCC). dwProviderSubType, 1
invoke CommConfigDialog, addr [esi]. szPortName, [esi]. hWnd, addr @ stCC
popad
ret

_CommConfigDialog Endp

3 Win32 Communications API Bug bis --- BuildCommDCB

BuildCommDCB function is to a string such as com1: 9600, n, 8,1 such a conversion to the specific data to fill in DCB, but in use there, I found that I use it to transform like com1: 9600, e, 7,1 with a parity bit like a string, it does not always give me this e conversion in the past, set up the serial port of a look into 9600, n, 7,1, and return the above-mentioned CommConfigDialog The results used to set the serial port is correct, by comparison, found that the problem lies in DCB.fbits.fParity this bit, only this bit set to 1, parity bit is valid, but BuildCommDCB precisely missed this bit, If you want to use all BuildCommDCB, do not forget to add the DCB.fbits.fParity settings back, I used the code is:

_BuildCommDCB Proc _lpszPara, _lpstDCB

pushad
mov esi, _lpstDCB
assume esi: ptr DCB

invoke RtlZeroMemory, esi, sizeof DCB
invoke BuildCommDCB, _lpszPara, esi
;************************************************* *******************
; Under the parity bit added to set DCB in DCB.fbits.fParity field
;************************************************* *******************
mov dword ptr [esi]. fbits, 0010b

cld
@ @:
lodsb
or al, al
jz @ F
cmp al ,''=''
jz _BCD_Check
cmp al ,'',''
jnz @ B
_BCD_Check:
lodsb
or al, al
jz @ F
or al, 20h
cmp al,''n''
jnz @ B
;************************************************* *******************
; Scan = n or, n parity bit is canceled
;************************************************* *******************
mov esi, _lpstDCB
and dword ptr [esi]. fbits, not 0010b
@ @:
popad
ret

_BuildCommDCB Endp

4 Win32 programming in general process of communication

Because the synchronization method is relatively simple, here is about the way the process of induction, many of the other article mentioned Windows communication API has more than 20, they are:

BuildCommDCB
BuildCommDCBAndTimeouts
ClearCommBreak
ClearCommError
CommConfigDialog
EscapeCommFunction
GetCommConfig
GetCommMask
GetCommModemStatus
GetCommProperties
GetCommState
GetCommTimeouts
GetDefaultCommConfig
PurgeComm
SetCommBreak
SetCommConfig
SetCommMask
SetCommState
SetCommTimeouts
SetDefaultCommConfig
SetupComm
TransmitCommChar
WaitCommEvent

I just see the API, when do not know how to use them, but not all of these API are to be used, for example, you want to detect the current serial port settings can only SetCommState without GetCommProperties and GetCommConfig, although they return to The information may be more. Similarly, if you want to use some default values, such as buffer size and timeout time, etc., then SetupComm and BuildCommDCBAndTimeouts, SetCommTimeouts can not, TransmitCommChar is immediately sent into the priority sequence used to send a character, usually rarely used, the following must be used about the API and use these steps:

Establishment of Event - with CreateEvent

invoke CreateEvent, NULL, TRUE, FALSE, NULL
Asynchronous serial mode operation OVERLAPPED structure must be defined, which hEvent must establish their own, you have to define two OVERLAPPED structure, one for reading one for writing, of course, must also create two Event, put them in OVERLAPPED.hEvent


Open the serial port - use CreateFile

invoke CreateFile, addr szPortName, GENERIC_READ or GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL
Note that with asynchronous mode must be specified FILE_FLAG_OVERLAPPED, and papers must be OPEN_EXISTING, read and write must be GENERIC_READ or GENERIC_WRITE


Set serial port parameters - with SetCommState

invoke SetCommState, hCom, addr dcbx
hCom is in front of the handle to open a successful return, dcbx is the data structure DCB, which includes the specific parameters of communication, as the establishment of this parameter, you can fill out their own, you can also use the previously mentioned BuildCommDCB or CommConfigDialog fill


The establishment of the thread reading data

Here, you can start reading data, and generally we are in the main thread to write data, because writing is something we can control, and reading the data when we do not know when it will come, so I want to set up a new thread Yonglai Reading data, in this thread, we cycle to read serial port using ReadFile, while the state line with WaitCommEvent detection.


To test communication status, as CTS signals, RingIn and so on - with SetCommMask, WaitCommEvent, ClearCommError, GetCommModemStatus

invoke SetCommMask, hCom, EV_BREAK or EV_CTS or EV_DSR or EV_ERR or EV_RING or EV_RLSD or EV_RXCHAR or EV_RXFLAG or EV_TXEMPTY
SetCommMask designated WaitCommEvent to wait for the event name, please check the manual for the specific parameters

invoke WaitCommEvent, hCom, addr dwEvent, NULL
WaitCommEvent wait until one of the specified event occurs SetCommMask

invoke ClearCommError, hCom, addr dwError, addr stComStat
In WaitCommEvent later, use the clear events ClearCommError Flag, for the next round of WaitCommEvent, while the API can get more detailed event information

invoke GetCommModemStatus, hCom, addr dwModemStatus
Similarly, GetCommModemStatus is used to obtain serial line status, such as CTS, RING, etc., when WaitCommEvent return, only that the state has changed, such as CTS, etc., but specifically into the On or Off to also depend on the API obtain more detailed information


Reading data - use ReadFile

invoke ReadFile, hCom, addr szBuffer, sizeof szBuffer, addr dwBytesRead, addr stReadState
The last parameter is defined at the beginning of the OVERLAPPED structure's address, designated it the way that is asynchronous read mode, the API will return immediately, and the latter use

invoke GetOverlappedResult, hCom, addr stReadState, addr dwBytesRead, FALSE
Read the rest of the data


Close the port at the end - stop waiting and close ports WaitCommEvent CloseHandle

Normal procedures will remain in WaitCommEvent wait, when to terminate the thread when the process must withdraw from the WaitCommEvent in, this time to use

In accordance with the instructions on the Win32 manual, parameters NULL's SetCommMask make another thread in the WaitCommEvent immediately returned, and then the port is closed with CloseHandle
invoke CloseHandle, hCom
5 Win32 Communications API Bug bis --- SetCommMask and WaitCommEvent

Strictly speaking it should not be a Bug, but by accident, I found that sometimes I can not read the thread end, tracking found to be parked in the WaitCommEvent, this description sometimes invoke SetCommMask, hCom, NULL does not make WaitCommEvent exit I last used by: the SetCommMask a later invoke SetEvent, stReadState.hEvent, to read the OVERLAPPED structure Event Set for WaitCommEvent think that Event occurs, it will immediately return, perhaps this is not universal , but if your program is stopped at the WaitCommEvent place a try.

6 How to read the thread in the cycle of preparation

In accordance with the "Serial communications in Microsoft Win32" article in the routine, time cycle can be:

# Define READ_TIMEOUT 500 / / milliseconds

DWORD dwRes;
DWORD dwRead;
BOOL fWaitingOnRead = FALSE;
OVERLAPPED osReader = (0);

/ / Create the overlapped event. Must be closed before exiting
/ / To avoid a handle leak.
osReader.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);

if (osReader.hEvent == NULL)
/ / Error creating overlapped event; abort.

if (! fWaitingOnRead) (
/ / Issue read operation.
if (! ReadFile (hComm, lpBuf, READ_BUF_SIZE, & dwRead, & osReader)) (
if (GetLastError ()! = ERROR_IO_PENDING) / / read not delayed?
/ / Error in communications; report it.
else
fWaitingOnRead = TRUE;
)
else (
/ / Read completed immediately
HandleASuccessfulRead (lpBuf, dwRead);
)
)


if (fWaitingOnRead) (
dwRes = WaitForSingleObject (osReader.hEvent, READ_TIMEOUT);
switch (dwRes)
(
/ / Read completed.
case WAIT_OBJECT_0:
if (! GetOverlappedResult (hComm, & osReader, & dwRead, FALSE))
/ / Error in communications; report it.
else
/ / Read completed successfully.
HandleASuccessfulRead (lpBuf, dwRead);

/ / Reset flag so that another opertion can be issued.
fWaitingOnRead = FALSE;
break;

case WAIT_TIMEOUT:
/ / Operation isn''t complete yet. FWaitingOnRead flag isn''t
/ / Changed since I''ll loop back around, and I don''t want
/ / To issue another read until the first one finishes.
/ /
/ / This is a good time to do some background work.
break;

default:
/ / Error in the WaitForSingleObject; abort.
/ / This indicates a problem with the OVERLAPPED structure''s
/ / Event handle.
break;
)
)


This is a procedure in 98 normal, but very unfortunate that under the Win2000, ReadFile always returns the correct time, not to return ERROR_IO_PENDING, make the following WaitForSingleObject cycle non-existent, The problem is, ReadFile returns the correct time is read every time 1 byte, the result program works very strange, even if many of the characters in the buffer, the program also can only read one character each time, to wait until the send operation character or do other changes to the state line to read the next character , I do not know this strange phenomenon is how it happened, anyway I solved the way is ReadFile Qian Zai add WaitCommEvent, Zhen Zheng Yi Hou Cai until EV_RXCHAR go ReadFile, Dao Finally, I Yong's Xunhuan is that, without an article in Suiran example is the case, but it also in windows9x and work well under windows2000:

. While dwFlag & IF_CONNECT
;************************************************* *******************
; Detection of other communication events
; If detected and defined lpProcessEvent call the lpProcessEvent
;************************************************* *******************
invoke WaitCommEvent, hCom, addr @ dwEvent, NULL; addr stReadState
push eax
invoke ClearCommError, hCom, addr @ dwError, addr @ stComStat
pop eax
. If eax == 0
invoke GetLastError
. If eax == ERROR_IO_PENDING
or dwFlag, IF_WAITING
. Endif
. Else
; Here is the line handling state
. Endif
;************************************************* *******************
; If you do not have to wait for asynchronous read process, the read port
;************************************************* *******************
. If! (DwFlag & IF_WAITING)
mov @ dwBytesRead, 0
invoke ReadFile, hCom, addr @ szBuffer, sizeof @ szBuffer, addr @ dwBytesRead, addr stReadState
. If eax == FALSE
or dwFlag, IF_WAITING
invoke GetLastError
. If eax! = ERROR_IO_PENDING
; Here is the error handling
. Endif
. Else
and dwFlag, not IF_WAITING
mov eax, @ dwBytesRead
. If eax! = 0
; Here is the received data processing
. Endif
. Endif
. Endif
;************************************************* *******************
; If the asynchronous read port, then wait
;************************************************* *******************
. If dwFlag & IF_WAITING
invoke WaitForSingleObject, stReadState.hEvent, 200
. If eax == WAIT_OBJECT_0
and dwFlag, not IF_WAITING
invoke GetOverlappedResult, hCom, addr stReadState, addr @ dwBytesRead, FALSE
. If eax! = 0
mov eax, @ dwBytesRead
. If eax! = 0
; Here is the received data processing
. Endif
. Else
; Here is the error handling
invoke ClearCommError, hCom, addr @ dwError, addr @ stComStat
. Endif
. Else
; Here is the error handling
. Endif
. Endif
. Endw

7 flow control problems

In flow control mode for the "no" and "software controlled" circumstances, basically no problem, but the "hardware control" under, win32 manual control method described in RTS_CONTROL_HANDSHAKE meaning is:

Enables RTS handshaking. The driver raises the RTS line when the "type-ahead" (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.

That is, when the buffer is full when the fast OFF RTS will automatically send notice to the other suspended, when the buffer is empty again came out, RTS will be automatically ON, but I found that when RTS OFF after changing the buffer even if you have empty , RTS will not automatically ON, causing the other party do not stop there, sent in, so if the hardware flow control to use it, even with the best detection in the receiving buffer size after the judge, after the concrete is used to return ClearCommError The COMSTAT.cbInQue, when the buffer is already empty out when to use invoke EscapeCommFunction, hCom, SETRTS re-RTS is set to ON.

These are the serial communication programming I found the real problem, if there are discrepancies and where practical, or other questions, welcome to the forum of programming.







Recommended links:



Basic Or VB Or VB DotNet Report



Dell CEO or forced to replace him within a six potential successors to the election



Using warm and intimate small music prompted the fish that you're familiar with the music fish



Jinshan Jinshan Nu Pi Typing Through Repeated Fake "Li Gui," Poisonous Pit Users



My Favorite Printer



Introduction to Fibre Channel based: FCIP and iSCSI comparison



Registry combat Collection - "Operation" Change Collection



avi to mp4 converter free download



Browser Tools for you



Orient Securities Executive Assistant Shu Wang: grab the share of off-site transactions



My Favorite Management And Distribution



Alternative workplace quit: to a rival company to do an undercover intelligence probe



mov to mpeg converter free



M2TS to mov



Realplayer H.264



Navigator V6.0 grand public



Customer is not his wife is a lover of God is