×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Turbo Basic Code Converted To Clarion. Need help.

Turbo Basic Code Converted To Clarion. Need help.

Turbo Basic Code Converted To Clarion. Need help.

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close