W
white0212
Unregistered / Unconfirmed
GUEST, unregistred user!
Option Explicit
Const SOH = 1
Const STX = 2
Const EOT = 4
Const ACK = &H6
Const NAK = &H15
Const CAN = &H18
Const CPMEOF = 26
Const TXBLKSIZE = 128
Const RXBLKSIZE = 128
'
Dim baud As Integer
Dim NOFFILE As String
Dim dfname As String
Dim id As Byte
Dim CHECKSUM As Byte, RUNNINGSUM As Long
Dim DELAYCON As Long
Dim abort As Integer
Dimdo
ing As Integer
Private Sub cmdAbort_Click()
If Notdo
ing then
Exit Sub
abort = True
MsgBox ("Action Aborted")
txtDebug = "ABORTED"
Call defocusabort
End Sub
Private Sub cmdBaud_Click()
baud = (baud + 1) Mod 3
If baud = 0 then
MSComm.Settings = "9600,n,8,1"
cmdBaud.Caption = "9600 baud"
else
If baud = 1 then
MSComm.Settings = "19200,n,8,1"
cmdBaud.Caption = "19200 baud"
else
MSComm.Settings = "4800,n,8,1"
cmdBaud.Caption = "4800 baud"
End If
End Sub
Private Sub cmdQuit_Click()
'Call WakeUp
'Call SENDID
'MSComm.Output = "3"
Do
Loop While MSComm.OutBufferCount <> 0
'
'MSComm.PortOpen = False
End
End Sub
Sub GetFileName()
If Right$(Dir1, 1) = "/" then
NOFFILE = Dir1 &
txtFileName
else
NOFFILE = Dir1 &
"/" &
txtFileName
End If
Debug.Print "getfilename - " &
NOFFILE
End Sub
Sub defocusabort()
cmdReceive.Enabled = True
cmdTransmit.Enabled = True
cmdQuit.Enabled = True
cmdAbort.Enabled = False
End Sub
Sub focusabort()
cmdReceive.Enabled = False
cmdTransmit.Enabled = False
cmdQuit.Enabled = False
cmdAbort.Enabled = True
cmdAbort.SetFocus
End Sub
Private Sub cmdReceive_Click()
Dim cfgFilename As String
Dim iIndex As Integer
Dim uIndex As Integer
Dim iSection As String
Dim KeyValue As String
CommonDialog1.InitDir = App.Path
CommonDialog1.ShowOpen
cfgFilename = CommonDialog1.filename
CommonDialog1.filename = ""
If (cfgFilename <> "") And (Len(cfgFilename) > 3) then
iSection = "Receive"
KeyValue = ReadINI(iSection, "Size", cfgFilename)
uIndex = CInt(KeyValue)
For iIndex = 1 To uIndex
KeyValue = ReadINI(iSection, iSection &
CStr(iIndex), cfgFilename)
NOFFILE = App.Path &
"/" &
KeyValue
dfname = KeyValue
Call Receive
Next
End If
'NOFFILE = App.Path &
"/88.txt"
'dfname = "11.txt"
'Call Receive
End Sub
Sub Receive()
Dim ch As String
'
Dim BYTECH As Byte
Dim I As Long
Dim BLOCKNOHI As Integer, BLOCKNOLO As Integer
Dim BLOCKNOCPL As Integer, PREVBLOCKNO As Integer
Dim CRCHI As Integer, CRCLO As Integer
Dim NOFBLOCK As Integer
Dim OUTFILE As Integer
'
Call OPenPort
Call WakeUp
'
Call focusabort
doing = True
abort = False
' flush input
txtDebug.Text = "RECEIVING..."
OUTFILE = FreeFile
On Error GoTo openfileerror
'Call GetFileName '// modified by noffile
Open NOFFILE For Random As #OUTFILE Len = 1
On Error GoTo 0
MSComm.InBufferCount = 0
' send ID
Call SENDID
If (doing = False) then
Exit Sub
' Send command
Call send1byte(&H31)
' send file name
'dfname = txtFileName '// modified by noffile
For I = 1 To Len(dfname)
Call send1byte(Asc(Mid$(dfname, I, 1)))
Next I
Call send1byte(0)
'
' wait sync
waitsync:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If ch = ChrB$(&H7F) then
GoTo startrece
End If
GoTo waitsync
'
startrece:
Call send1byte(Asc("C"))
'
NOFBLOCK = 0
PREVBLOCKNO = 0
BLOCKNOHI = 0
'
NEXTBLOCK:
waitheader:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If ch = ChrB$(EOT) then
Close #OUTFILE
txtDebug.Text = "FINISHED"
MsgBox ("End Receiving " &
NOFBLOCK &
" Blocks")
GoTo EXITSUB
End If
If ch = ChrB$(SOH) then
GoTo startrecedata
End If
GoTo waitheader
'
startrecedata:
NOFBLOCK = NOFBLOCK + 1
txtBlockNo.Text = Str$(NOFBLOCK)
GoSub GET1CH
BLOCKNOLO = AscB(ch)
GoSub GET1CH
BLOCKNOCPL = AscB(ch)
If BLOCKNOLO + BLOCKNOCPL <> 255 then
MsgBox ("WRONG CPL")
GoTo EXITSUB
End If
'
PREVBLOCKNO = PREVBLOCKNO + 1
If PREVBLOCKNO = 256 then
PREVBLOCKNO = 0
BLOCKNOHI = BLOCKNOHI + 1
End If
If PREVBLOCKNO <> BLOCKNOLO then
MsgBox ("NOT IN SEQ")
GoTo EXITSUB
End If
'
RUNNINGSUM = 0
For I = 1 To RXBLKSIZE
GoSub GET1CH
Put #OUTFILE, , AscB(ch)
RUNNINGSUM = (RUNNINGSUM + AscB(ch)) Mod 256
Next I
GoSub GET1CH
CHECKSUM = AscB(ch)
If CHECKSUM <> RUNNINGSUM then
MsgBox ("WRONG CHECKSUM" &
Str(RUNNINGSUM) &
Str(CHECKSUM))
End If
send1byte (ACK)
GoTo NEXTBLOCK
'
GET1CH:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
Return
End If
GoTo GET1CH
'
openfileerror:
MsgBox ("Error in Open File ")
EXITSUB:
Close #OUTFILE
Call closeport
do
ing = False
Call defocusabort
cmdReceive.SetFocus
Exit Sub
'
End Sub
Sub SENDID()
'id = Val(txtID)
If id < 1 Or id > 99 then
doing = False
Exit Sub
End If
Call send1byte(SOH)
Call send1byte(id)
End Sub
Sub send1byte(dbyte As Byte)
Dim bytBYTE(0 To 0) As Byte
bytBYTE(0) = dbyte
MSComm.Output = bytBYTE()
DoEvents
End Sub
Sub delay500ms()
Dim targtimer Asdo
uble
targtimer = Timer + 0.5
If targtimer >= 86400# then
targtimer = targtimer - 86400#
Do
Loop While Timer < targtimer
End Sub
Sub WakeUp()
MSComm.RTSEnable = True
Call delay500ms
MSComm.RTSEnable = False
Call delay500ms
End Sub
Sub OPenPort()
MSComm.PortOpen = True
cmdBaud.Enabled = False
End Sub
Sub closeport()
MSComm.PortOpen = False
cmdBaud.Enabled = True
End Sub
Private Sub cmdTransmit_Click()
Dim cfgFilename As String
Dim iIndex As Integer
Dim uIndex As Integer
Dim iSection As String
Dim KeyValue As String
CommonDialog1.InitDir = App.Path
CommonDialog1.ShowOpen
cfgFilename = CommonDialog1.filename
CommonDialog1.filename = ""
If (cfgFilename <> "") And (Len(cfgFilename) > 3) then
iSection = "Send"
KeyValue = ReadINI(iSection, "Size", cfgFilename)
uIndex = CInt(KeyValue)
For iIndex = 1 To uIndex
KeyValue = ReadINI(iSection, iSection &
CStr(iIndex), cfgFilename)
NOFFILE = App.Path &
"/" &
KeyValue
dfname = KeyValue
Call Transmit
Next
End If
'Debug.Print " start "
'Call Transmit
End Sub
Sub Transmit()
Dim NOFBLOCK As Long
Dim loffile As Long
Dim fnoin As Integer
Dim byteptr As Integer
'Dim c As Variant
Dim ch As String
Dim BLOCKNO As Integer
Dim CRCHI As Byte, CRCLO As Byte
Dim inblk() As Byte
Dim inblkFIXED(0 To TXBLKSIZE - 1) As Byte
Dim iptr As Integer, optr As Integer
Dim feedback As Integer
Dim CHFEEDBACK As String
Dim BLOCKNOHI As Byte, BLOCKNOLO As Byte
Dim BLOCKNOCPL As Byte
Dim TIMEOUT As Long
'
Dim I As Integer
doing = True
abort = False
txtDebug.Text = "OPENING FILE"
'Call GetFileName ' modified by kenneth
On Error GoTo openfileerror
fnoin = FreeFile
Open NOFFILE For Random As #fnoin Len = TXBLKSIZE
On Error GoTo 0
loffile = LOF(fnoin)
NOFBLOCK = (loffile - 1) / TXBLKSIZE + 1
txtDebug.Text = "NO. OF BLOCK =" &
Str$(NOFBLOCK)
' FLUSH INput
Call focusabort
Call OPenPort
Call WakeUp
MSComm.InBufferCount = 0
TIMEOUT = -1
' send ID
Call SENDID
If (doing = False) then
Exit Sub
' send command
Call send1byte(&H32)
' send file name
'dfname = txtFileName // modified by kenneth
'Debug.Print "transmit" &
dfname
For I = 1 To Len(dfname)
Call send1byte(Asc(Mid$(dfname, I, 1)))
Next I
Call send1byte(0)
Call delay500ms
'
SENDSYNC:
DoEvents
If abort then
GoTo EXITSUB
txtDebug.Text = "SENDING SYNC"
If MSComm.OutBufferCount = 0 then
send1byte (&H7F)
' TIMEOUT = TIMEOUT + 1
' If TIMEOUT Mod 10 = 0 then
Call DELAYms(100)
' End If
End If
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If AscB(ch) = AscB("C") then
GoTo STARTSEND
End If
txtDebug.Text = "SYNC NOT ACKNOWLEDGED"
GoTo SENDSYNC
'
STARTSEND:
txtDebug.Text = "SYNC ACKNOWLEDGED"
For BLOCKNO = 1 To NOFBLOCK
'
Get #fnoin, , inblkFIXED
inblk() = inblkFIXED
'GoSub conv
txtDebug.Text = "TRANSMIT HEADER"
txtBlockNo = Str$(BLOCKNO)
Call send1byte(SOH)
'BLOCKNOHI = BLOCKNO / 256
BLOCKNOLO = BLOCKNO Mod 256
Call send1byte(BLOCKNOLO)
Call send1byte(255 - BLOCKNOLO)
txtDebug.Text = "TRANSMIT DATA"
'DoEvents
MSComm.Output = inblk()
txtDebug.Text = "TRANSMIT CHECKSUM"
RUNNINGSUM = 0
For I = 0 To TXBLKSIZE - 1
RUNNINGSUM = (RUNNINGSUM + inblkFIXED(I)) Mod 256
Next I
CHECKSUM = RUNNINGSUM
Call send1byte(CHECKSUM)
'Call send1byte(CRCHI)
'Call send1byte(CRCLO)
do
Events
If abort then
GoTo EXITSUB
txtDebug = "WAIT ACK"
feedback = 0
do
do
Events
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
CHFEEDBACK = MSComm.Input
feedback = AscB(CHFEEDBACK)
End If
Loop While feedback <> ACK
txtDebug = " ACK RECEIVED"
Next BLOCKNO
send1byte (EOT)
txtDebug = "FINISHED"
MsgBox ("End of Transmission - " &
Str$(NOFBLOCK) &
" Blocks")
EXITSUB:
doing = False
Call defocusabort
cmdTransmit.SetFocus
Call closeport
Close #fnoin
Exit Sub
'
openfileerror:
MsgBox ("Error in Open File")
Exit Sub
'
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
txtFileName = ""
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
txtFileName = ""
End Sub
Private Sub File1_Click()
txtFileName = File1.filename
End Sub
Private Sub Form_ACTIVATE()
Dim OTIME As String
doing = False
' default 9600 baud
baud = 0
cmdAbort.Enabled = False
'
OTIME = Time$
Do
Loop While OTIME = Time$
'
OTIME = Time$
Do
DELAYCON = DELAYCON + 1
Loop While OTIME = Time$
'
DELAYCON = DELAYCON / 1000
End Sub
Sub DELAYms(DELAYCNT As Long)
Dim I As Long
Dim OTIME As String
For I = 1 To DELAYCNT * DELAYCON
OTIME = Time$
Next I
End Sub
Function ReadINI(Section, KeyName, filename As String) As String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), filename))
End Function
Const SOH = 1
Const STX = 2
Const EOT = 4
Const ACK = &H6
Const NAK = &H15
Const CAN = &H18
Const CPMEOF = 26
Const TXBLKSIZE = 128
Const RXBLKSIZE = 128
'
Dim baud As Integer
Dim NOFFILE As String
Dim dfname As String
Dim id As Byte
Dim CHECKSUM As Byte, RUNNINGSUM As Long
Dim DELAYCON As Long
Dim abort As Integer
Dimdo
ing As Integer
Private Sub cmdAbort_Click()
If Notdo
ing then
Exit Sub
abort = True
MsgBox ("Action Aborted")
txtDebug = "ABORTED"
Call defocusabort
End Sub
Private Sub cmdBaud_Click()
baud = (baud + 1) Mod 3
If baud = 0 then
MSComm.Settings = "9600,n,8,1"
cmdBaud.Caption = "9600 baud"
else
If baud = 1 then
MSComm.Settings = "19200,n,8,1"
cmdBaud.Caption = "19200 baud"
else
MSComm.Settings = "4800,n,8,1"
cmdBaud.Caption = "4800 baud"
End If
End Sub
Private Sub cmdQuit_Click()
'Call WakeUp
'Call SENDID
'MSComm.Output = "3"
Do
Loop While MSComm.OutBufferCount <> 0
'
'MSComm.PortOpen = False
End
End Sub
Sub GetFileName()
If Right$(Dir1, 1) = "/" then
NOFFILE = Dir1 &
txtFileName
else
NOFFILE = Dir1 &
"/" &
txtFileName
End If
Debug.Print "getfilename - " &
NOFFILE
End Sub
Sub defocusabort()
cmdReceive.Enabled = True
cmdTransmit.Enabled = True
cmdQuit.Enabled = True
cmdAbort.Enabled = False
End Sub
Sub focusabort()
cmdReceive.Enabled = False
cmdTransmit.Enabled = False
cmdQuit.Enabled = False
cmdAbort.Enabled = True
cmdAbort.SetFocus
End Sub
Private Sub cmdReceive_Click()
Dim cfgFilename As String
Dim iIndex As Integer
Dim uIndex As Integer
Dim iSection As String
Dim KeyValue As String
CommonDialog1.InitDir = App.Path
CommonDialog1.ShowOpen
cfgFilename = CommonDialog1.filename
CommonDialog1.filename = ""
If (cfgFilename <> "") And (Len(cfgFilename) > 3) then
iSection = "Receive"
KeyValue = ReadINI(iSection, "Size", cfgFilename)
uIndex = CInt(KeyValue)
For iIndex = 1 To uIndex
KeyValue = ReadINI(iSection, iSection &
CStr(iIndex), cfgFilename)
NOFFILE = App.Path &
"/" &
KeyValue
dfname = KeyValue
Call Receive
Next
End If
'NOFFILE = App.Path &
"/88.txt"
'dfname = "11.txt"
'Call Receive
End Sub
Sub Receive()
Dim ch As String
'
Dim BYTECH As Byte
Dim I As Long
Dim BLOCKNOHI As Integer, BLOCKNOLO As Integer
Dim BLOCKNOCPL As Integer, PREVBLOCKNO As Integer
Dim CRCHI As Integer, CRCLO As Integer
Dim NOFBLOCK As Integer
Dim OUTFILE As Integer
'
Call OPenPort
Call WakeUp
'
Call focusabort
doing = True
abort = False
' flush input
txtDebug.Text = "RECEIVING..."
OUTFILE = FreeFile
On Error GoTo openfileerror
'Call GetFileName '// modified by noffile
Open NOFFILE For Random As #OUTFILE Len = 1
On Error GoTo 0
MSComm.InBufferCount = 0
' send ID
Call SENDID
If (doing = False) then
Exit Sub
' Send command
Call send1byte(&H31)
' send file name
'dfname = txtFileName '// modified by noffile
For I = 1 To Len(dfname)
Call send1byte(Asc(Mid$(dfname, I, 1)))
Next I
Call send1byte(0)
'
' wait sync
waitsync:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If ch = ChrB$(&H7F) then
GoTo startrece
End If
GoTo waitsync
'
startrece:
Call send1byte(Asc("C"))
'
NOFBLOCK = 0
PREVBLOCKNO = 0
BLOCKNOHI = 0
'
NEXTBLOCK:
waitheader:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If ch = ChrB$(EOT) then
Close #OUTFILE
txtDebug.Text = "FINISHED"
MsgBox ("End Receiving " &
NOFBLOCK &
" Blocks")
GoTo EXITSUB
End If
If ch = ChrB$(SOH) then
GoTo startrecedata
End If
GoTo waitheader
'
startrecedata:
NOFBLOCK = NOFBLOCK + 1
txtBlockNo.Text = Str$(NOFBLOCK)
GoSub GET1CH
BLOCKNOLO = AscB(ch)
GoSub GET1CH
BLOCKNOCPL = AscB(ch)
If BLOCKNOLO + BLOCKNOCPL <> 255 then
MsgBox ("WRONG CPL")
GoTo EXITSUB
End If
'
PREVBLOCKNO = PREVBLOCKNO + 1
If PREVBLOCKNO = 256 then
PREVBLOCKNO = 0
BLOCKNOHI = BLOCKNOHI + 1
End If
If PREVBLOCKNO <> BLOCKNOLO then
MsgBox ("NOT IN SEQ")
GoTo EXITSUB
End If
'
RUNNINGSUM = 0
For I = 1 To RXBLKSIZE
GoSub GET1CH
Put #OUTFILE, , AscB(ch)
RUNNINGSUM = (RUNNINGSUM + AscB(ch)) Mod 256
Next I
GoSub GET1CH
CHECKSUM = AscB(ch)
If CHECKSUM <> RUNNINGSUM then
MsgBox ("WRONG CHECKSUM" &
Str(RUNNINGSUM) &
Str(CHECKSUM))
End If
send1byte (ACK)
GoTo NEXTBLOCK
'
GET1CH:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
Return
End If
GoTo GET1CH
'
openfileerror:
MsgBox ("Error in Open File ")
EXITSUB:
Close #OUTFILE
Call closeport
do
ing = False
Call defocusabort
cmdReceive.SetFocus
Exit Sub
'
End Sub
Sub SENDID()
'id = Val(txtID)
If id < 1 Or id > 99 then
doing = False
Exit Sub
End If
Call send1byte(SOH)
Call send1byte(id)
End Sub
Sub send1byte(dbyte As Byte)
Dim bytBYTE(0 To 0) As Byte
bytBYTE(0) = dbyte
MSComm.Output = bytBYTE()
DoEvents
End Sub
Sub delay500ms()
Dim targtimer Asdo
uble
targtimer = Timer + 0.5
If targtimer >= 86400# then
targtimer = targtimer - 86400#
Do
Loop While Timer < targtimer
End Sub
Sub WakeUp()
MSComm.RTSEnable = True
Call delay500ms
MSComm.RTSEnable = False
Call delay500ms
End Sub
Sub OPenPort()
MSComm.PortOpen = True
cmdBaud.Enabled = False
End Sub
Sub closeport()
MSComm.PortOpen = False
cmdBaud.Enabled = True
End Sub
Private Sub cmdTransmit_Click()
Dim cfgFilename As String
Dim iIndex As Integer
Dim uIndex As Integer
Dim iSection As String
Dim KeyValue As String
CommonDialog1.InitDir = App.Path
CommonDialog1.ShowOpen
cfgFilename = CommonDialog1.filename
CommonDialog1.filename = ""
If (cfgFilename <> "") And (Len(cfgFilename) > 3) then
iSection = "Send"
KeyValue = ReadINI(iSection, "Size", cfgFilename)
uIndex = CInt(KeyValue)
For iIndex = 1 To uIndex
KeyValue = ReadINI(iSection, iSection &
CStr(iIndex), cfgFilename)
NOFFILE = App.Path &
"/" &
KeyValue
dfname = KeyValue
Call Transmit
Next
End If
'Debug.Print " start "
'Call Transmit
End Sub
Sub Transmit()
Dim NOFBLOCK As Long
Dim loffile As Long
Dim fnoin As Integer
Dim byteptr As Integer
'Dim c As Variant
Dim ch As String
Dim BLOCKNO As Integer
Dim CRCHI As Byte, CRCLO As Byte
Dim inblk() As Byte
Dim inblkFIXED(0 To TXBLKSIZE - 1) As Byte
Dim iptr As Integer, optr As Integer
Dim feedback As Integer
Dim CHFEEDBACK As String
Dim BLOCKNOHI As Byte, BLOCKNOLO As Byte
Dim BLOCKNOCPL As Byte
Dim TIMEOUT As Long
'
Dim I As Integer
doing = True
abort = False
txtDebug.Text = "OPENING FILE"
'Call GetFileName ' modified by kenneth
On Error GoTo openfileerror
fnoin = FreeFile
Open NOFFILE For Random As #fnoin Len = TXBLKSIZE
On Error GoTo 0
loffile = LOF(fnoin)
NOFBLOCK = (loffile - 1) / TXBLKSIZE + 1
txtDebug.Text = "NO. OF BLOCK =" &
Str$(NOFBLOCK)
' FLUSH INput
Call focusabort
Call OPenPort
Call WakeUp
MSComm.InBufferCount = 0
TIMEOUT = -1
' send ID
Call SENDID
If (doing = False) then
Exit Sub
' send command
Call send1byte(&H32)
' send file name
'dfname = txtFileName // modified by kenneth
'Debug.Print "transmit" &
dfname
For I = 1 To Len(dfname)
Call send1byte(Asc(Mid$(dfname, I, 1)))
Next I
Call send1byte(0)
Call delay500ms
'
SENDSYNC:
DoEvents
If abort then
GoTo EXITSUB
txtDebug.Text = "SENDING SYNC"
If MSComm.OutBufferCount = 0 then
send1byte (&H7F)
' TIMEOUT = TIMEOUT + 1
' If TIMEOUT Mod 10 = 0 then
Call DELAYms(100)
' End If
End If
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If AscB(ch) = AscB("C") then
GoTo STARTSEND
End If
txtDebug.Text = "SYNC NOT ACKNOWLEDGED"
GoTo SENDSYNC
'
STARTSEND:
txtDebug.Text = "SYNC ACKNOWLEDGED"
For BLOCKNO = 1 To NOFBLOCK
'
Get #fnoin, , inblkFIXED
inblk() = inblkFIXED
'GoSub conv
txtDebug.Text = "TRANSMIT HEADER"
txtBlockNo = Str$(BLOCKNO)
Call send1byte(SOH)
'BLOCKNOHI = BLOCKNO / 256
BLOCKNOLO = BLOCKNO Mod 256
Call send1byte(BLOCKNOLO)
Call send1byte(255 - BLOCKNOLO)
txtDebug.Text = "TRANSMIT DATA"
'DoEvents
MSComm.Output = inblk()
txtDebug.Text = "TRANSMIT CHECKSUM"
RUNNINGSUM = 0
For I = 0 To TXBLKSIZE - 1
RUNNINGSUM = (RUNNINGSUM + inblkFIXED(I)) Mod 256
Next I
CHECKSUM = RUNNINGSUM
Call send1byte(CHECKSUM)
'Call send1byte(CRCHI)
'Call send1byte(CRCLO)
do
Events
If abort then
GoTo EXITSUB
txtDebug = "WAIT ACK"
feedback = 0
do
do
Events
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
CHFEEDBACK = MSComm.Input
feedback = AscB(CHFEEDBACK)
End If
Loop While feedback <> ACK
txtDebug = " ACK RECEIVED"
Next BLOCKNO
send1byte (EOT)
txtDebug = "FINISHED"
MsgBox ("End of Transmission - " &
Str$(NOFBLOCK) &
" Blocks")
EXITSUB:
doing = False
Call defocusabort
cmdTransmit.SetFocus
Call closeport
Close #fnoin
Exit Sub
'
openfileerror:
MsgBox ("Error in Open File")
Exit Sub
'
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
txtFileName = ""
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
txtFileName = ""
End Sub
Private Sub File1_Click()
txtFileName = File1.filename
End Sub
Private Sub Form_ACTIVATE()
Dim OTIME As String
doing = False
' default 9600 baud
baud = 0
cmdAbort.Enabled = False
'
OTIME = Time$
Do
Loop While OTIME = Time$
'
OTIME = Time$
Do
DELAYCON = DELAYCON + 1
Loop While OTIME = Time$
'
DELAYCON = DELAYCON / 1000
End Sub
Sub DELAYms(DELAYCNT As Long)
Dim I As Long
Dim OTIME As String
For I = 1 To DELAYCNT * DELAYCON
OTIME = Time$
Next I
End Sub
Function ReadINI(Section, KeyName, filename As String) As String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), filename))
End Function