Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COM to COM chat

Status
Not open for further replies.

5888

Programmer
Apr 27, 2003
16
MY
Hello there.

I am trying to write a chat program through the serial com port. Unfortunately, the following code that allows me to send a character at one time. So I am not able to type an English word and send it to the other side.

For example if i would like to send "Hello" from PC-A to PC-B, I have to type "H" and then wait for PC-B to press a key then only I can type "e".

The whole process is like PC-A sends one character, then PC-B has to response and send a character back to PC-A so that PC-A can send the second character to PC-B.

I do not know what happen to the following code, logically it makes sense but......please help. Thank you

.MODEL SMALL
.STACK 64
.DATA
MESSAGE DB 'Serial communication via COM2,4800,No P,1 Stop,8-BIT
DATA.',0AH,0DH
DB 'ANY KEY PRESS IN SENT TO OTHER PC.',0AH,0DH
DB 'PRESS ESC TO EXIT','$'

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,09
MOV DX,OFFSET MESSAGE
INT 21H ;initializing COM2
MOV AH,0 ;initialize COM port
MOV DX,01 ;COM 2
MOV AL,0E3H ;4800,NO P,1 STOP,8-BIT DATA
INT 14H ;checking key press and sending key to COM2 to
be transfered

AGAIN:

MOV AH,01 ;check for key press using INT 16H,AH=01
INT 16H ;if ZF=1,there is no key press
JZ NEXT ;if no key go check COM port
MOV AH,0 ;yes,there is a key press,get it
INT 16H ;notice we must use INT 16H twice,2nd time
;with AH=0 to get the char itself.AL=ASCII char pressed
CMP AL,1BH ;is it esc key?
JE EXIT ;yes EXIT

MOV AH,1 ;no.send the char to COM 2 port
MOV DX,01
INT 14H ;check COM2 port to see there is char, if so get
it and display it

mov ah, 0
int 16h

NEXT: MOV AH,03 ;get COM2 status
MOV DX,01
INT 14H
AND AH,01 ;AH has COM port status, mask all bits except D0
CMP AH,01 ;check D0 to see if there is a char
JNE AGAIN ;no data, go to monitor keyboard
MOV AH,02 ;yes,COM2 has data:get it
MOV DX,01
INT 14H ;get it
MOV DL,AL ;and display it using INT 21H
MOV AH,02 ;DL has char to be displayed
INT 21H

JMP AGAIN ;keep monitoring keyboard
EXIT: MOV AH,4CH ;exit to DOS
INT 21H

MAIN ENDP
END main
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top