Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem when accessing COM1 with "Peek" & "out" statemen

Status
Not open for further replies.

BobTheMad

Programmer
Jun 11, 1999
81
0
0
US
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...
 
The method I use to set the port baud, stop-bits, etc is as follows

-=-=-=- 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...
 
My next question would be; Are you able to use another program such as ProCom+ for DOS on Com 3&4 successfully?
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
 
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 know it's a old thread, but I'm trying to talk to the Verifone 1000 pinpad and I always get a NAK. So I thought that my LRC maybe wrong. I hope you got it working and can help me out.

Kim Jensen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top