Private Declare Function ScanIF Lib "bvcm.dll" Alias "?BVCM_ScanInterface@@YGKPAI@Z" (ByRef puiNumber As Integer) As Integer Private Declare Function OpenIF Lib "bvcm.dll" Alias "?BVCM_OpenInterface@@YGKIPAPAX@Z" (ByVal uiInterface As Integer, ByRef bvcmHandle As Integer) As Integer Private Declare Function Stby Lib "bvcm.dll" Alias "?BVCM_Standby@@YGKPAXI@Z" (ByVal bvcmHandle As Long, ByVal iTarget As Integer) As Integer Private Declare Function PutDt Lib "bvcm.dll" Alias "?BVCM_PutData@@YGKPAXIPAD@Z" (ByRef bvcmHandle As Long, ByVal iTarget As Integer, ByRef pcBuffer As Byte) As Integer
Dim ifNumber As Integer 'インターフェース数 Dim ifHndl As Long 'インターフェースハンドル Dim stc As Integer 'ステータスコード Dim buff(4) As Byte Dim tmp As Byte
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click stc = ScanIF(ifNumber) 'インターフェースをスキャン TextBox1.Text = ifNumber If (ifNumber > 0) Then stc = OpenIF(0, ifHndl) '最初のインターフェースをオープン If (stc = BVCM_OK) And (ifHndl <> 0) Then TextBox2.Text = "No.1 Inteface is Initialized." stc = Stby(ifHndl, BVCM_BILL) 'ビルバリスタンバイ stc = Stby(ifHndl, BVCM_COIN) 'コインメックスタンバイ
Private Declare Function PutDt Lib "bvcm.dll" Alias "?BVCM_PutData@@YGKPAXIPAD@Z" (ByVal bvcmHandle As Integer, ByVal iTarget As Integer, ByVal cBuffer() As Byte) As Integer
Public Class Form1 Const BVCM_BILL As Integer = 0 Const BVCM_COIN As Integer = 1
Const BVCM_OK As Integer = 0 Const BVCM_INVALID_HANDLE As Integer = 1 Const BVCM_IO_ERROR As Integer = 2 Const BVCM_INVALID_PARAMETER As Integer = 3 Const BVCM_NO_RESPONSE As Integer = 4 Const BVCM_OTHER_ERROR As Integer = 5 Const BVCM_ACK1 As Integer = 6 Const BVCM_ACK2 As Integer = 7 Const BVCM_ACK3 As Integer = 8 Const BVCM_ACK4 As Integer = 9 Const BVCM_NAK As Integer = 10 Const BVCM_BUSY As Integer = 11
Private Declare Function ScanIF Lib "bvcm.dll" Alias "?BVCM_ScanInterface@@YGKPAI@Z" (ByRef puiNumber As Integer) As Integer Private Declare Function OpenIF Lib "bvcm.dll" Alias "?BVCM_OpenInterface@@YGKIPAPAX@Z" (ByVal uiInterface As Integer, ByRef bvcmHandle As Integer) As Integer Private Declare Function Stby Lib "bvcm.dll" Alias "?BVCM_Standby@@YGKPAXI@Z" (ByVal bvcmHandle As Integer, ByVal iTarget As Integer) As Integer Private Declare Function GetAllDt Lib "bvcm.dll" Alias "?BVCM_GetAllData@@YGKPAXIPADI@Z" (ByVal bvcmHandle As Integer, ByVal iTarget As Integer, ByVal pcBuffer As String, ByVal iBufferSize As Integer) As Integer Private Declare Function PutDt Lib "bvcm.dll" Alias "?BVCM_PutData@@YGKPAXIPAD@Z" (ByVal bvcmHandle As Integer, ByVal iTarget As Integer, ByVal pcBuffer() As Byte) As Integer
Dim ifNumber As Integer 'インターフェース数 Dim ifHndl As Integer 'インターフェースハンドル Dim stc As Integer 'ステータスコード Dim buff(4) As Byte Dim tmp As Byte
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click stc = ScanIF(ifNumber) 'インターフェースをスキャン TextBox1.Text = ifNumber TextBox2.Text = stc If (ifNumber > 0) Then stc = OpenIF(0, ifHndl) '最初のインターフェースをオープン TextBox3.Text = ifHndl TextBox4.Text = stc If (stc = BVCM_OK) And (ifHndl <> 0) Then TextBox5.Text = "No.1 Inteface is Initialized." stc = Stby(ifHndl, BVCM_BILL) 'ビルバリスタンバイ TextBox6.Text = stc
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim dtbuf(512) As String stc = GetAllDt(ifHndl, BVCM_BILL, dtbuf(0), 512)
分類:[.NET]
お世話になります。
VBはまったくの初心者です。
紙幣識別機と通信する基盤を制御(シリアル通信?)するプログラムをしています。
付属のAPI関数を使い制御するのですが、データ送信の際、データフレームの作成(キャラクタコード?)を送信するらしいのですが、サンプルコードをもとに自分なりに作成してみましたが、配列データを送信する際
PutDt(ifHndl, BVCM_BILL, buff)
の部分でエラーになってしまいます。
下記のプログラムで間違っているところ、またはこうすべき、という部分をご指摘いただければ幸いです。
Private Declare Function ScanIF Lib "bvcm.dll" Alias "?BVCM_ScanInterface@@YGKPAI@Z" (ByRef puiNumber As Integer) As Integer
Private Declare Function OpenIF Lib "bvcm.dll" Alias "?BVCM_OpenInterface@@YGKIPAPAX@Z" (ByVal uiInterface As Integer, ByRef bvcmHandle As Integer) As Integer
Private Declare Function Stby Lib "bvcm.dll" Alias "?BVCM_Standby@@YGKPAXI@Z" (ByVal bvcmHandle As Long, ByVal iTarget As Integer) As Integer
Private Declare Function PutDt Lib "bvcm.dll" Alias "?BVCM_PutData@@YGKPAXIPAD@Z" (ByRef bvcmHandle As Long, ByVal iTarget As Integer, ByRef pcBuffer As Byte) As Integer
Dim ifNumber As Integer 'インターフェース数
Dim ifHndl As Long 'インターフェースハンドル
Dim stc As Integer 'ステータスコード
Dim buff(4) As Byte
Dim tmp As Byte
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
stc = ScanIF(ifNumber) 'インターフェースをスキャン
TextBox1.Text = ifNumber
If (ifNumber > 0) Then
stc = OpenIF(0, ifHndl) '最初のインターフェースをオープン
If (stc = BVCM_OK) And (ifHndl <> 0) Then
TextBox2.Text = "No.1 Inteface is Initialized."
stc = Stby(ifHndl, BVCM_BILL) 'ビルバリスタンバイ
stc = Stby(ifHndl, BVCM_COIN) 'コインメックスタンバイ
buff(0) = &H3
tmp = buff(0)
buff(1) = &H10
tmp = tmp Xor buff(1)
buff(2) = &H31
tmp = tmp Xor buff(2)
buff(3) = &H0
tmp = tmp Xor buff(3)
buff(4) = tmp
stc = PutDt(ifHndl, BVCM_BILL, buff)
End If
End If
長々とすみません。
以上よろしくお願いいたします