Vb 2003 Framework 1.1

A

Armin Zingler

cmdolcet69 said:
armin my appologies.... I have figure out that last problem i was
posting, however a funny issue poped up
in my code below how can i show me Len as 08 and my Cmd as 02. when
it displays in the messagebox it shows
up as a 2 and a single 8 i need it to show as a 02 and 08 also when
i display my pmsg it will only display 1 0 and not both zero

Format them like the other values using the "X2" format.

BTW, if you need to convert only one value into a string, you can use

len.ToString("X2")

instead of using String.Format.


Armin
 
C

cmdolcet69

Format them like the other values using the "X2" format.

BTW, if you need to convert only one value into a string, you can use

len.ToString("X2")

instead of using String.Format.

Armin- Hide quoted text -

- Show quoted text -

well te way you showed me i like the most, however if you look at the
code when my message box is dislayed it cuts off the other 0's in the
message box
 
A

Armin Zingler

cmdolcet69 said:
well te way you showed me i like the most, however if you look at
the code when my message box is dislayed it cuts off the other 0's
in the message box

I can't test you code because some declarations are missing, and it can not
be compiled. You should enable Option Strict to find programming faults ASAP
and to get aware of conversions that have to be done.

Though, I don't see the problem. After making it compilable, it does work by
using the ToString function:

pmsg(0) = Len.ToString("X2")
pmsg(1) = Cmd.ToString("X2")

No zeros are missing. Neither with pmsg(0) and pmsg(1), nor with all other
pmsg(n).


Armin
 
C

cmdolcet69

Format them like the other values using the "X2" format.

BTW, if you need to convert only one value into a string, you can use

len.ToString("X2")

instead of using String.Format.

Armin- Hide quoted text -

- Show quoted text -

I think it has somthing to do with the following declaration:
Public Shared pmsg As Byte() = New Byte(24) {}
i declare my pmsg as byte
is this correct???
 
A

Armin Zingler

cmdolcet69 said:
I think it has somthing to do with the following declaration: Public
Shared pmsg As Byte() = New Byte(24) {}
i declare my pmsg as byte
is this correct???

No!

You want to store a formatted string. How can you expect you can store a
String in a Byte variable?

Did you enable Option Strict meanwhile? You should do it.

The basics still didn't change:

<quote>
- An Integer (System.Int32) is made of 4 Bytes.

- You get the single bytes into an array by using BitConverter.GetBytes

- Bytes are stored as binary digits. They don't have a Decimal nor a
Hexadecimal format.

- You can convert an Integer value into a string in different formats,
usually Decimal or Hexadecimal. Use the ToString function to do this. The
default is Decimal, otherwise use "X8" as the format string.

- You can convert a string, containing a number in hex format, into an
Integer value by using "Convert.ToInt32(TheString, 16)"
</quote>

Currently, there is nothing new I can add.



Armin
 
C

cmdolcet69

No!

You want to store a formatted string. How can you expect you can store a
String in a Byte variable?

Did you enable Option Strict meanwhile? You should do it.

The basics still didn't change:

<quote>
- An Integer (System.Int32) is made of 4 Bytes.

- You get the single bytes into an array by using BitConverter.GetBytes

- Bytes are stored as binary digits. They don't have a Decimal nor a
Hexadecimal format.

- You can convert an Integer value into a string in different formats,
usually Decimal or Hexadecimal. Use the ToString function to do this. The
default is Decimal, otherwise use "X8" as the format string.

- You can convert a string, containing a number in hex format, into an
Integer value by using "Convert.ToInt32(TheString, 16)"
</quote>

Currently, there is nothing new I can add.

Armin- Hide quoted text -

- Show quoted text -

Armin, i have modified the program so that i pass in constant string
value that i figured out using a calculator i converted there binary
rep to hex
does the comm1.output make sense?.
my sdata is a string which i should get back some notice from the
micro, however i get nothing. i use the string type "1c" which is
converted from the decimal passord value of 11548. i break this up
into two string that are suppose to represent two bytes. I think this
should work but im not getting anything from my micro???


Public Sub GetIndicator_Info()
Dim Len As Byte = &H6
Dim Cmd As Byte = &H7
Dim loPass As String = "1C"
Dim hiPass As String = "2D"
Dim CRChi As String = "30"
Dim CRClo As String = "82"

