Click here to Skip to main content
15,887,350 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: How to read a text file containing Arabic chars in VB.Net 2005? Pin
Eddy Vluggen29-Oct-13 8:29
professionalEddy Vluggen29-Oct-13 8:29 
QuestionError with Assembly reference Pin
indian14328-Oct-13 7:43
indian14328-Oct-13 7:43 
AnswerRe: Error with Assembly reference Pin
Eddy Vluggen29-Oct-13 8:23
professionalEddy Vluggen29-Oct-13 8:23 
GeneralRe: Error with Assembly reference Pin
indian14329-Oct-13 13:21
indian14329-Oct-13 13:21 
GeneralRe: Error with Assembly reference Pin
Eddy Vluggen30-Oct-13 11:02
professionalEddy Vluggen30-Oct-13 11:02 
GeneralRe: Error with Assembly reference Pin
indian14331-Oct-13 6:48
indian14331-Oct-13 6:48 
GeneralRe: Error with Assembly reference Pin
Eddy Vluggen31-Oct-13 9:34
professionalEddy Vluggen31-Oct-13 9:34 
Question[VB.NET 2008] How to use DeviceIoControl function? Pin
steve_949661328-Oct-13 3:06
professionalsteve_949661328-Oct-13 3:06 
Hello everybody,
I need to use the function DeviceIoControl to monitor the status of a COM port (RS485) but I don't know how to do.
I have declared the functions:
VB
<DllImport("CoreDll.dll")> _
Shared Function DeviceIoControl(ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, _
                       ByVal lpInBuffer As String, ByVal nInBufferSize As Integer, _
                       ByVal lpOutBuffer() As Byte, ByVal nOutBufferSize As Integer, _
                       ByRef lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As Integer
End Function

Private Declare Function CreateFile Lib "coredll.dll" _
                       (ByVal lpFileName As String, ByVal dwDesiredAccess As Int32, _
                        ByVal dwShareMode As Int32, ByVal lpSecurityAttributes As IntPtr, _
                        ByVal dwCreationDisposition As Int32, ByVal dwFlagsAndAttributes As Int32, _
                        ByVal hTemplateFile As IntPtr) As IntPtr

Declare Function CloseHandle Lib "coredll.dll" (ByVal hObject As IntPtr) As Boolean


I use CreateFile (it works) to get an handle to the COM port and I pass it to DeviceIoControl:
VB
Const FILE_SHARE_READ As Integer = &H1
Const FILE_SHARE_WRITE As Integer = &H2
Const GENERIC_READ As Integer = &H80000000
Const GENERIC_WRITE As Integer = &H40000000

Dim portPtr As IntPtr
Dim ris As Boolean
Dim InBuffer As String
Dim OutBuffer(100) As Byte
Dim BytesReturned, Overlapped As Int32

portPtr = CreateFile(com.PortName & ":", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)

ris = DeviceIoControl(portPtr.ToInt32, IOCTL_SERIAL_GET_COMMSTATUS, InBuffer, InBuffer.Length, OutBuffer, OutBuffer.Count, BytesReturned, Overlapped)

CloseHandle(portPtr)


I don't know what must be the value of IOCTL_SERIAL_GET_COMMSTATUS and I'm not sure that I'm using DeviceIoControl in the right way.
I have found some information only in C++ like:

C++
#define IOCTL_SERIAL_GET_COMMSTATUS     CTL_CODE(FILE_DEVICE_SERIAL_PORT, 27, METHOD_BUFFERED, FILE_ANY_ACCESS)

but how can I use it in VB.NET?

And then, DeviceIoControl should fill a SERIAL_STATUS structure:
C++
typedef struct _SERIAL_STATUS {
  ULONG   Errors;
  ULONG   HoldReasons;
  ULONG   AmountInInQueue;
  ULONG   AmountInOutQueue;
  BOOLEAN EofReceived;
  BOOLEAN WaitForImmediate;
} SERIAL_STATUS, *PSERIAL_STATUS;

but a structure is not just a byte array as in my declaration of DeviceIoControl (that I have found googling around).

Can somebody help me?

Thanks in advance.
AnswerRe: [VB.NET 2008] How to use DeviceIoControl function? Pin
David Knechtges28-Oct-13 3:14
David Knechtges28-Oct-13 3:14 
GeneralRe: [VB.NET 2008] How to use DeviceIoControl function? Pin
steve_949661328-Oct-13 3:47
professionalsteve_949661328-Oct-13 3:47 
GeneralRe: [VB.NET 2008] How to use DeviceIoControl function? Pin
David Knechtges29-Oct-13 3:13
David Knechtges29-Oct-13 3:13 
GeneralRe: [VB.NET 2008] How to use DeviceIoControl function? Pin
steve_949661329-Oct-13 4:55
professionalsteve_949661329-Oct-13 4:55 
Questiontimer events, vb.net Pin
srinivasankrishnaa24-Oct-13 6:08
srinivasankrishnaa24-Oct-13 6:08 
AnswerRe: timer events, vb.net Pin
Eddy Vluggen24-Oct-13 8:09
professionalEddy Vluggen24-Oct-13 8:09 
GeneralRe: timer events, vb.net Pin
srinivasankrishnaa27-Oct-13 3:06
srinivasankrishnaa27-Oct-13 3:06 
GeneralRe: timer events, vb.net Pin
Dave Kreskowiak27-Oct-13 5:34
mveDave Kreskowiak27-Oct-13 5:34 
GeneralRe: timer events, vb.net Pin
srinivasankrishnaa29-Oct-13 7:05
srinivasankrishnaa29-Oct-13 7:05 
GeneralRe: timer events, vb.net Pin
Dave Kreskowiak29-Oct-13 10:17
mveDave Kreskowiak29-Oct-13 10:17 
GeneralRe: timer events, vb.net Pin
srinivasankrishnaa30-Oct-13 7:04
srinivasankrishnaa30-Oct-13 7:04 
QuestionPlacing a number in registry,vb.net Pin
srinivasankrishnaa22-Oct-13 0:46
srinivasankrishnaa22-Oct-13 0:46 
AnswerRe: Placing a number in registry,vb.net Pin
Richard Deeming22-Oct-13 1:16
mveRichard Deeming22-Oct-13 1:16 
AnswerRe: Placing a number in registry,vb.net Pin
Marco Bertschi22-Oct-13 1:17
protectorMarco Bertschi22-Oct-13 1:17 
QuestionFileWtacher stop working after 300 Pin
byka21-Oct-13 3:02
byka21-Oct-13 3:02 
AnswerRe: FileWtacher stop working after 300 Pin
Abhinav S21-Oct-13 3:08
Abhinav S21-Oct-13 3:08 
AnswerRe: FileWtacher stop working after 300 Pin
Kornfeld Eliyahu Peter21-Oct-13 3:53
professionalKornfeld Eliyahu Peter21-Oct-13 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.