掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
VB.NETのスマートデバイスアプリケーション開発において、シリアル通信を行うには? (ID:84305)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
CEでは、APIの宣言もWindows用とは全然違うんですよね。 これは余談ですが、 EVBなんて構造体も使用できないんですよ。 そのため、String宣言した変数の中に、 構造体と同じバイナリを格納したりだとか。。。 下記は、私がトライしたコードです。 ただ、このコードでは成功しませんでしたので参考までに。。。 'シリアルポートのオープン関数の定義 Private Declare Function CreateFile Lib "Coredll" Alias "CreateFileW" _ (ByVal lpFileName As String, _ ByVal dwDesiredAccess As Integer, _ ByVal dwShareMode As Integer, _ ByVal lpSecurityAttributes As Integer, _ ByVal dwCreationDisposition As Integer, _ ByVal dwFlagsAndAttributes As Integer, _ ByVal hTemplateFile As Integer) As Integer 'シリアルポートのクローズ関数の定義 Private Declare Function CloseHandle Lib "Coredll" Alias "CloseHandle" _ (ByVal hObject As Integer) As Integer 'シリアルポートの設定関数の定義 Private Declare Function SetCommState Lib "Coredll" Alias "SetCommState" _ (ByVal hCommDev As Integer, ByVal lpDCB As DCB) As Integer 'タイムアウトの設定関数の定義 Private Declare Function SetCommTimeouts Lib "Coredll" Alias "SetCommTimeouts" _ (ByVal hFile As Integer, _ ByVal lpCommTimeouts As COMMTIMEOUTS) As Integer 'データの送信関数の定義 Private Declare Function ReadFile Lib "Coredll" Alias "ReadFile" _ (ByVal hFile As Integer, _ ByVal lpBuffer As String, _ ByVal nNumberOfBytesToRead As Integer, _ ByVal lpNumberOfBytesRead As Integer, _ ByVal lpOverlapped As Integer) As Integer 'データの受信関数の定義 Private Declare Function WriteFile Lib "Coredll" Alias "WriteFile" _ (ByVal hFile As Integer, _ ByVal lpBuffer As String, _ ByVal nNumberOfBytesToWrite As Integer, _ ByVal lpNumberOfBytesWritten As Integer, _ ByVal lpOverlapped As Integer) As Integer ' DCB構造体の定義 Private Structure DCB Dim DCBlength As Integer Dim BaudRate As Integer Dim fBitFields As Short Dim wReserved As Short Dim XonLim As Short Dim XoffLim As Short Dim ByteSize As Byte Dim Parity As Byte Dim StopBits As Byte Dim XonChar As Byte Dim XoffChar As Byte Dim ErrorChar As Byte Dim EofChar As Byte Dim EvtChar As Byte End Structure ' COMMTIMEOUTS構造体の定義 Private Structure COMMTIMEOUTS Dim ReadIntervalTimeout As Integer Dim ReadTotalTimeoutMultiplier As Integer Dim ReadTotalTimeoutConstant As Integer Dim WriteTotalTimeoutMultiplier As Integer Dim WriteTotalTimeoutConstant As Integer End Structure Private hComm As Integer Private stDCB As DCB Private timeOut As COMMTIMEOUTS Private dummy As Integer Const GENERIC_READ As Integer = &H80000000 Const GENERIC_WRITE As Integer = &H40000000 Const OPEN_EXISTING As Integer = 3 Const comname As String = "COM1" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click hComm = CreateFile(comname, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0) If hComm = -1 Then MsgBox(comname & "が使えません", vbCritical) End If stDCB.BaudRate = 115200 stDCB.ByteSize = 8 stDCB.fBitFields = &H3001 stDCB.Parity = 0 stDCB.StopBits = 0 dummy = SetCommState(hComm, stDCB) timeOut.ReadIntervalTimeout = 500 timeOut.ReadTotalTimeoutMultiplier = 0 timeOut.ReadTotalTimeoutConstant = 500 timeOut.WriteTotalTimeoutMultiplier = 0 timeOut.WriteTotalTimeoutConstant = 500 dummy = SetCommTimeouts(hComm, timeOut)
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.