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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using MsComm32.ocx Need to send data with a STX end with ETX and a LRC

Status
Not open for further replies.

TrickyRick

Programmer
Mar 26, 2012
2
CA
Trying to communicate with a Credit card Machine using Com Port 1
Installed MSComm32.ocx in a Form No Problem
Need to send a string with STX ETX and a LRC Character
the data part is "10001^1^10002^1^10007^99^10022^65613^"
I have added a STX, ETX and CR LF and the LRC character which I think should be 7
so my entire string is TheStr = = CHR(2)+"10001^1^10002^1^10007^99^10022^65613^"+CHR(13)+CHR(10)+CHR(3)+CHR(55)

Doesn't work Anybody have any Ideas
 
Have you determined you are actually talking to the device?
Are you getting any sort of response from the machine?

I think you may also need to verify the data format. For instance, are you really supposed to transmit the '^' character or is it actually representing CTRL+1 as a field separator? Or is it itself a field separator?



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
The first act with COM is to set baud rate, data bits, parity, stop bits and then send the commands.

^ may also denote ESC = chr(27) or something else. Look out for the specifics of the notation. Devices differ very much and often don't come with such instructios and specifications. Do you have something official for your device, or are you just trying out what should work?

I would use Hyperterminal to test first, or putty or some other replacement for the missing Hyperterminal in Vista or later.

Bye, Olaf.



 
As Olaf has suggested above, the character ^ (ASCII Decimal 94) within a character string is NOT the same as an ESC (ASCII Decimal 27).
There are some recipient devices which 'interpret' them the same, but not all.

So:
"10001^1^10002^1^10007^99^10022^65613^"
might need to be
"10001" + CHR(27) + "1" + CHR(27) + "10002" <and so on...>

And since the LRC (Longitudinal Redundancy Check) is a calculated value, are you 100% certain that you are doing so correctly using the correct byte values?

Good Luck,
JRB-Bldr

 
1. Yes I believe I'm getting a response from the machine because if I don't issue a open port command I get an Error.

2. The ^ is actually the separator

3. I wasn't Sending the Baud Rate because I had set it up in the
Ole Control Properties

While I was sleeping I come up with the same thought as Olfdochke sending the settings first in case they were not getting set when the OLE Contol gets initialized. So I tried OleControl1.settings = "9600,7,e,1" which gave me an error Invalid property value However the sale amount of .99 came up on the machine.

I have the "9600,7,e,1" set in the properties of the OLE Control Box

4 I then just sent OleControl1.settings() and all my errors have gone away and everything appears to be working.

NOTE: I use the following code to generate the LRC character which is generated without the STX

cString = "10001^1^10002^1^10007^999^10022^65613^"+CHR(13)+CHR(10)+CHR(3)

LOCAL TheLRC, nChr

TheLRC = 0

FOR nChr = 1 TO LEN(cString)
TheLRC = BITAND(0xFF,BITXOR(TheLRC, ASC(SUBSTR(cString,nChr,1))))
ENDFOR

RETURN CHR(TheLRC)

And it is all work thanks for the Help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top