R232 SerialPort Communication
R232 SerialPort Communication
R232 SerialPort Communication
R232 SerialPort Communication
R232 SerialPort Communication
R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication
R232 SerialPort Communication R232 SerialPort Communication
R232 SerialPort Communication
Go Back  Xtreme Visual Basic Talk > > > R232 SerialPort Communication


Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2014, 06:37 AM
flashyjunior flashyjunior is offline
Newcomer
 
Join Date: Jun 2014
Posts: 2
Default R232 SerialPort Communication


Hi,
Can someone please assist me urgently to translate this vb.net piece of code into vb6 for me.

Thanks everyone
Please its urgent


Code:
Static SeqNum As Byte = 60

                Dim rtype As String = cboRecType.Text
                Dim MRC As String = txtMRC.Text
                Dim TIN As String = txtTIN.Text
                Dim RecNo As String = txtRecNo.Text
                Dim recDate As String = Format(Date.Now, "dd/MM/yyyy")
                Dim recTime As String = Format(Date:confused:.Now, "HH:mm:ss").ToString
                Dim RecDateTime As String = recDate & " " & recTime

                'Dim StringData As String = rtype & MRC & "," & TIN & "," & RecDateTime & "," & RecNo & ",0.00,18.00,0.00,0.00,11.00,12.00,0.00,0.00,0.00,1.83,0.00,0.00"
                Dim StringData As String = rtype & MRC & "," & TIN & "," & RecDateTime & "," & RecNo & ",0.00,18.00,0.00,0.00,00.00,4525.42,0.00,0.00,0.00,814.58,0.00,0.00"

                Dim DataLen As Byte = CByte(StringData.Length)
                Const HeaderLen As Byte = 4  'Preamble(01), Len, Seq, Cmd
                Const _1 As Byte = 1 'with Option Strict On, you can't do SeqNum += 1 'because 1 is not a byte, so we'll use the constant _1

                Dim leng As Byte = CByte(HeaderLen + DataLen + 32) ' +32 protocol specified bias 
                Dim btMessage(HeaderLen + DataLen + 6 - 1) As Byte '+ 6 for post amble, CRC and Terminator (- 1 because 0 based array)

                SeqNum += _1
                If SeqNum > 127 Then SeqNum = 32

                'set the other values here
                btMessage(0) = 1
                btMessage(1) = leng
                btMessage(2) = SeqNum 'sequence no 
                btMessage(3) = 198  'C6

                'get the string into a byte array
                Dim btData As Byte() = System.Text.Encoding.ASCII.GetBytes(StringData)
                'copy to the right position in the message
                Array.Copy(btData, 0, btMessage, 4, btData.Length)

                Dim ptr As Integer = HeaderLen + DataLen  'point to next byte (post amble) after header and data
                btMessage(ptr) = 5     'Post amble (summed as part of BCC, so we'll set it before BCC calc)

                'Getting ready to calc BCC
                Dim BCC As Integer = 0
                For i As Int32 = 1 To ptr  'sum from the second byte to and including the post amble byte
                    BCC = BCC + btMessage(i)
                Next

                btMessage(ptr + 1) = CByte(((BCC And &HF000) >> 12) + 48)
                btMessage(ptr + 2) = CByte(((BCC And &HF00) >> 8) + 48)
                btMessage(ptr + 3) = CByte(((BCC And &HF0) >> 4) + 48)
                btMessage(ptr + 4) = CByte((BCC And &HF) + 48)
                btMessage(ptr + 5) = 3 'terminator

                'send btMessage out the serial port here

                'ADRport.Encoding = System.Text.Encoding.GetEncoding(1252)
                ADRport.Write(btMessage, 0, btMessage.Length)

                TextBox1.Text = ADRport.ReadExisting()
Reply With Quote
  #2  
Old 06-12-2014, 06:56 AM
Flyguy's Avatar
FlyguyR232 SerialPort Communication Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,155
Default

No, that's not how this forum works.

We will try to help you with specific problems or coding question, but we don't rewrite portions of code for you.
Reply With Quote
  #3  
Old 06-12-2014, 07:49 AM
flashyjunior flashyjunior is offline
Newcomer
 
Join Date: Jun 2014
Posts: 2
Default Array Copy

Sorry Flyguy,
My apologies

I want to copy an array into a second array at the specific index in the second array.
I read about using the CopyMemory windows API but that doesnt give you the option to specify the sourceindex and the destination index in the second array

Can anyone help me out.

Code:
Private Declare Sub CopyMemory Lib "kernel32" _
    Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Reply With Quote
  #4  
Old 06-13-2014, 12:35 AM
Flyguy's Avatar
FlyguyR232 SerialPort Communication Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,155
Default

If you had 2 arrays of the same size (12 bytes) the syntax would be the following:
Code:
CopyMemory btDest(0), btSource(0), 12
If you want to copy 4 bytes from position 6 to location 2:
Code:
CopyMemory btDest(1), btSource(5), 4
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
R232 SerialPort Communication
R232 SerialPort Communication
R232 SerialPort Communication R232 SerialPort Communication
R232 SerialPort Communication
R232 SerialPort Communication
R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication R232 SerialPort Communication
R232 SerialPort Communication
R232 SerialPort Communication
 
R232 SerialPort Communication
R232 SerialPort Communication
 
-->