Hi I found this function from the net.
But I have a problem with the reply buffer.
The reply buffer is in ASCII value...but I need is HEX value.
Is there any way that the reply buffer is in hex?
This is my codes that I am sending to device via usbCode:Public Function read_write_string(ByVal devicehandle, ByVal command, ByVal commandlenght) As String Dim inputReportBuffer(100) As Byte unManagedBuffer = Marshal.AllocHGlobal(inputReportBuffer.Length) numberOfBytesRead = 0 numberOfBytesWritten = 0 success = WriteFile _ (devicehandle, _ command, _ commandlenght, _ numberOfBytesWritten, _ IntPtr.Zero) Thread.Sleep(50) success = ReadFile _ (devicehandle, _ unManagedBuffer, _ inputReportBuffer.Length, _ numberOfBytesRead, _ unManagedOverlapped) Marshal.Copy _ (unManagedBuffer, inputReportBuffer, 0, numberOfBytesRead) ReDim Preserve inputReportBuffer(numberOfBytesRead - 1) Dim inputReportBuffer_element As Byte Dim rest As String = "" Dim n As Integer = 0 For Each inputReportBuffer_element In inputReportBuffer If n > commandlenght - 1 Then Select Case inputReportBuffer_element Case Is < &H20 rest = rest & " " Case Is = &H20 rest = rest & " " Case Is > &H20 rest = rest & Chr(Val("&h" & inputReportBuffer_element.ToString("X2"))) End Select End If n += 1 Next Return rest.Trim End Function
My expected answer is:Code:Private Sub AxLaVolpeButton6_ClickEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxLaVolpeButton6.ClickEvent Dim sp_f() As Byte = {&H1B, &H0, &H10, &H53, &H0, &H5, &H0, &HF, &H16, &H12, &HD} TextBox1.Text = read_write_str(deviceHandle, sp_f, sp_f.Length) End Sub
but in my current codes the answer is:Code:1B 10 00 53 00 5C 0F 40 16 13 12 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 44 80 00 00 00 00 00 00 06 24 40 70 00 00 00 00 00 00 18 07 00 00 00 00 00 00 50 00 00 05 FF FF FF 00 B4 00 00 05 FF FF FF 01 18 00 00 05 FF FF FF 01 7C 00 00 05 FF FF FF 01 E0 00 00 05 FF FF FF 02 44 00 00
which is not i need.Code:Uÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ D€ $@p P ÿÿÿ ´ ÿÿÿ ÿÿÿ | ÿÿÿ à ÿÿÿ D
Anyone can help me?




Reply With Quote