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

Turbo Basic Code Converted To Clarion. Need help.

Status
Not open for further replies.

Reaper2050

Programmer
May 25, 2012
12
Hi All,

The following is the Turbo Basic code:


locate 5,40:print " ";
getltr: 'Calling routine must supply curhose% and unitnumber%
'This routine returns lstam!,lvol! and lastppu
ltrtrouble%=0 'Ltrtrouble%<>0 is used to tell calling routine that
'fetch was not successful
'Trouble%=1 : Checksum error
' 2 : No REPLY NEXT word
' 3 : Incorrect number of words
' 4 : Transmission error
' 5 : No reply (open loop)
' 6 : Could not read totes
' 7 : Totes did not change
open "com1:4800,e,8,1" as #1
print #1,chr$(240+unitnumber%); 'FX X=unit number
delay 0.01
print #1,chr$(16*curhose%+6); 'Y6 Y=hose number
delay 0.01
print #1,chr$(176); 'B0 End of command
delay 0.15 'Wait for reply
buff%=loc(1) 'Length of input buffer
if buff%=0 then 'NO REPLY (OPEN LOOP)
ltrtrouble%=5
close #1
return
end if
on error goto stayalive2
recstrg$=input$(buff%,#1)
if buff%=23 then 'Xmitted plus received bytes
if mid$(recstrg$,4,1)=chr$(208+unitnumber%) then 'REPLY NEXT word
checksum%=0
for i=4 to 21 'Calculate checksum
checksum%=checksum%+(asc(mid$(recstrg$,i,1)) and 15)
next i
checksum%=checksum% and 15
sentsum%=asc(mid$(recstrg$,22,1)) and 15
if checksum%<>sentsum% then
ltrtrouble%=1
close #1
return
end if
close #1
ppu1=asc(mid$(recstrg$,6,1)) and 15
ppu2=asc(mid$(recstrg$,7,1)) and 15
ppu3=asc(mid$(recstrg$,8,1)) and 15
ppu4=asc(mid$(recstrg$,9,1)) and 15
money1=asc(mid$(recstrg$,10,1)) and 15
money2=asc(mid$(recstrg$,11,1)) and 15
money3=asc(mid$(recstrg$,12,1)) and 15
money4=asc(mid$(recstrg$,13,1)) and 15
money5=asc(mid$(recstrg$,14,1)) and 15
money6=asc(mid$(recstrg$,15,1)) and 15
volume1=asc(mid$(recstrg$,16,1)) and 15
volume2=asc(mid$(recstrg$,17,1)) and 15
volume3=asc(mid$(recstrg$,18,1)) and 15
volume4=asc(mid$(recstrg$,19,1)) and 15
volume5=asc(mid$(recstrg$,20,1)) and 15
volume6=asc(mid$(recstrg$,21,1)) and 15
lastppu=.01*ppu1+.1*ppu2+ppu3+10*ppu4
lstam!=.01*money1+.1*money2+money3+10*money4+100*money5+1000*money6
lvol!=.01*volume1+.1*volume2+volume3+10*volume4+100*volume5+1000*volume6
locate 5,40
print using "AMNT ####.## LIT ####.## PPU ##.##"; lstam!,lvol!,lastppu
return
else
ltrtrouble%=2
close #1
return
end if
else
ltrtrouble%=3
close #1
return
end if
recover2:
close #1
return

stayalive2:
ltrtrouble%=4
resume recover2
'***** END OF GET LAST TRANSACTION *****


I have converted it to Clarion, but when I get to this point in the routine, my checksum% and sentsum% doesn't match.

Can someone see if I am doing something wrong in my code?

Here is my Clarion code:


Loc:LUnitNumber = '1'
Loc:LCurHose = '4'
Loc:DataBuffer = CHR(240+Loc:LUnitNumber)
Loc:BytesSend = WritePort(PortID,Loc:DataBuffer,0)
sjSleep(100)
Loc:DataBuffer = CHR(16*Loc:LCurHose+6)
Loc:BytesSend = WritePort(PortID,Loc:DataBuffer,0)
sjSleep(100)
Loc:DataBuffer = CHR(176)
Loc:BytesSend = WritePort(PortID,Loc:DataBuffer,0)
sjSleep(150)
loc:BytesRead = ReadPort(PortId,loc:RXBuffer,0) !Length of Input Buffer
IF Len(Clip(Loc:RXBuffer)) = 0 THEN !OPEN LOOP
Loc:LLtrTrouble = 5
Glo:TestQ:BytesRead = loc:BytesRead
Glo:TestQ:RXBuffer = 'OPEN LOOP ==> GET LAST TRAN ROUTINE'
Glo:TestQ:BufferLen = Len(Clip(loc:RXBuffer))
Add(Glo:TestQ)
Display()
End
Loc:SRecStrg = Clip(Loc:RXBuffer)
IF Len(Clip(Loc:RXBuffer)) = 23 THEN
IF Sub(Loc:SRecStrg,4,1) = CHR(208+Loc:LUnitNumber) THEN !REPLY NEXT word
Loc:LCheckSum = 0
Loop Loc:LoopInteger = 4 To 21
Loc:LCheckSum = Loc:LCheckSum+(Val(Sub(Loc:SRecStrg,Loc:LoopInteger,1)) & 15)
End
Loc:LCheckSum = Loc:LCheckSum & 15
Loc:LSentSum = Val(Sub(Loc:SRecStrg,22,1)) & 15
Message('SentSum: ' & Loc:LSentsum & ' ' & 'CheckSum: ' & Loc:LCheckSum)
IF Loc:LCheckSum <> Loc:LSentSum THEN
Loc:LLtrTrouble = 1
Message('Trouble 1')
Else
Loc:Lppu1 = VAL(SUB(recstrg$,6,1)) & 15
Loc:Lppu2 = VAL(SUB(recstrg$,7,1)) & 15
Loc:Lppu3 = VAL(SUB(recstrg$,8,1)) & 15
Loc:Lppu4 = VAL(SUB(recstrg$,9,1)) & 15
Loc:Lmoney1 = VAL(SUB(recstrg$,10,1)) & 15
Loc:Lmoney2 = VAL(SUB(recstrg$,11,1)) & 15
Loc:Lmoney3 = VAL(SUB(recstrg$,12,1)) & 15
Loc:Lmoney4 = VAL(SUB(recstrg$,13,1)) & 15
Loc:Lmoney5 = VAL(SUB(recstrg$,14,1)) & 15
Loc:Lmoney6 = VAL(SUB(recstrg$,15,1)) & 15
Loc:Lvolume1 = VAL(SUB(recstrg$,16,1)) & 15
Loc:Lvolume2 = VAL(SUB(recstrg$,17,1)) & 15
Loc:Lvolume3 = VAL(SUB(recstrg$,18,1)) & 15
Loc:Lvolume4 = VAL(SUB(recstrg$,19,1)) & 15
Loc:Lvolume5 = VAL(SUB(recstrg$,20,1)) & 15
Loc:Lvolume6 = VAL(SUB(recstrg$,21,1)) & 15
Loc:Llastppu = .01 * Loc:Lppu1 + .1 * Loc:Lppu2 + Loc:Lppu3+10 * Loc:Lppu4
Loc:Llstam = .01 * Loc:Lmoney1 + .1 * Loc:Lmoney2 + Loc:Lmoney3+10 * Loc:Lmoney4 +100 * Loc:Lmoney5 + 1000*Loc:Lmoney6
Loc:Llvol = .01 * Loc:Lvolume1 + .1 * Loc:Lvolume2 + Loc:Lvolume3+10 * Loc:Lvolume4+100 * Loc:Lvolume5 + 1000*Loc:Lvolume6
Loc:LAmount = Loc:LIstam
Loc:LLitres = Loc:LLvol
Loc:LPpu = Loc:LLastPpu
Message('Amount: ' & Loc:LAmount & ' ' & 'Liters: ' & Loc:Llvol & ' ' & 'Price Per Unit: ' & Loc:LlastPpu)
End
Else
Loc:LLtrTrouble = 2
Message('Trouble 2')
End
Else
Loc:LltrTrouble = 3
Message('Trouble 3')
End


Thank you in advance.

Regards,
Adriaan Du Plessis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top