tredekka13
Programmer
Hello,
I've placed the message below in the QBasic section, because I saw a related post there, but I'm coding in VB so I thought maybe someone here may be able to help.
Information from QBasic section -->
-=-=-=- 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 -=-=-=-
Message I placed in the QBasic section -->
I'm not sure this is the correct place, but I've been working on this for awhile and cannot discover my error. Similar to BobTheMad, I've been working on using a pin pad for a non-commerce application (ie using it for simple input) and I'm programming in VB 6. The problem is I don't know if I have my LRC algorithm incorrect or if it's a problem in the code.
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.
I've placed the message below in the QBasic section, because I saw a related post there, but I'm coding in VB so I thought maybe someone here may be able to help.
Information from QBasic section -->
-=-=-=- 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 -=-=-=-
Message I placed in the QBasic section -->
I'm not sure this is the correct place, but I've been working on this for awhile and cannot discover my error. Similar to BobTheMad, I've been working on using a pin pad for a non-commerce application (ie using it for simple input) and I'm programming in VB 6. The problem is I don't know if I have my LRC algorithm incorrect or if it's a problem in the code.
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.