problem when accessing COM1 with "Peek" & "out" statemen
problem when accessing COM1 with "Peek" & "out" statemen
(OP)
Hey all. I am re-writing an application that is going to access a PINPad device through one of the serial ports. I am having something less than success. By that I mean that the device does not seem to be receiving the data I am sending. I am posting my test-app below, anyone have any ideas on where I went wrong?
Thanks in advance
-=-=-=- BEGIN CODE EXAMPLE -=-=-=-
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
' TestPIN.bas
' Test program for communicating with a PINPad
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CLS
DIM PortAdd
DEF SEG = 0
PortAdd = PEEK(&H400) + 256& * PEEK(&H401) 'For COM1
DEF SEG
LOCATE 2, 1
PRINT "PortAdd: ", PortAdd
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Packet$ = ""
Char$ = CHR$(15)
Packet$ = Packet$ + Char$
Char$ = "0"
Packet$ = Packet$ + Char$
Char$ = "1"
Packet$ = Packet$ + Char$
Char$ = "0"
Packet$ = Packet$ + Char$
Char$ = "1"
Packet$ = Packet$ + Char$
Char$ = CHR$(14)
Packet$ = Packet$ + Char$
'*** Get LRC
Char$ = LRC$(Packet$)
Packet$ = Packet$ + Char$
PRINT "Packet$: ", Packet$
FOR x = 1 TO LEN(Packet$)
OUT PortAdd, ASC(MID$(Packet$, x, 1))
Out$ = " " + STR$(ASC(MID$(Packet$, x, 1)))
PRINT Out$
NEXT x
DEF SEG
END
FUNCTION LRC$ (Packet$)
'****************************************************************************
' Name: LRC$ *
' Purpose: Calculates and appends the LRC (error check character) to *
' the communications packet. *
' *
' On Entry: Packet$ Communications packet to append LRC char *
' *
' On Return: LRC$ Longitudinal Redundancy Check character *
'****************************************************************************
FOR x% = 2 TO LEN(Packet$) ' Each character
Calc% = Calc% XOR ASC(MID$(Packet$, x%, 1)) ' Calculate 'XOR'
NEXT x% ' Next character
LRC$ = CHR$(Calc%) ' Return LRC
END FUNCTION
-=-=-=- END CODE EXAMPLE -=-=-=-
Thanks in advance
-=-=-=- BEGIN CODE EXAMPLE -=-=-=-
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
' TestPIN.bas
' Test program for communicating with a PINPad
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CLS
DIM PortAdd
DEF SEG = 0
PortAdd = PEEK(&H400) + 256& * PEEK(&H401) 'For COM1
DEF SEG
LOCATE 2, 1
PRINT "PortAdd: ", PortAdd
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Packet$ = ""
Char$ = CHR$(15)
Packet$ = Packet$ + Char$
Char$ = "0"
Packet$ = Packet$ + Char$
Char$ = "1"
Packet$ = Packet$ + Char$
Char$ = "0"
Packet$ = Packet$ + Char$
Char$ = "1"
Packet$ = Packet$ + Char$
Char$ = CHR$(14)
Packet$ = Packet$ + Char$
'*** Get LRC
Char$ = LRC$(Packet$)
Packet$ = Packet$ + Char$
PRINT "Packet$: ", Packet$
FOR x = 1 TO LEN(Packet$)
OUT PortAdd, ASC(MID$(Packet$, x, 1))
Out$ = " " + STR$(ASC(MID$(Packet$, x, 1)))
PRINT Out$
NEXT x
DEF SEG
END
FUNCTION LRC$ (Packet$)
'****************************************************************************
' Name: LRC$ *
' Purpose: Calculates and appends the LRC (error check character) to *
' the communications packet. *
' *
' On Entry: Packet$ Communications packet to append LRC char *
' *
' On Return: LRC$ Longitudinal Redundancy Check character *
'****************************************************************************
FOR x% = 2 TO LEN(Packet$) ' Each character
Calc% = Calc% XOR ASC(MID$(Packet$, x%, 1)) ' Calculate 'XOR'
NEXT x% ' Next character
LRC$ = CHR$(Calc%) ' Return LRC
END FUNCTION
-=-=-=- END CODE EXAMPLE -=-=-=-
Thought for the day: Beware of Gods who cannot laugh...
RE: problem when accessing COM1 with "Peek" & "out" statemen
Kim_Christensen@telus.net
http://www3.bc.sympatico.ca/Kim_Christensen/index.html
RE: problem when accessing COM1 with "Peek" & "out" statemen
-=-=-=- BEGIN CODE EXAMPLE -=-=-=-
Open$ = "COM" + LTRIM$(STR$(Port)) + ": 1200,E,7,1,BIN,CD0,CS0,DS0,OP0,RS,TB2048,RB2048"
OPEN Open$ FOR RANDOM AS #1
CLOSE #1
-=-=-=- END CODE EXAMPLE -=-=-=-
The program works just fine when accessing the two ports that are hard-wired into the motherboard. The problem comes when attmempting to access the other ports (com 3&4) that are creted by the PCI serial card.
Thought for the day: Beware of Gods who cannot laugh...
RE: problem when accessing COM1 with "Peek" & "out" statemen
Also, when you boot up the computer, does the BIOS indicate that it sees all four COM ports? I ask this because the BIOS may not be recognizing those ports and your PEEK method is reading this BIOS data area. Another possibility is that your OS (Such as Win95 etc) is reconfiguring the PnP devices so that it no longer matches the info in the BIOS data area.
Try looking in the device manager and comparing the data there to what your program is "peeking at"
If none of the above helps, get a 2nd computer and connect it to the offending port using a null modem cable to monitor what is happening.
Kim_Christensen@telus.net
http://www3.bc.sympatico.ca/Kim_Christensen/index.html
RE: problem when accessing COM1 with "Peek" & "out" statemen
QB can't access COM3 and 4 through OPEN, unless
you remap them to COM1 and 2.
http://www.fys.ruu.nl/~bergmann/com3.bas
RE: problem when accessing COM1 with "Peek" & "out" statemen
In Bob's ex. he sends:
chr(15) 0 1 1 0 chr(14)
What I would like to know is what is the valid LRC? In his algorithm it appears he ignores the "Shift In" byte when calculating the LRC. Why?
Also, I'm not even trying to go to an odd port like COM3 or COM4, but COM2.
Thanx for any replies.
tredekka13
PS If anyone would like me to e-mail them a copy of the VB code please e-mail me at tredekka@yahoo.com and I will send it to them yesterday. I'm very frustrated at this point.
RE: problem when accessing COM1 with "Peek" & "out" statemen
Kim Jensen