'send command to microcontroller
comm1.Output = ((BMS & Len + Cmd + loPass + hiPass + CRClo +
CRChi))


'view what the microcontroller sends back
sData = comm1.Input ' Get data (2 bytes)
End Sub
 
A

Armin Zingler

cmdolcet69 said:
Armin, i have modified the program so that i pass in constant string
value that i figured out using a calculator i converted there binary
rep to hex
does the comm1.output make sense?.
my sdata is a string which i should get back some notice from the
micro, however i get nothing. i use the string type "1c" which is
converted from the decimal passord value of 11548. i break this up
into two string that are suppose to represent two bytes. I think
this should work but im not getting anything from my micro???


Public Sub GetIndicator_Info()
Dim Len As Byte = &H6
Dim Cmd As Byte = &H7
Dim loPass As String = "1C"
Dim hiPass As String = "2D"
Dim CRChi As String = "30"
Dim CRClo As String = "82"

'send command to microcontroller
comm1.Output = ((BMS & Len + Cmd + loPass + hiPass + CRClo +
CRChi))


'view what the microcontroller sends back
sData = comm1.Input ' Get data (2 bytes)
End Sub


Even if I switch Option Strict Off to be able to compile the code, I get a
runtime error in the line "BMS & ...".

Anyways, I don't know the protocol/format that has to be used to communicate
with the device, therefore I can not evaluate whether the code is correct.
Maybe the byte order is incorrect, or it expects the bytes as bytes and not
as hex values, or Len and Cmd must have leading zeros, or or.... Do you
have a link to the protocol documentation?

So, all I can say:
- Use Option Strict On
- To concatenate Strings, use the & operator (not the + operator). Note that
it converts numeric operands to the decimal string representation before
concatenation.



Armin
 
C

cmdolcet69

Even if I switch Option Strict Off to be able to compile the code, I get a
runtime error in the line "BMS & ...".

Anyways, I don't know the protocol/format that has to be used to communicate
with the device, therefore I can not evaluate whether the code is correct.
Maybe the byte order is incorrect, or it expects the bytes as bytes and not
as hex values, or Len and Cmd must have leading zeros, or or.... Do you
have a link to the protocol documentation?

So, all I can say:
- Use Option Strict On
- To concatenate Strings, use the & operator (not the + operator). Note that
it converts numeric operands to the decimal string representation before
concatenation.

Armin- Hide quoted text -

- Show quoted text -

Armin how can i get you a link ? I dont think i can attach a document
any ideas?
 
A

Armin Zingler

cmdolcet69 said:
Armin how can i get you a link ? I dont think i can attach a
document any ideas?

I thought you know the manufacturer of the device and you can find a manual
on his web site and post the link here. But much more important is that
/you/ have access to the required docs. If you have problems in
understanding the protocol documentation you should ask someone who can
assist you with that, or give the task to someone who can handle it.

We can still help you in realizing the implementation in VB. Did you change
the code by using Option Strict On and the "&" operator?


Armin
 
C

cmdolcet69

I thought you know the manufacturer of the device and you can find a manual
on his web site and post the link here. But much more important is that
/you/ have access to the required docs. If you have problems in
understanding the protocol documentation you should ask someone who can
assist you with that, or give the task to someone who can handle it.

We can still help you in realizing the implementation in VB. Did you change
the code by using Option Strict On and the "&" operator?

Armin- Hide quoted text -

- Show quoted text -

Yes i did change the + to &. To get the whole story we had anothe
company manfacture the micro and everything else. Im doing a vb
interface so that i can program it. We came out yesterday is now we
need to send out a delay of 5ms after each byte so that the micro can
process. Can i send you the protocol/format document somehow?
 
A

Armin Zingler

cmdolcet69 said:
Yes i did change the + to &.

Did you also enable Option Strict?
To get the whole story we had anothe
company manfacture the micro and everything else. Im doing a vb
interface so that i can program it. We came out yesterday is now we
need to send out a delay of 5ms after each byte so that the micro
can process. Can i send you the protocol/format document somehow?

Reply per mail. Replace "nospam" by "no_spam". Please include the
information where exactly the information can be found
(page). I don't know when I will have the time to have a look.


Armin
 
C

cmdolcet69

Did you also enable Option Strict?


Reply per mail. Replace "nospam" by "no_spam". Please include the
information where exactly the information can be found
(page). I don't know when I will have the time to have a look.

