Hi, i am new on this page and i have problem with card P8056-1.
I read all instruction and PDF’s which describe how to communicate with card i am using.
I am working with vb.net 2008.
Can somebody help me with string and checksum below why i can not set the second relay ON for example?
Thank you for help awards.
My code looks like:
Public Class Form1
Function CheckSum(ByVal inStr As Char, ByVal relay As Char) As Integer
Dim sum As Integer = (13 + 1 + Asc(inStr) + Asc(relay))
Dim res As Integer = (255 - (sum Mod 256)) + 1
Return res
End Function
Function SetSwitch(ByVal _On As Boolean, ByVal Relay As Char) As String
Dim niz As String
Dim inStr As Char
If _On Then
inStr = "S"
Else
inStr = "C"
End If
niz = "#13" + "1" + inStr + Relay + CType(CheckSum(inStr, Relay), String)
Return niz
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim _ports As New SerialPort
With _ports
.PortName = My.Settings.Com 'COM1
.BaudRate = 2400
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
End With
_ports.Open()
_ports.Write(SetSwitch(True, "2"))
_ports.Close()
End Sub