Hi every one

I have a loop back in my com1 so I can read & write to the same port, my program is supposed to send data via the port and then receive the same data back..


.486
.model flat, stdcall

option casemap:none

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
include \masm32\include\shell32.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
include \masm32\include\windows.inc

.data
AppName db "ComX Test",0
comX db "//./com1",0
data db "abcd",0
values db "COM1: baud=11500 parity=N data=8 stop=1",0
CreateProblem db "Couldn't create Handel",0
InitProblem db "Couldn't Initialize Port",0
WriteProblem db "Couldn't Write to Port",0
ReadProblem db "Couldn't Read from Port",0
.data?
m_dcb DCB <?>
m_CommTimeouts COMMTIMEOUTS <?>
data2 db ?
hcomm dd ?

.code

start:
invoke CreateFile,addr comX, GENERIC_WRITE,0,0,OPEN_EXISTING,0,0
mov hcomm,eax
.IF eax==INVALID_HANDLE_VALUE
invoke MessageBox,NULL, addr CreateProblem,addr AppName,MB_OK
jmp @F
.ENDIF

mov m_CommTimeouts.ReadIntervalTimeout,0FFFFFFFFh
mov m_CommTimeouts.ReadTotalTimeoutMultiplier,0
mov m_CommTimeouts.ReadTotalTimeoutConstant,3000
mov m_CommTimeouts.WriteTotalTimeoutMultiplier,0
mov m_CommTimeouts.WriteTotalTimeoutConstant,1000
invoke SetCommTimeouts, hcomm,ADDR m_CommTimeouts
mov eax,sizeof DCB
mov m_dcb.DCBlength,eax
invoke GetCommState, hcomm,ADDR m_dcb
.IF eax==0
invoke BuildCommDCBAndTimeouts,ADDR values,ADDR m_dcb,ADDR m_CommTimeouts
.IF eax==0
invoke SetCommState, hcomm,ADDR m_dcb
.IF eax==1
jmp problem1
.ENDIF
.ELSE
jmp problem1
.ENDIF
jmp problem1
.ELSE
jmp problem1
.ENDIF

invoke WriteFile,hcomm,addr data,1,1,NULL
.if eax==1
jmp problem2
.endif

invoke ReadFile,hcomm,addr data2,1,1,NULL

problem1:
invoke MessageBox,NULL, addr InitProblem,addr AppName,MB_OK
jmp @F
problem2:
invoke MessageBox,NULL, addr WriteProblem,addr AppName,MB_OK
jmp @F
problem3:
invoke MessageBox,NULL, addr ReadProblem,addr AppName,MB_OK
jmp @F

@@:
invoke CloseHandle, hcomm
invoke ExitProcess,0
end start


But it fails in the initialzing fase.. Pease help

