Posts: 8
Threads: 3
Joined: Mar 2004
Hi.
Does anyone know how to open COM2 with baud rates in excess of 9600, in particular 115200?
Thanks.....
Posts: 1,752
Threads: 21
Joined: Jun 2002
From the ABC Packets:
Code:
'===========================================================================
' Subject: BEYOND 19200 Date: Unknown Date (00:00)
' Author: Donn Bly Code: QB, QBasic, PDS
' Keys: BEYOND,19200 Packet: MODEM.ABC
'===========================================================================
DECLARE SUB BaudLatch ()
'Use the straight OPEN COM statement for 19200. To go higher you can
'use this code (originally from Donn Bly):
BaudLatch
SUB BaudLatch 'enables 38400 baud want to put in com3 and com4 support
'NewBaud$ = "38400"
'BaudNum% = 3 'for 38.4
'BaudNum% = 2 'for 56000
BaudNum% = 1 'for 115K
Port$ = "COM4:"
SELECT CASE Port$
CASE "COM1:"
BaseAddress% = &H3F8
CASE "COM2:"
BaseAddress% = &H2F8
CASE "COM3:"
BaseAddress% = &H3E8
CASE "COM4:"
BaseAddress% = &H2E8
END SELECT
OldLSR% = INP(BaseAddress% + 3)
OUT (BaseAddress% + 3), (OldLSR% OR &H80) ' Enable the Divisor Latch
OUT (BaseAddress% + 0), (BaudNum% MOD &HFF) ' Lo Byte of Baud Rate
OUT (BaseAddress% + 1), (BaudNum% \ &H100) ' Hi Byte of baud Rate
OUT (BaseAddress% + 3), OldLSR% ' Disable Divisor Latch
END SUB
Posts: 8
Threads: 3
Joined: Mar 2004
Thanks Plasma. I will try this code shortly.
MGG....
Posts: 8
Threads: 3
Joined: Mar 2004
Hi again. My understanding of INP and OUT are that they read and write bytes from/to a hardware port. I failed to mention
that I must send a string of characters to COM2 (request
packet) and receive back characters (response packet), i.e.
something like this:
Rqst_Pkt = "440900000000d35e"
open "com2:115200,n,8,1" for random as #1
print #1, Rqst_Pkt
sleep 1
line input #1, Resp_Pkt
...
Is this do-able in QB7?
Thanks,
MGG...
Posts: 1,752
Threads: 21
Joined: Jun 2002
Should be...
Code:
DEFINT A-Z
DECLARE SUB ComSpeed (Port, Baud&)
ComSpeed 2, 115200
OPEN "COM2: ,N,8,1" FOR RANDOM AS #1
Rqst.Pkt$ = "440900000000d35e"
PRINT #1, Rqst.Pkt$
SLEEP 1
LINE INPUT #1, Resp.Pkt$
CLOSE #1
SUB ComSpeed (Port, Baud&)
' Based on BaudLatch() sub by Donn Bly
'
' Port = COM Port (1, 2, 3, or 4)
' Baud& = Baud setting (9600, 14400, 19200, 38400, 57600, 115200, etc.)
BaudDiv = 115200 / Baud&
IF BaudDiv = 0 THEN BaudDiv = 1
SELECT CASE Port
CASE 4
BaseAddr = &H2E8 ' com4
CASE 3
BaseAddr = &H3E8 ' com3
CASE 2
BaseAddr = &H2F8 ' com2
CASE ELSE
BaseAddr = &H3F8 ' com1
END SELECT
OldLSR = INP(BaseAddr + 3)
OUT BaseAddr + 3, OldLSR OR &H80 ' Enable the Divisor Latch
OUT BaseAddr + 0, BaudNum MOD &HFF ' Lo Byte of Baud Rate
OUT BaseAddr + 1, BaudNum \ &H100 ' Hi Byte of baud Rate
OUT BaseAddr + 3, OldLSR ' Disable Divisor Latch
END SUB
Posts: 8
Threads: 3
Joined: Mar 2004
You're fast and you're good. I will try this and let you know.
Thanks,
MG........
Posts: 273
Threads: 51
Joined: May 2002
Plasma knows everything. :lol: I bet you can't stump him. That should be a challenge in the challenge section.