newneel 09-05-2003, 04:07 PM Hi,
I am sending some data to an external USB device. This data contains ID + Parameters. ID should go as a hexa string and paramters should be sent as Hexa value(0x0000) having different data types (like long,byte,integer data type)
So, If i have Data like "dA2302" should be sent as
"dA" = hexa string - String Data Type
23 = 0x23 - cByte(&H23) - Byte Data Type
02 = 0x02 - cInt(&H02) - integer Data type
In USB API i can send this data using any object (could be string,long, or any structure object).
But, My Question is.. Everytime My Data can contain different number of parameters, different data types with different order. So, How can i send these multiple data type values in one object in Visual Basic?
Please Help.. Thanks
SnakeChomp 09-05-2003, 05:15 PM Well, if I understand any of that correctly, 4 bytes will fit into 1 long, as will 2 integers. If you need to send say 4 bytes with one variable, use each byte of a long to send one of your byte values. You need some way for what ever you send this long to be aware that the long really has 4 byte values and is not just one big value though. If you need to send say 2 bytes and int and a long all in one go, make a UDT, and send that to whereever it needs to be. (2 bytes an int and a long will also fit into a double which is 8 bytes( 1+1+2+4 ). I assume structure object means a memory structure aka user defined type. Thats probably your best bet.
newneel 09-05-2003, 05:25 PM Well, if I understand any of that correctly, 4 bytes will fit into 1 long, as will 2 integers. If you need to send say 4 bytes with one variable, use each byte of a long to send one of your byte values. You need some way for what ever you send this long to be aware that the long really has 4 byte values and is not just one big value though. If you need to send say 2 bytes and int and a long all in one go, make a UDT, and send that to whereever it needs to be. (2 bytes an int and a long will also fit into a double which is 8 bytes( 1+1+2+4 ). I assume structure object means a memory structure aka user defined type. Thats probably your best bet.
Thanks for your help but, I guess you haven't understood my actual problem.
I have many Data Commands. Each contains different number of Parameters (These parameters can be of different data types).
Example: pA(string) 23(long) 02(Integer) 345(long)
rB(string) 2(byte) 1(Integer)....................
.............................................
So, I need some kind of Dyanmic Structure which can contain any number of Data with different Data Types.
How can i design this kind of issue?
SnakeChomp 09-05-2003, 05:26 PM Uh make a UDT full of variants? Variants can accept any data type but thy are slow mojos and I never use them.
newneel 09-05-2003, 05:31 PM Uh make a UDT full of variants? Variants can accept any data type but thy are slow mojos and I never use them.
Thanks.. Thats kinda good idea. but, 1 command can contain 3 data, other can have 12 data.
how can i design this?
SnakeChomp 09-05-2003, 08:05 PM You need to design your function that recieves the data to interpret whether it has X commands or Y commands, and if it has X commands, send it to the function designed to accept X commands, same for the Y commands. Or you could make a function accept an array of variants (or a UDT) allowing you to pass any number of any type of data to the function.
Rockoon 09-05-2003, 09:51 PM Uh make a UDT full of variants? Variants can accept any data type but thy are slow mojos and I never use them.
Thanks.. Thats kinda good idea. but, 1 command can contain 3 data, other can have 12 data.
how can i design this?
You can have an array of variants.
the routine that builds the command and data could dimension an array of variants for each 'object' that must be sent to the usb thingy.
Like if you have 1 command and 3 data, thats 4 'objects':
dim myVariant(1 to 4) as variant
myVariant(1) = MyCommand
myVariant(2) = MyData1
etc..
then when you want to output this command, have a routine like this:
public sub SendToUSB(v() as variant)
dim i as long
for i = 1 to ubound(v)
' output v(i) to USB here
select case TypeName(v(i))
case "Byte"
' code for outputing v(i) as byte
case "Integer"
' code for outputting v(i) as 16 bit integer
case "Long"
' code for outputting v(i) as 32 bit integer
case "String"
' code for outputting v(i) as a string
case "Byte()"
' code for outputting v(i) as an array of bytes
case else
msgbox "[SendToUSB] Unhandled type: " & TypeName(v(i))
end
end select
next
end sub
Hope this helps
newneel 09-08-2003, 03:35 PM Hi
What i am trying is:
Option Explicit
Public Type BufferData
DataParm(12) As Variant
End Type
Public bufferObj As BufferData
Suppose i have data of only 4 parameters so,
bufferObj.DataParm(0) = cByte(parm1) ' Byte Type
bufferObj.DataParm(1) = cByte(parm2) ' Byte Type
bufferObj.DataParm(2) = cInt(parm3) ' Integer Type
bufferObj.DataParm(3) = cLng(parm4) ' Long Type
Now, Receiving firmware only expecting this 1+1+2+4 = 8 bytes. but, i am sending "bufferObj" object so, how could we make receiving end ignore array index from 4 to 12.
can we use "Empty" or "Null" or something else...
Thanks
Banjo 09-08-2003, 04:17 PM You might also want to look at the ParamArray keyword.
|