Home All Groups Group Topic Archive Search About

convert BASIC to VB.NET

Author
11 Dec 2006 4:49 PM
thecamisland
I'm trying to communicate with Durant Ambassador counter through serial
port. All I have is an old piece of BASIC code. I have managed to
convert a portion of this old BASIC code to VB6 and I can send commands
to the counter but I don't get any response from counter and I don't
know why. Does anybody have any idea what I am doing wrong? Below you
can find original BASIC code and my VB6 code. I would appreciate any
suggestions, samples, anything...

--- BASIC CODE ---

100 REM *** INITIALIZE INPUT ***
110 DEFINT A - Z
120 DEF SEG = &HO40
130 CB = PEEK(1) * &H100 + PEEK(0)
135 DEF SEG
140 MSR = CB + 6
150 LSR = CB + 5
160 MCR = CB + 4
170 RSTON = 8 + 2 + 1 : RTSOFF = 8 + 1
180 OPEN "COM1:19200,N,8,1,RS" AS #1
190 ON TIMER(1) GOSUB 450
200 INPUT "ENTER COMMAND >", A$
210 REM *** CALC CHECKSUM ***
220 CS = 0
230 R$ = ""
240 FOR X = 1 TO LEN(A$)
250 CS = CS + ASC(MID$(A$, X, 1))
260 NEXT X
270 CS = CS AND 255
280 C$ = HEX$(CS)
290 IF CS < 16 THEN CS$ = "0" + CS$
300 T$ = ">" + A$ + CS$ : PRINT T$
310 REM *** RTS CONTROL AND SEND ***
320 OUT MCR, RSTON
330 PRINT #1, T$
340 IF INP(LSR) <> &H60 THEN 340
350 OUT MCR, RTSOFF
360 REM *** GET RESPONSE ***
370 TIMER ON
380 IF LOC(1) = 0 THEN 380
390 R$ = R$ + INPUT$(LOC(1), #1)
400 TIMER OFF
410 IF RIGHT$(R$, 1) <> CHR$(13) THEN 370
420 PRINT R$
430 GOTO 200
440 REM *** NO RESPONSE ROUTINE ***
450 PRINT "NO RESPONSE" : PRINT
460 TIMER OFF : RETURN 200

--- VB6 CODE ---

Sub InitConn()
  With MSComm1
    'make sure the serial port is not open (by this program)
    If .PortOpen Then .PortOpen = False
    'set the active serial port
    .CommPort = 1
    'set the badurate,parity,databits,stopbits for the connection
    .Settings = "1200,N,8,1"
    'set the DRT and RTS flags
    '.DTREnable = True
    '.RTSEnable = True
    '.DTREnable = False
    '.Handshaking = comNone
    'enable the oncomm event for every reveived character
    '.RThreshold = 1
    'disable the oncomm event for send characters
    '.SThreshold = 0
    'open the serial port
    .PortOpen = True
     Text2.Text = "Connected to COM port."
  End With 'MSComm1
End Sub

Function CalcSum(strCommand As String) As String

Dim btCount As Byte
Dim intChSum As Integer

For btCount = 1 To Len(strCommand)
  intChSum = intChSum + Asc(Mid(strCommand, btCount, 1))
Next btCount

intChSum = intChSum And 255

CalcSum = Hex(intChSum)

End Function

Private Sub Command1_Click()
Dim strOutput As String
strOutput = ">" & Text1.Text & CalcSum(Text1.Text) & vbCr
Label1.Caption = CalcSum(Text1.Text)
   With MSComm1
    'make sure the serial port is open
    If .PortOpen = False Then .PortOpen = True
    'send the data (including a tailing carriage return as often
needed)
    .Output = strOutput
    Text2.Text = strOutput
  End With 'MSComm1
End Sub

Private Sub Form_Load()
InitConn
End Sub

Private Sub MSComm1_OnComm()
  With MSComm1
    'test for incoming event
    Select Case .CommEvent
      Case comEvReceive
        'display incoming event data to displaying textbox
        Text2.Text = ""
        Text2.Text = .Input
    End Select
  End With 'MSComm1
End Sub

Author
11 Dec 2006 5:05 PM
Spam Catcher
thecamisl***@yahoo.com wrote in news:1165855778.962132.58470@
79g2000cws.googlegroups.com:

> I'm trying to communicate with Durant Ambassador counter through serial
> port. All I have is an old piece of BASIC code. I have managed to
> convert a portion of this old BASIC code to VB6 and I can send commands
> to the counter but I don't get any response from counter and I don't
> know why. Does anybody have any idea what I am doing wrong? Below you
> can find original BASIC code and my VB6 code. I would appreciate any
> suggestions, samples, anything...

Do you have a port sniffer? Perhaps you can include the conversation
between the Basic App -> Counter. That would help alot in rewriting the
code.
Author
11 Dec 2006 5:56 PM
thecamisland
I downloaded Advanced Serial Port Monitor from net and I can't receive
data from the counter unless RS-485 interface mode is on. How should I
change my VB code to be able to communicate through RS-485 interface?


Spam Catcher wrote:
Show quoteHide quote
> thecamisl***@yahoo.com wrote in news:1165855778.962132.58470@
> 79g2000cws.googlegroups.com:
>
> > I'm trying to communicate with Durant Ambassador counter through serial
> > port. All I have is an old piece of BASIC code. I have managed to
> > convert a portion of this old BASIC code to VB6 and I can send commands
> > to the counter but I don't get any response from counter and I don't
> > know why. Does anybody have any idea what I am doing wrong? Below you
> > can find original BASIC code and my VB6 code. I would appreciate any
> > suggestions, samples, anything...
>
> Do you have a port sniffer? Perhaps you can include the conversation
> between the Basic App -> Counter. That would help alot in rewriting the
> code.