Best Regards
Posted on 2003-08-17 18:11:45 by mistronr1
What ever ever happened to
mov dx,3f8
in al,dx
or 2f8
Posted on 2003-08-17 18:45:00 by mrgone
We can't accsses serial port's from windows any more, we have to get permission :(
to accsses port's like serial, Parallel, network, PS2 etc, you have to open them as a file, this is how win32 works.
Posted on 2003-08-17 18:53:28 by mistronr1
Try this:
comX db "COM1",0

invoke CreateFile,ADDR comX,GENERIC_READ or GENERIC_WRITE,0,NULL,OPEN_EXISTING
FILE_ATTRIBUTE_NORMAL,NULL

"But it fails in the initialzing fase.."
What is this?
CreateProblem
InitProblem
ReadProblem
WriteProblem etc.
Posted on 2003-08-17 21:18:31 by lingo12
It's offset 64h in TSS. Search this site for user "Four-F" and download his KMD tutorial.
Posted on 2003-08-17 21:34:17 by mrgone
Hi
lingo:
CreateProblem shows a messagebox if File Creation fails
InitProblem shows a messagebox if Initializing fails ASO

mrgone:
The Tutorial is Great, but not what I am looking for, I just need to send & receive some bytes via com1.

Here is my code so far, it fails in the Write fase:


.486
.model flat, stdcall

option casemap:none

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
include \masm32\include\shell32.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
include \masm32\include\windows.inc

.data
AppName db "ComX Test",0
comX db "COM1",0
data db "abcd",0
values db "baud=11500 parity=N data=8 stop=1",0
CreateProblem db "Couldn't create Handel",0
InitProblem db "Couldn't Initialize Port",0
WriteProblem db "Couldn't Write to Port",0
ReadProblem db "Couldn't Read from Port",0
NoProblemz db "NO Problems",0

.data?
m_dcb DCB <?>
m_CommTimeouts COMMTIMEOUTS <?>
data2 db ?
hcomm dd ?
NrOfByte dd ?
dataPointer dd ?
.code

start:



invoke CreateFile,addr comX,GENERIC_READ or GENERIC_WRITE,0,0,OPEN_EXISTING,0,0
mov hcomm,eax
.IF eax==INVALID_HANDLE_VALUE
invoke MessageBox,NULL, addr CreateProblem,addr AppName,MB_OK
jmp @F
.ENDIF


invoke GetCommTimeouts, hcomm,ADDR m_CommTimeouts
.IF eax==0
;invoke MessageBox,NULL, addr InitProblem,addr AppName,MB_OK
.ENDIF
invoke SetCommTimeouts, hcomm,ADDR m_CommTimeouts
.IF eax==0
;invoke MessageBox,NULL, addr InitProblem,addr AppName,MB_OK
.ENDIF


invoke BuildCommDCBAndTimeouts,ADDR values,ADDR m_dcb,ADDR m_CommTimeouts
.IF eax==0
jmp problem1
.ENDIF



invoke WriteFile,hcomm,ADDR data,sizeof data,NrOfByte,NULL
.if eax==0
jmp problem2
.endif

invoke ReadFile,hcomm,ADDR data2,NrOfByte,NULL,NULL
.if eax==0
jmp problem3
.endif

invoke MessageBox,NULL, addr NoProblemz,addr AppName,MB_OK
jmp @F

problem1:
invoke MessageBox,NULL, addr InitProblem,addr AppName,MB_OK
jmp @F
problem2:
invoke MessageBox,NULL, addr WriteProblem,addr AppName,MB_OK
jmp @F
problem3:
invoke MessageBox,NULL, addr ReadProblem,addr AppName,MB_OK
jmp @F

@@:
invoke CloseHandle, hcomm
invoke ExitProcess,0
end start



Best Regards

BTW I have a loop back in my com1 port, It's tested with a program written in C, it works just fine.
Posted on 2003-08-18 12:06:28 by mistronr1
You have to fill the DCB structure with values before you create the file. So move the BuildCommDCBAndTimeouts function before CreateFile function.
Posted on 2003-08-18 13:48:43 by minor28
Hi minor28
I Did but it fails in WriteFile
Best Regards
Posted on 2003-08-18 13:55:00 by mistronr1
;invoke WriteFile,hcomm,ADDR data,sizeof data,NrOfByte,NULL

invoke WriteFile,hcomm,ADDR data,sizeof data,ADDR NrOfByte,NULL


;invoke ReadFile,hcomm,ADDR data2,NrOfByte,NULL,NULL

invoke ReadFile,hcomm,ADDR data2,ADDR NrOfByte,NULL,NULL
Posted on 2003-08-18 14:06:04 by lingo12
Hi

Great the WriteFile is OK, Now it fails in ReadFile.
Thanx lingo

Best Regards


This one works
invoke ReadFile,hcomm,ADDR data2,sizeof data,ADDR NrOfByte,NULL
Posted on 2003-08-18 14:18:15 by mistronr1
;invoke ReadFile,hcomm,ADDR data2,NrOfByte,NULL,NULL

invoke ReadFile,hcomm,ADDR data2,sizeof data, ADDR NrOfByte,NULL
Posted on 2003-08-18 14:27:01 by lingo12
invoke ReadFile,hcomm,ADDR data2,NrOfByte,ADDR NrOfBytesRead,NULL
NrOfBytesRead must be zero before read.

Edit: I am too slow to write.
Posted on 2003-08-18 14:28:27 by minor28
Thanx alot every one I realy appricate all the help
peace
Posted on 2003-08-18 14:57:49 by mistronr1
hello, everybody.
I learn The Serial Communications in MASM. here is the code :
===============================================
.486
.model flat, stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

include \masm32\include\shell32.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
include \masm32\include\windows.inc

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
AppName db "ComX Test",0
comX db "COM1",0
m_data db "abcd",0
values db "COM1: baud=9600 parity=N data=8 stop=1",0
CreateProblem db "Couldn't create Handel",0
InitProblem db "Couldn't Initialize Port",0
WriteProblem db "Couldn't Write to Port",0
ReadProblem db "Couldn't Read from Port",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
m_dcb DCB <?>
m_CommTimeouts COMMTIMEOUTS <?>
m_data2 db ?
hcomm dd ?

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code

start:
invoke CreateFile,ADDR comX,GENERIC_READ or GENERIC_WRITE,0,NULL,OPEN_EXISTING,\
FILE_ATTRIBUTE_NORMAL,NULL
mov hcomm,eax
.IF eax==INVALID_HANDLE_VALUE
invoke MessageBox,NULL, addr CreateProblem,addr AppName,MB_OK
jmp @F
.ENDIF

mov m_CommTimeouts.ReadIntervalTimeout,0FFFFFFFFh
mov m_CommTimeouts.ReadTotalTimeoutMultiplier,0
mov m_CommTimeouts.ReadTotalTimeoutConstant,3000
mov m_CommTimeouts.WriteTotalTimeoutMultiplier,0
mov m_CommTimeouts.WriteTotalTimeoutConstant,1000
invoke SetCommTimeouts, hcomm,ADDR m_CommTimeouts
mov eax,sizeof DCB
mov m_dcb.DCBlength,eax
invoke GetCommState, hcomm,ADDR m_dcb
.IF eax==0
invoke BuildCommDCBAndTimeouts,ADDR values,ADDR m_dcb,ADDR m_CommTimeouts
.IF eax==0
invoke SetCommState, hcomm,ADDR m_dcb
.IF eax==1
jmp problem1
.ENDIF
.ELSE
jmp problem1
.ENDIF
jmp problem1
.ELSE
jmp problem3
.ENDIF

invoke WriteFile,hcomm,addr m_data,1,1,NULL
.if eax==1
jmp problem2
.endif

invoke ReadFile,hcomm,addr m_data2,1,1,NULL

problem1:
invoke MessageBox,NULL, addr InitProblem,addr AppName,MB_OK
jmp @F
problem2:
invoke MessageBox,NULL, addr WriteProblem,addr AppName,MB_OK
jmp @F
problem3:
invoke MessageBox,NULL, addr ReadProblem,addr AppName,MB_OK
jmp @F

@@:
invoke CloseHandle, hcomm
invoke ExitProcess,0

end start
=============================================== :roll:
when compiling , appear follow:
" \masm32\include\windows.inc(84): error A2005: symbol redefinition : CHAR "
why can't pass when compiling in the code?
Best Regards.
Posted on 2004-11-03 00:02:07 by dcskm4200
if you use, Four-F's Kernel-Mode-Driver Kit, you can access I/O ports easily (as it was done several years ago).

A lot more simple.
Posted on 2004-11-03 03:57:27 by vandenab
Hello,


Another try to make Serial Comm program. It is not finished, but works with a modem. It make a "ATH1" / "ATH0".

Suggestions?
Posted on 2004-11-03 05:04:15 by lgg2
Vandenab , Lgg2 . Thranks for your help.
In the Four-F's Kernel-Mode-Driver Kit , There is only one example about how show serial port baud rate. The example have many macros, understanding need more difficulty.
Posted on 2004-11-03 06:28:14 by dcskm4200
what I just ment was, use the simple driver (example1) with its corresponding SCP (which you use to launche it), and in the driver entry routine, you can do what ever you want in RING0 (except BIOS real mode functions of course). This means you can use cli, sti, in and out functions.

Concerning serial ports, you can easily find which IO ports you have to use with in and out. I personnally never worked with serial ports, so I wouldn't know which ports.

Good luck.
Posted on 2004-11-03 07:56:22 by vandenab
vandenab:
Thanks your reply.
Your method is very good and powerful, maybe simple. but i am a beginner at masm language and serial commumication. if my program that have much more errors and can't working will work in ring0, it is terrible. debugging more difficult, and don't know where was error. many times i have to poweroff for continuing.
my little concept built at <<Serial Communications in Win32>> (Allen Denver. Microsoft Windows Developer Support). there are nice base Communication examples for learnning. but they were written by C. How translate c into win32 asm is hard for me. i need more example win32 asm code for practicing and comprehend the concept. internet have few stuffs about Serial Communications in win32 asm. could you commend some internet address ?
best regards.
Posted on 2004-11-03 09:53:54 by dcskm4200
I am pretty new at asm myself. I'm building a routine that accesses hardware in the simplest ways, but for a (maybe) powerfull application. Once in Ring0, I work with the keyboard controller, so what I do couldn't help you.

I suggest you go through Randall Hyde's ArtOfAssembly book (available on the net). It's really neat if you're starting, it helped me a lot. After that, you 'll have to find documentation about communication protocol and interrupt routines involving the serial port. You may begin with http://cs.smith.edu/~thiebaut/ArtOfAssembly/artofasm.html . It's the old version of AOA. It's not really applicable to todays computer environments since everything is in protected mode now, but you can learn how serial ports work. This is (I think so) still applicable.

Have fun.

Nico.
Posted on 2004-11-04 04:55:12 by vandenab