has anyone got a proc to communicate with the serial port in ASM??
my mates doing solar tracking and we need to graph the inputs in the serial port. i got the grapher. but i have not got a serial com procedure... :cry:
Posted on 2004-12-04 20:51:16 by Retsim_X
Retsim_X,

Have a look at:

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

I use asm code doing this to read from a scale and write to a slip printer every day.

hth

farrier
Posted on 2004-12-04 23:59:58 by farrier
yeh but im slack, re its all in C something and it has to be at hardware level. thats the prob. so has any one got any ideas on programming an isr(interupt service routine)??? (i dont know much about isr's) :?: :cry:
Posted on 2004-12-05 01:27:19 by Retsim_X
Try posting on the 16bit asm on the masmforum. There is at least one thread on isr there. MichaelW might help you out too.
Posted on 2004-12-05 08:39:09 by roticv
I have a process reading NMEA strings from a GPS.

Windowprocess code:
.ELSEIF uMsg==WM_COMMAND

mov eax,wParam
.IF lParam==0
.IF ax==IDM_START
INVOKE CreateEvent,NULL,FALSE,FALSE,NULL
mov hEventStart,eax
mov eax,OFFSET ReadNMEA
invoke CreateThread,NULL,NULL,eax,\
NULL,0,\
ADDR ThreadID
invoke CloseHandle,eax
INVOKE SetEvent,hEventStart
.ELSEIF ax==IDM_STOP
mov EventStop,TRUE
.ELSE
mov EventStop,TRUE
INVOKE DestroyWindow,hWnd
.ENDIF
.ENDIF


And the process reading from commport.
ReadNMEA PROC USES ecx Param:DWORD

INVOKE WaitForSingleObject,hEventStart,INFINITE
push OFFSET AppName1
mov eax, OFFSET CommPort1
mov pCommPort,eax
nextport:
INVOKE CreateFile,pCommPort,\
GENERIC_READ,\
NULL,\
NULL,\
OPEN_EXISTING,\
NULL,\
NULL
mov hComm,eax
pop eax
INVOKE SetWindowText,hwnd,eax
INVOKE SetCommState,hComm,ADDR dcb
INVOKE SetCommTimeouts,hComm,ADDR TO
INVOKE GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMemory,eax
INVOKE GlobalLock,hMemory
mov pMemory,eax
INVOKE GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,NMEASize
mov hNMEA,eax
INVOKE GlobalLock,hNMEA
mov pNMEA,eax
INVOKE RtlZeroMemory,pMemory,MEMSIZE
;================================================
;Reads from Com1
;================================================
search:
INVOKE ReadFile,hComm,pMemory,MEMSIZE,ADDR AntalBits,NULL
;================================================
;Timeout ?
;================================================
mov eax,pMemory
mov eax,[eax]
cmp al,0
jne GoOn
INVOKE RtlZeroMemory,pMemory,MEMSIZE
mov eax,pCommPort

cmp eax, OFFSET CommPort1
jne port2
mov eax,OFFSET CommPort2
mov pCommPort,eax
push OFFSET AppName2
jmp NoConnect
port2:
cmp eax,OFFSET CommPort2
jne port3
mov eax,OFFSET CommPort3
mov pCommPort,eax
push OFFSET AppName3
jmp NoConnect
port3:
cmp eax,OFFSET CommPort3
jne port4
mov eax,OFFSET CommPort4
mov pCommPort,eax
push OFFSET AppName4
jmp NoConnect
port4:
INVOKE MessageBox,hInstance,ADDR NoConnected,ADDR Rubrik,MB_OK or MB_ICONEXCLAMATION
jmp avsluta
NoConnect:
INVOKE GlobalUnlock,pMemory
INVOKE GlobalFree,hMemory
INVOKE GlobalUnlock,pNMEA
INVOKE GlobalFree,hNMEA
jmp nextport
GoOn:
;================================================
;Looking for character "$"
;================================================
cmp al,24h
jne search
mov ecx,pNMEA
mov [ecx],al
add ecx,1
next:
.IF EventStop==FALSE
;================================================
;Looking for "Line Feed"
;================================================
.WHILE al!=10
push ecx
read:
INVOKE ReadFile,hComm,pMemory,MEMSIZE,ADDR AntalBits,NULL
pop ecx
mov eax,pMemory
mov eax,[eax]
mov [ecx],al
add ecx,1
push ecx
sub ecx,pNMEA
.IF ecx==NMEASize
INVOKE RtlZeroMemory,pNMEA,NMEASize
jmp avsluta
.ENDIF
pop ecx
.ENDW
INVOKE SendMessage,hwndEdit,EM_REPLACESEL,NULL,pNMEA ;WM_SETTEXT
INVOKE RtlZeroMemory,pNMEA,NMEASize
mov ecx,pNMEA
jmp next
.ENDIF
mov EventStop,FALSE
avsluta:
INVOKE CloseHandle,hComm
INVOKE GlobalUnlock,pMemory
INVOKE GlobalFree,hMemory
INVOKE GlobalUnlock,pNMEA
INVOKE GlobalFree,hNMEA
INVOKE SetWindowText,hwnd,ADDR AppNameStop
ret
ReadNMEA ENDP


I hope it will help you.
Posted on 2004-12-05 08:47:30 by minor28
Retsim_X,

Describe your requirements for us. Windows, DOS, Linux, ...? Is your computer sitting, waiting for a signal from your device, or are you sending a request to your device to send a response? The more you tell us, the better we may be able to help you.

minor28, a very nice approach. I need to look closely at your code, it may be much better for what I am doing. Thanks.

Retsim_X, if you are using Windows, the code minor28 gave you is what you can use. It does exactly what is described in the link I sent to you, with a method to notify you of an event.

farrier
Posted on 2004-12-05 11:52:12 by farrier
I once wrote a demonstration app for the HX dos extender. Its a simple terminal app which accesses COM ports directly. Written in MASM 32bit in DOS protected mode download http://www.japheth.de/download/comxdlg.zip

It may of some help - possibly.
Posted on 2004-12-05 12:24:26 by japheth
i am working with masm32 WIN\DOS "i dont know ANYTHING about LINUX"

i am trying to do an isr that signals my app as soon as the com port gets a signal, and tells it if its a 1 or 0 on the port so its DIRECT ACCESS.

the write routine is similar it should write 1 bit at a time.
Posted on 2004-12-05 18:06:58 by Retsim_X
> and tells it if its a 1 or 0 on the port

is not possible with PC hardware. You will always get a "full" byte.
Posted on 2004-12-06 01:47:56 by japheth