473,326 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

convert BASIC to VB.NET

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

Dec 11 '06 #1
2 2084
th**********@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.
Dec 11 '06 #2
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:
th**********@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.
Dec 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
3
by: Mark Kamoski | last post by:
Hi-- What is the difference between Convert.ToString(obj) and CType(obj, String)? (Assume obj is a variable of type Object.) Please advise. Thank you.
2
by: fabrice | last post by:
Hello I'm getting an error during a .vb file compilation. My command is : vbc /t:library /r:system.web.dll /r:system.dll /r:mscorlib.dll myFile.vb The error is :
7
by: Ish2000 | last post by:
Hello, I've a simple windows application and i want to be able to convert a csv file to xml. So far, i can browse for the csv file from the file structure and display in a textbox. I want to...
8
by: Prakash | last post by:
Hi Friends, Using Remoting concept, i have send WCHAR values from VC++.net applicaiton to C# applicaiton. In my C# application it is treated as unsigned shot. I need to convert it back to string...
5
by: Camille Petersen | last post by:
I have a rather old VisualBasic program which is included inside an Access *.mdb database. So I guess it is an VisualBasic and not and VBA program. Can I somehow automatically convert it into a...
6
by: Ken Fine | last post by:
This is a basic question. What is the difference between casting and using the Convert.ToXXX methods, from the standpoint of the compiler, in terms of performance, and in other ways? e.g. ...
10
by: =?Utf-8?B?Um95?= | last post by:
What is the way to have best performance to copy a byte to a value such as long? I use BitConverter.ToInt64(binary, offset) But the performace is not good enough. I need to have the best...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.