![]() |
Forum Index : Microcontroller and PC projects : Micromite serial port monitor
Author | Message | ||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
I was going to use the PC to monitor my micromite communications but I thought that that was not in the right spirit. So here is a program that runs on a MM+ and can monitor a serial port in both directions. You connect COM1 Rx to one of the RX/Tx lines to monitor and COM2 Rx to the other line. Use up/down arrows or U and D to set the baud rate. S to start and X to stop capturing. Non printing characters are in HEX preceded by a backslash'\' a '\' in the normal text is not treated any special way. One direction is in red and the other in blue. If you are using a LCD to monitor with, you can rem out the three lines that set the VT100 colours. You might also want to reduce the line length (maxcol) to suit. I was going to use a MX170 but I wanted the higher baudrates that the 470 offers. ![]() ' TassyJim ' Serial port monitor ' MMMon.bas ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' OPTION EXPLICIT DIM blist$(11)= ("150","300","600","1200","2400","4800","9600","19200","38400","57600","115200","230400") DIM brate=8, current, running, col, k$ DIM crlf$=CHR$(13)+CHR$(10) DIM maxcol = 80 PRINT "Baudrate: "+blist$(brate) PRINT "Idle..." col=1 DO ' IF running = 1 THEN IF LOC(#1)>0 THEN fetch1 IF LOC(#2)>0 THEN fetch2 ENDIF k$=INKEY$ IF k$<>"" THEN setup k$ PAUSE 100 LOOP SUB setup k$ SELECT CASE k$ CASE "U","u", CHR$(128) ' baud rate up brate=min(brate+1,11) PRINT "Baudrate: "+blist$(brate) col=1 CASE "D","d", CHR$(129) ' baud rate down brate=max(brate-1,0) PRINT "Baudrate: "+blist$(brate) col=1 CASE "S","s" ' start capture IF running=0 THEN running =1 OPEN "COM1:"+blist$(brate) AS #1 OPEN "COM2:"+blist$(brate) AS #2 PRINT "Capture started at "+blist$(brate)+" baud" col=1 ENDIF CASE "X","x" ' stop capture IF running = 1 THEN running = 0 current = 0 CLOSE #1 CLOSE #2 COLOUR RGB(white) ' for LCD PRINT CHR$(27)+"[0m"; ' for Teraterm PRINT crlf$+"Capture stopped" ENDIF CASE "?" ' help PRINT crlf$ PRINT "U baud rate up" PRINT "D baud rate down" PRINT "S start capture" PRINT "X stop capture" col=1 CASE ELSE ' unknown command PRINT crlf$+"? for help " col=1 END SELECT END SUB SUB fetch1 LOCAL txt$, ch$, n IF current <> 1 THEN current = 1 COLOUR RGB(red) ' for LCD PRINT CHR$(27)+"[31m"; 'for Teraterm ENDIF txt$=INPUT$(LOC(#1),#1) FOR n = 1 TO LEN(txt$) ch$=MID$(txt$,n,1) IF ASC(ch$) < 32 THEN ch$="\"+RIGHT$("0"+HEX$(ASC(ch$)),2) IF ASC(ch$) > 127 THEN ch$="\"+RIGHT$("0"+HEX$(ASC(ch$)),2) col=col+LEN(ch$) IF col>maxcol THEN PRINT "" col=1 ENDIF PRINT ch$; NEXT n END SUB SUB fetch2 LOCAL txt$, ch$,n IF current <> 2 THEN current = 2 COLOUR RGB(blue) ' for LCD PRINT CHR$(27)+"[34m"; 'for teraterm ENDIF txt$=INPUT$(LOC(#2),#2) FOR n = 1 TO LEN(txt$) ch$=MID$(txt$,n,1) IF ASC(ch$) < 32 THEN ch$="\"+RIGHT$("0"+HEX$(ASC(ch$)),2) IF ASC(ch$) > 127 THEN ch$="\"+RIGHT$("0"+HEX$(ASC(ch$)),2) col=col+LEN(ch$) IF col>maxcol THEN PRINT "" col=1 ENDIF PRINT ch$; NEXT n END SUB FUNCTION max(a,b) 'returns the maximum of the two float values IF a>b THEN max=a ELSE max=b END IF END FUNCTION FUNCTION min(a,b) 'returns the minimum of the two float values IF a<b THEN min=a ELSE min=b END IF END FUNCTION Jim VK7JH MMedit |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2944 |
Interesting little program there Jim with lots of uses (for me anyway!). Can't wait to try this out so thanks for posting it ![]() WW |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |