|
-
Nov 23rd, 2009, 03:27 AM
#25
Thread Starter
New Member
Re: VB6.0: MSComm gives me ascii character but i need single data type !!
Microsoft Visual Studio 2005 code is given below. I am not using Visual Studio because of some circumstances (as i mentioned before):
(Only serial code is included not whole)
The code below might help in converting it to VB6 (the difference is that it uses polling and i had done interrupt as i have to include some other code in future too.)
receive(i, j) = serialportx.ReadByte() ' Reads the byte
singlearray(k) = BitConverter.ToSingle(temp, 4 * k) ' converts the cosecutive bytes to single
(actually need to translate ReadByte() and ToSingle command in vb6)
'Code in Visual studio 2005 is
Dim receive(,) As Byte = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
Dim singlearray() As Single = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Dim temp() As Byte = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
'--------Loading Serial Port Form--------
If serialportx.IsOpen Then
serialportx.Close()
End If
Try
With serialportx 'setting serial comm. parameters
.PortName = "COM4"
.BaudRate = 115200
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
End With
serialportx.Open() 'opening serial port
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub serialPortX_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialportx.DataReceived
Dim i As Integer
Dim j As Integer
Dim k As Integer
If serialportx.BytesToRead > 0 Then
For i = 0 To 15
For j = 0 To 3
receive(i, j) = serialportx.ReadByte()
temp(j + i * 4) = receive(i, j)
Next
Next
For k = 0 To 15
singlearray(k) = BitConverter.ToSingle(temp, 4 * k)
Next
End If
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|