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 -=-=-=- Thought for the day: Beware of Gods who cannot laugh...
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...