Armin- Hide quoted text -

- Show quoted text -

Armin before i send the document can you help me out on this for
loop .when i do the following loop and code for the initial loop it
will
break and give me an error saying "property value is not valid"
I need to send the byte commands over one at a time with a 5ms
delay....

Dim i As Integer
Dim Packet(5) As Byte
Packet(0) = 6
Packet(1) = 7
Packet(2) = 28
Packet(3) = 45
Packet(4) = 48
Packet(5) = 130


For i = 0 To 5
comm1.Output = Packet(i)
Thread.Sleep(5)
Next i
 
A

Armin Zingler

cmdolcet69 said:
Armin before i send the document can you help me out on this for
loop .when i do the following loop and code for the initial loop it
will
[...]


As I see in your other thread, there are already people helping you.


Armin
 
C

cmdolcet69

cmdolcet69 said:
Armin before i send the document can you help me out on this for
loop .when i do the following loop and code for the initial loop it
will
[...]

As I see in your other thread, there are already people helping you.

Armin

No Armin, that was a new way of doing this. I was mentioned that
because the code written for the controller couldn't accept all the
bytes at once so i need to put a for loop with a 5 ms delay...I dont
think this will work however i will e-mail the protocol to you. any
help would be aprrieciated.
 
C

cmdolcet69

cmdolcet69 said:
Armin before i send the document can you help me out on this for
loop .when i do the following loop and code for the initial loop it
will
[...]

As I see in your other thread, there are already people helping you.

Armin

2.1.11 Erase Table Request
0x07
Description:
The "Erase Table Request" provides a means for the master to clear the
calibration table in preparation for a new table upload. The slave
will respond with an ACK packet upon successful completion of the
erase operation.

Erase Packet Format
Byte Offset Byte
0 1 2 3 4 5 6
0 BMS Len Cmd Pass CRC




BMS binary message start byte
Value: 0x2A ('*')
Len command length, number of bytes in message - excludes BMS
Value Range: 0x06
Cmd binary command - erase table
Value: 0x07
Pass factory pass code
Value: 11548
CRC Cyclic Redundancy Check - excludes BMS
Value Range: 0x0000 - 0xFFFF


Both the Pass and CRC take 2 bytes
 
A

Armin Zingler

cmdolcet69 said:
cmdolcet69 said:
Armin before i send the document can you help me out on this for
loop .when i do the following loop and code for the initial loop
it will
[...]

As I see in your other thread, there are already people helping
you.

Armin

2.1.11 Erase Table Request
0x07
Description:
The "Erase Table Request" provides a means for the master to clear
the calibration table in preparation for a new table upload. The
slave will respond with an ACK packet upon successful completion of
the erase operation.

Erase Packet Format
Byte Offset Byte
0 1 2 3 4 5 6
0 BMS Len Cmd Pass CRC




BMS binary message start byte
Value: 0x2A ('*')
Len command length, number of bytes in message - excludes BMS Value
Range: 0x06
Cmd binary command - erase table
Value: 0x07
Pass factory pass code
Value: 11548
CRC Cyclic Redundancy Check - excludes BMS
Value Range: 0x0000 - 0xFFFF


Both the Pass and CRC take 2 bytes


Looks as if you don't need any hex conversions.....



Imports System.Runtime.InteropServices

Public Class Form1
<StructLayout(LayoutKind.Sequential, pack:=1)> _
Class EraseTable
Public BMS As Byte = &H2A
Public len As Byte = 6
Public cmd As Byte = 7
Public Pass As Short = 11548
Public CRC As Short = &H3082

Public Function ToByteArray() As Byte()

Dim result As Byte()
Dim gch As GCHandle

gch = GCHandle.Alloc(Me, GCHandleType.Pinned)

Try
ReDim result(Marshal.SizeOf(Me) - 1)
Marshal.Copy(gch.AddrOfPinnedObject, result, 0,
result.Length)
Finally
gch.Free()
End Try

Return result

End Function

End Class

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Dim out As New EraseTable
Dim bytes As Byte()

bytes = out.ToByteArray

'send byte-array here

End Sub

End Class



This solution puts the data into an object. It's better to handle. Then it's
written into a byte array as a whole, so you don't have to bother about each
single byte anymore. The usage is shown in Form1_Load.

I guess you will have to write different commands to the device, so you can
use this approach for each one.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top