I'm trying to to a program that send via COMM1. But my program has a lot of problems.

1.When my program starts always take the problemo route.
mov hcomm,eax
        cmp eax,INVALID_HANDLE_VALUE
        je problem0

Jumps to this line

problem0:
invoke MessageBox,NULL, addr InitProblem,addr AppName,MB_OK
jmp @F

And the program exit.

2.If i ommit that line, when i compare the final user decision (1, 2 or 3), the code don't enters to the loop.
mov esi, input("ENTER 1 TO TRANSMIT, 2 TO RECEIVE O 3 TO EXIT: ")

and don't do anything.



I' don't know if in my code need more lines, or if i ommit it.

Can anybody help me, Thanks.

:sad:


.486
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
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

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\macros\macros.asm

.data
AppName db "Check Port",0
com db "COM1",0
                parf                 db "COM1: baud=9600 parity=N data=8 stop=1",0
m_data db "test",0
InitProblem                 db "Can't Inicializate Port",0
WriteProblem                 db "Can't Writte Through Port",0
ReadProblem db "Can't Read From port",0
hcomm dd ?
contador                 dd ?
m_data2 db 256 dup (?)

.data?
lp_rdBuffer db 100 dup (?)
lp_sdBuffer db 100 dup (?)

.code
start:

; Abrimos el puerto
invoke CreateFile,ADDR com,GENERIC_READ or GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
mov hcomm,eax
                cmp eax,INVALID_HANDLE_VALUE
je problem0
      loc 10, 8
      mov esi, input("ENTER 1 TO TRANSMIT, 2 TO RECEIVE O 3 TO EXIT: ")
      .IF esi==1
        ; Escribimos al puerto
  mov esi,offset m_data
                  mov ebx,sizeof m_data
        .while ebx != 0
invoke WriteFile,hcomm,addr m_data,sizeof m_data,addr contador,NULL
test eax, eax
jz problem1
add esi,contador
sub ebx,contador
        .endw
      .ELSEIF eax==2
        ; Leemos del puerto
  mov esi,offset m_data2
  mov ebx,sizeof m_data2
  .while ebx != 0
invoke ReadFile,hcomm,addr m_data2,sizeof m_data2,addr contador,NULL
test eax,eax
jz problem2
add esi,contador
sub ebx,contador
  .endw
      .ELSEIF eax==3
        jmp @F
      .ENDIF

; terminamos
jmp @F

; no se pudo abrir el puerto
problem0:
invoke MessageBox,NULL, addr InitProblem,addr AppName,MB_OK
jmp @F

; no se pudo leer del puerto
problem1:
invoke MessageBox,NULL, addr ReadProblem,addr AppName,MB_OK
jmp @F

; no se pudo enviar por el puerto
problem2:
invoke MessageBox,NULL, addr WriteProblem,addr AppName,MB_OK

@@:
; cerramos el puerto, si es que estaba abierto
mov eax,hcomm
.if eax != INVALID_HANDLE_VALUE
invoke CloseHandle,eax
.endif

; terminamos el programa
invoke ExitProcess,0

Posted on 2005-11-28 16:30:50 by chola
to use HandleError, get more information about Errors.
Posted on 2005-11-29 08:21:47 by dcskm4200
Hi everyone!
chola, just try to use "\\.\COM1" against "COM1" in CreateFile function.

regards
...
Posted on 2005-11-29 10:46:02 by Bohdan
Ok, i'll try this.


Hi everyone!
chola, just try to use "\\.\COM1" against "COM1" in CreateFile function.

regards
Posted on 2005-11-29 16:51:06 by chola
i use "\\.\COM1"  and nothing. i use "\DEV\COM1" too, and nothings happend

:sad:

I have the dude if this is correct, because always is jumping to problem0

; Open Port
invoke GetModuleHandle, NULL
      invoke CreateFile,ADDR com,GENERIC_READ or GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
mov hcomm,eax
      cmp eax,INVALID_HANDLE_VALUE
je problem0


; Can't open port
problem0:
invoke MessageBox,NULL, addr InitProblem,addr AppName,MB_OK
jmp @F
Posted on 2005-11-29 21:45:03 by chola
chola,

This always works for me:


SPort db "COM1", 0
INVOKE CreateFile, ADDR SPort, GENERIC_READ or GENERIC_WRITE, NULL, NULL, OPEN_EXISTING, NULL, NULL


The only thing that will really help you and us is to check and report the return value and error report!

hth,

farrier
Posted on 2005-11-29 23:36:19 by farrier
Try this small app.  ;)
Maybe your COM1 is used by another process???  :sad:
Attachments:
Posted on 2005-11-30 04:03:55 by Bohdan
Thanks Bohdan, i use it, they show me that the com1 was succesfully open, the other, they show me that can't open the specific file.

The error that reports in the number 3, i don't know the meaning of this number.

I have a question, in all programs that i see, they have an aditional files, for ex. in the com.zip that Bohdan send me there a .wap file, when i use de MASM32.exe, they only create a .exe file and a .obj file, why this diferences. (.bat, .bin, .wap, .lib).
Posted on 2005-11-30 16:30:47 by chola
The .wap files are for this editor:
http://www.winasm.net
Posted on 2005-11-30 18:06:04 by QvasiModo
Hi chola.
"The system cannot find the file specified" means
"There is no \\.\COMx in your PC"  ;)
Posted on 2005-12-01 07:01:11 by Bohdan
Ok. But it did the test of the COM1 and it works. i did the test with the Hyperterminal. and the COM1 it's not been used by another program, it's free.

I have the dude with this line
invoke CreateFile,ADDR com,GENERIC_READ or GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
Posted on 2005-12-03 16:29:11 by chola
chola,

Did you try the line I suggested?  What is the GetLastError message? ? ?

Also look at the following thread, they explored most of what you can do with a serial port:

http://www.asmcommunity.net/board/index.php?topic=22204.0

farrier

Posted on 2005-12-03 20:16:38 by farrier
The error is number 3, ERROR_PATH_NOT_FOUND, but i check the Com1 and works OK.

Thanks For the link.

;)

regards
Posted on 2005-12-05 01:12:15 by chola
Is this line correct ??



invoke CreateFile,ADDR com,GENERIC_READ or GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
Posted on 2005-12-08 12:49:54 by chola
chola,

Once again...

Look at the code I showed you and the link I provided, they work!!

Everything I needed to learn to use the serial and parrallel port I found at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/configuring_a_communications_resource.asp

farrier
Posted on 2005-12-08 17:05:26 by farrier