Hallo,
I am trying to send a Byte thru the serial port to the K8056 Card. In my efforts I was partly successful. With my code I can send only decimal numbers a bow 44. The card ignores everything lower then 45 decimal. To get my program work properly, I have to be able to send all numbers from 1 to 255. Can you help me please? Here is the code that I use to send data to the Card:
Public Class Form1
Dim Port As Integer
Dim Portteller As Integer
Dim Portname As String
Private Sub CBPORT_SelectedIndexChanged(
ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles CBPORT.SelectedIndexChanged
SerialPort1.Close()
SerialPort1.PortName = "COM" & CBPORT.Text
On Error Resume Next
SerialPort1.BaudRate = 2400
SerialPort1.StopBits = 1
SerialPort1.DataBits = 8
SerialPort1.Open()
If SerialPort1.IsOpen Then
CBPORT.BackColor = Color.Green
Else
CBPORT.BackColor = Color.Red
End If
End Sub
Private Sub ButSet_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButSet.Click
SendCommand()
End Sub
Sub SendCommand()
Dim Buf As String
Dim Cardnr As Integer ' Cardnumber
Dim ByteToWrite As String ' Relais number
Dim Chksom As Integer ' Checksom
Dim I As Integer
Cardnr = Int(TBAdres.Text)
ByteToWrite = TBByte.Text
I = CInt(ByteToWrite)
Chksom = 256 - ((13 + Cardnr + Asc("B") + I) Mod 256)
Buf = Chr(13) & Chr(Cardnr) & "B" & Chr(I) & Chr(Chksom)
If SerialPort1.IsOpen = True Then SerialPort1.Write(Buf)
End Sub
End Class
Best regards,
Igor Juricic