| View previous topic :: View next topic |
| Author |
Message |
Fronzel Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Feb 2008 Posts: 1099 Location: Nexons backyard
|
Posted: Tue Dec 02, 2008 11:55 am Post subject: [Question] How to assign an array of Bytes |
|
|
OK this is somewhat of a stupid question as I'm already having a hard time writing it down.
I am currently writing a software that directly controls a USB device. OK to give you something to flame me - i am doing it in VB6 (Doh). Yeah we can spend like 3 hours discussing how noob that is, but if possible lets still get to my question as it is somewhat generic.
I have sniffed the device (Its a disco light kinda keyboard, you can program the lights) and so i know to initialize the device the program sends an AOB to the device. Lets say it sends "02 02 12 0A 00 00 80 02". The real array is a bit longer, but whatever.
My idea was to hardcode these AOBs in my app, but i already fail at assigning these.
For a string its easy, i would do it like "dim myString as String" and then "myString = "lolthis is the string"
For an array of bytes i am having many problems. The main problems is obviously my head as i dont think or dream in bytes... XD
I tried it like
"Dim myBytes() as Byte"
"myBytes = "02 02 12 0A 00 00 80 02"
Obviously this aint work. I am always having a hard time with arrays. I know it is probably working when i do it like
"myBytes(0) = 2"
"myBytes(1) = 2"
"myBytes(2) = 12"
"myBytes(3) = 0A"
Well at least close to that. But it gives me an error for 0A and it would make me crazy to write a line of code for every damn single byte.
I am aware i could use like
Dim myarray() As Byte
myarray = StrConv(mystring, vbFromUniCode)
to convert a string to an array of bytes. But the problem is i have no string, the bytes send are not readable in most cases, its just glibberish, nothing i could save to a text file.
I hope someone understands my problem. After we solved it i am willing to play victim for all VB6 hater flamewars. Actually i would also accept solutions in .net or similar, but no assembler, cobol or random crap please.
_________________
|
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Tue Dec 02, 2008 12:14 pm Post subject: |
|
|
| Code: |
BYTE Array[MAX_PATH] = {0};
Array[0] = *(BYTE*)02;
Array[1] = *(BYTE*)02;
|
second solution
| Code: |
BYTE *String = {02,02,12,0A,00};
//00 gets removed by strlen ;) so total size = 4
int len = strlen(String);
for(i = 0;i < len;i++)
{
Array[i] = *String;
}
|
could go on by u get the idea hopefully ;O
|
|
| Back to top |
|
 |
Fronzel Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Feb 2008 Posts: 1099 Location: Nexons backyard
|
Posted: Tue Dec 02, 2008 1:22 pm Post subject: |
|
|
The second solution helped me a lot, thanks!!!
Gaaah, i spent about 2 hours just to realize the module by Intel i use is bugged terribly, it doesnt read out the device name properly. Damn you Intel!!! lol@me noob fixing Intels bugs... XD
Wah, i approach slowly. First time i ever made an app to communicate with a USB device. I really hope i get this done as the original Software for my Luxeed Keyboard totally stinks! It was programmed by ppl even dumber then me or terribly lazy i think because it totally lacks features.
_________________
|
|
| Back to top |
|
 |
Fronzel Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Feb 2008 Posts: 1099 Location: Nexons backyard
|
Posted: Tue Dec 02, 2008 3:08 pm Post subject: |
|
|
Thanks, i totally love it. But the software STINKS! You cant even make your own animations although it is technically no problem. Its fucking 3rd world software, damn. As much as i like korean software (<3 maple) this is total BS.
However, i am having problems with my write function. I wanna write some bytes to the keyboard and always fail.
| Code: |
Public Sub WriteUSBdevice(BufferPtr&, ByteCount&)
' This subroutine "writes" to an openned USB device
' Copy the user buffer into a local buffer so that a ReportID (=0) may be prepended
' The first byte will contain the ReportID (=0)
Dim ReportBuffer(256) As Byte
If ByteCount& > 254 Then ErrorExit ("Maximum ByteCount for WriteUSBdevice is 254")
Call CopyBuffer(BufferPtr&, AddressFor(ReportBuffer(1)), ByteCount&)
ReportBuffer(0) = 0 ' ReportID
Success = WriteFile(HidHandle&, AddressFor(ReportBuffer(0)), ByteCount& + 1, BytesWritten&, 0)
If (Success = 0) Then ErrorExit ("Could not write an Output Report")
End Sub
|
I'm currently debugging this function, it looks like it should work, but i alsways get "Could not write output report". Well not giving up.
_________________
|
|
| Back to top |
|
 |
SXGuy I post too much
Reputation: 0
Joined: 19 Sep 2006 Posts: 3551
|
Posted: Tue Dec 02, 2008 3:13 pm Post subject: |
|
|
dunno if this helps you
| Quote: | If the function succeeds, the return value is nonzero (TRUE).
If the function fails, or is completing asynchronously, the return value is zero (FALSE). To get extended error information, call the GetLastError function.
Note The GetLastError code ERROR_IO_PENDING is not a failure; it designates the write operation is pending completion asynchronously. For more information, see Remarks.
|
|
|
| Back to top |
|
 |
Fronzel Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Feb 2008 Posts: 1099 Location: Nexons backyard
|
Posted: Tue Dec 02, 2008 4:01 pm Post subject: |
|
|
Well i always get back 0 and nothing is sent to the device. I know for sure as i am sniffing with Advanced USB port monitor. My OpenDevice works, i can see the packages in the monitor. However, the WriteUSBDevice always fails with 0 and i have not been able to find the reason yet. It simply doesnt send anything, absolutely nothing in the monitor.
_________________
|
|
| Back to top |
|
 |
SXGuy I post too much
Reputation: 0
Joined: 19 Sep 2006 Posts: 3551
|
Posted: Tue Dec 02, 2008 4:09 pm Post subject: |
|
|
check this link out, see if anyone had an answer
the guy is writing a driver for some controllers he bought to make a Quiz game.
However, he seems to have the same problem as u
| Quote: | Using these classes, I can successfully read FROM the controller, get the button pressed, and turn that into human-readable information (ie. Player One Pressed Red). But I'm having troubles WRITING to the device. If you read the article I posted above (see http://www.vsj.co.uk/articles/display.asp?id=600) you'll see that to turn the lights on in the device, you need to write to it. I've had a bit of a play around with the 3 modules, trying to get stuff to work, but all I can get is this:
Quote:
---------------------------
Project1
---------------------------
Could not write an Output Report
---------------------------
OK
---------------------------
|
http://www.xtremevbtalk.com/showthread.php?t=275582
|
|
| Back to top |
|
 |
Fronzel Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Feb 2008 Posts: 1099 Location: Nexons backyard
|
Posted: Tue Dec 02, 2008 4:54 pm Post subject: |
|
|
Yeah the post looks promising, but i still don't get how he solved the problem. I tried the read function he posted and then i get "could not write input report".
I'm too tired for today, i will spent more time with it tomorrow. Thanks for the help so far.
_________________
|
|
| Back to top |
|
 |
|