|
-
Aug 9th, 2005, 07:11 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Receiving Bytes Problem(How to Receive??)
the current module i am doing, receives some data bytes from winsock(for testing purpose temporarily in com port). from my previous experience, i would collect the data bytes received from port, write it to a file and read the file to get the appropriate fields.
the reason why i write to file is., the data packet which i receive will be like this ., for ex.,
id int,
deviceid int,
customername char[17],
amount float.
and i receive it as packet(collection of all these). i write the packet to the file and open the file and i will store it in the type which is in the exact format in which the packet has been sent. like this.,
Type info
ID as Integer,
DeviceID as Integer,
Cust_Name as String * 17,
Amount as Double
end Type
and use this as .,
dim Config as info
Open SavedFile For Binary Access Read As #fileno
Get #fileno, 1, Config
'SavedFile(variable) has the name of the file in which i stored the bytes.
now i get the values in the file in the variable Config. I get the data like this. I wanted to know is there any way around to skip the file process.
"In Short, I wanted to read the bytes received from port(either from winsock or com) and store it in VB's variables for my process"
--Kishore...
-
Aug 9th, 2005, 08:58 AM
#2
Frenzied Member
Re: Receiving Bytes Problem(How to Receive??)
It looks like one end point of the connection is written in C. I have done quite a few VB-to-C sockets apps. Here is how I do it.
Like you, I create a UDT that matches my C struct. I use the CopyMemory API to copy the UDT to a byte array before sending it. In the Data_Arrival code, I read the data into a byte array and use CopyMemory to copy the data to the UDT.
Are the client and server both running on Windows platforms? If not, you may have issues with big-endian vs little-endian and with your floats/doubles. There are APIs to deal with the endian issues. As for the floats/doubles, I have never had a need use them, but most people that I have talked to have said that the easiest way to pass them between different platforms (where they may be stored differently) is to convert them to/from strings and pass the strings.
Email me if you would like an example app that demonstrates all of the above (except the floats).
-
Aug 9th, 2005, 11:44 PM
#3
Thread Starter
Addicted Member
Re: Receiving Bytes Problem(How to Receive??)
hi,
i would certainly like to have the sample. and i receive data from a device. so it is embedded C. (Note : the data contains definite number of bytes for each fields)
I would also like to know, how the data is passed generally in winsock, or com from devices., if it is not string.
--Kishore...
-
Nov 8th, 2005, 06:03 AM
#4
Thread Starter
Addicted Member
Re: Receiving Bytes Problem(How to Receive??)
hi CCoder,
"CopyMemory" was a very good/useful solution. Thanks a lot. and sorry for very late acknowledgement.
--Kishore...
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
|