Jump to content
Xtreme .Net Talk

Tor Henrik Hovi

Members
  • Posts

    9
  • Joined

  • Last visited

Everything posted by Tor Henrik Hovi

  1. Thank you VERY much PlausiblyDamp. I'm not quite sure of what this is doing ,but it seems to do the trick, and I can now stop banging my head against he wall. Really nice of you to take the time to answer my question.
  2. Hi all. I'm comunicating with an USB device and are getting values as bytearrays through it. So I recive a 8 byte long array wich is supposed to be a double variable. How do I convert/typecast those eight bytes into a Double value? I have found some hints on the net about using a fromstream function. But I cant find out how to do it. It is probably the same as reading a double value from a file? If so there should be an easy way of doing this, but I can't find it. Banging my head against the wall on this one, so any input would be appriciated......
  3. OK, first of all thanx for taking the time to look into my problem. :D Let's say did something like this: Dim TempStruct As SendBuffer TempStruct.MagicCookie = &HABBA TempStruct.Command = 1 TempStruct.Length = 8 TempStruct.Data = Nothing I would then somhow like to get the structure as an array of bytes: (171,186,0,1,0,0,0,8) Much as if i pointed an array to the same place as Tempstruct in memory. I'm perhaps not very good at explaining my problem.....
  4. Hi guys! I have a structure like this: Public Structure SendBuffer Public MagicCookie As Short Public Command As Short Public Length As Integer Public Data As Byte() End Structure and I would like to convert it to a 1-dimensional array of bytes. is there a fancy and swift way of doing this or do I have to do it manually?
  5. OK guys! Thanx allot for your answers, butI could not make it work. So to test this I created a new form, slapped on a PictureBox and wrote this code: Dim Buffer As Byte() Dim VideoBitmap As Bitmap Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim x, y, c As Integer ReDim Buffer(480000) c = 1 For y = 1 To 600 For x = 1 To 800 Buffer(c) = CByte(255 / 800 * x) c = c + 1 Next Next End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click Dim BufferPointer As IntPtr Dim Stride As Integer BufferPointer = Nothing 'How do I get a pointer ro an Array? Stride = 800 * 8 'What is Stride?? VideoBitmap = New Bitmap(800, 600, Stride, Drawing.Imaging.PixelFormat.Format8bppIndexed, BufferPointer) VideoBitmap.MakeTransparent() PictureBox1.Refresh() End Sub Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint e.Graphics.DrawImage(VideoBitmap, 0, 0, PictureBox.Width, PictureBox.Height) End Sub Now I've got a few moe questions; How do I get a pointer to my Array (Buffer)? What is Stride?? (The memory size of a row in the stream of pixel data???) (I just took the number of pixels in a row and multiplied with eight since they are byte?? Probably wrong.) Please take the time to answer my stupid questions
  6. I recive an array of bytes from a USB 2.0 device. The array is a 800x600 grayscale picture. The array is named Buffer I use this code to present the image: Private Sub BuildImage() Dim Gray As Byte Dim c, x, y As Integer c=0 For y = 0 To 599 For x = 0 To 799 Gray = Buffer© VideoBitmap.SetPixel(x, y, Color.FromArgb(Gray, Gray, Gray)) c = c + 1 Next Next End Sub I takes about .5 sec to complete this on my PC. Wich gives me a frame rate of 2 pictures per sec. I'm looking for a faster way of displaying the picture. Probably setpixel is not the fastest way? As you see I have to make a RGB code for the grayscale Color.FromArgb(Gray, Gray, Gray). Is there some way of inserting the grayscale values directly? Thanx in advance :D
  7. Your declaration did not compile without the "<" so i Included those but unfortunately I still got the same ERROR message when trying the Marshal.SizeOf(): "Type WD_USB_SCAN_DEVICES can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed." Structure WD_USB_SCAN_DEVICES Dim searchId As WD_USB_ID Dim dwDevices As Integer <MarshalAs(UnmanagedType.LPArray, SizeConst:=29)> Dim uniqueId() As Integer <MarshalAs(UnmanagedType.LPArray, SizeConst:=29)> Dim deviceGeneralInfo() As WD_USB_DEVICE_GENERAL_INFO Dim dwStatus As Integer End Structure Function WD_UsbScanDevice(ByRef hWD As Integer) As WD_USB_SCAN_DEVICES Dim Scan As WD_USB_SCAN_DEVICES Dim memSize As Integer = Marshal.SizeOf(Scan) Dim lpScan As IntPtr = Marshal.AllocHGlobal(memSize) Dim lpScan2 As Integer = lpScan.ToInt64() DeviceIoControl(hWD, IOCTL_WD_USB_SCAN_DEVICES, lpScan2, memSize, 0, 0, WinDriverGlobalDW, 0) Return Scan End Function While searching for clues on the net I stumbeled over this article that I belive to be written by you: http://www.elitevb.com/content/print.aspx?contentid=75 This article mentiones an update about the very core of my problem. If you have written this update, would you give me an URL to where it is? Do you have any other ideas of what I'm doing wrong?
  8. Thank you for taking the time to answer my post. Your suggestion of using the Marshall Class is definately a step in the right direction.:) My proggie now compiles but gives me an error message: "Type WD_USB_SCAN_DEVICES can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed." :confused: To explain the Scan Object/Structure I have extracted a bit of my code: Structure WD_USB_ID Dim dwVendorId As Integer Dim dwProductId As Integer End Structure Structure WD_USB_HUB_GENERAL_INFO Dim fBusPowered As Integer Dim dwPorts As Integer Dim dwCharacteristics As Integer Dim dwPowerOnToPowerGood As Integer Dim dwHubControlCurrent As Integer End Structure Structure WD_USB_DEVICE_GENERAL_INFO Dim deviceId As WD_USB_ID Dim dwHubNum As Integer Dim dwPortNum As Integer Dim fHub As Integer Dim fFullSpeed As Integer Dim dwConfigurationsNum As Integer Dim deviceAddress As Integer Dim hubInfo As WD_USB_HUB_GENERAL_INFO Dim deviceClass As Integer Dim deviceSubClass As Integer Dim dwInterfaceNum As Integer End Structure Structure WD_USB_SCAN_DEVICES Dim searchId As WD_USB_ID Dim dwDevices As Integer <VBFixedArray(29)> Dim uniqueId() As Integer <VBFixedArray(29)> Dim deviceGeneralInfo() As WD_USB_DEVICE_GENERAL_INFO Dim dwStatus As Integer 'UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Public Sub Initialize() ReDim uniqueId(29) ReDim deviceGeneralInfo(29) End Sub End Structure Function WD_UsbScanDevice(ByRef hWD As Integer) As WD_USB_SCAN_DEVICES Dim Scan As WD_USB_SCAN_DEVICES Scan.Initialize() Dim memSize As Integer = System.Runtime.InteropServices.Marshal.SizeOf(Scan) Dim lpScan As IntPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(memSize) Dim lpScan2 As Integer = lpScan.ToInt64() DeviceIoControl(hWD, IOCTL_WD_USB_SCAN_DEVICES, lpScan2, memSize, 0, 0, WinDriverGlobalDW, 0) Return Scan End Function
  9. :confused: I'm trying to convert a VB6 example to VB.NET. The example uses the DeviceIoControl function: DeviceIoControl(hWD, IOCTL_WD_USB_SCAN_DEVICES, lpScan, LenB(lpScan), 0, 0, WinDriverGlobalDW, 0) lpscan is a pointer to the Scan object. My problem is i do not know how to make a pointer to a object. Is it possible in VB.NET? something like lpScan = pointer(Scan) ?????
×
×
  • Create New...