Hi,
I 've just finished my K8056 Velleman kit. I Try to write a program in VB 2008 but I don’t really know how to use VB.
here my program, I just want to set the relay n°1 with a button
Imports System
Imports System.IO.Ports
Public Class Form1
Dim Port As SerialPort = New SerialPort("COM1", 2400, Parity.None, 8, StopBits.One)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Essai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Essai.Click
Port.Open()
Port.Write(Chr(13) & "1" & "S" & "1" & "88")
Port.Close()
End Sub
End Class
How can I calculate the Checksum, is it really necessary?
what is the code to configurate the serial port, is it correct?
ok thanks for your answer but i think the problem is in the parameter that i try to send to the card: CHR$13 (is it 0x13 in hexa?), adress 1 (in hex?), S (in ASCII code?), adress 1 (in ASCII code?):
00010011 : CHR$13 (ASCII)? or 0x13 in hex
00000001 : adresse of the card --> 1
01010011 : instruction ‘S’ in ASCII
00011001 : nb of the relais --> 1 or 0x31 in hex
10000000 : addition
01111111 : 2-complement
00000001+: add one
10000000 : checksum=128??? is CORRECT??
Nothing happen on the card but with the demo program, it’s working…
fred
Just to say that I found the error: Here my program in VB2008 just to communicate with the K8056 board and set the relay one. I can send you the code when i will finish it if you want.
[code]
Imports System
Imports System.IO.Ports
Public Class Form1
Dim Port As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort(“COM1”, 2400, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Port.Close()
End Sub
Private Sub Essai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Essai.Click
Dim messagestring As String
messagestring = Chr(13) & Chr(1) & "S" & Chr(49) & Chr(110) 'number in decimal
messagestring = messagestring & messagestring
messagestring = messagestring & messagestring
Port.Open()
Port.Write(messagestring)
Port.Close()
End Sub
End Class[/code]
Thanks for your help…
see u
PS: for the checksum in hexa: [FF-(0D+01+53+31)]+1 = 6E or 110 in decimal
I found out that the formula of the demo program may get a wrong checksum of 256 while using the command “Send a Byte” with the value 176.
That’s why I came to the following solution to get the checksum for the K8056 in VB6:
Public Function funcChecksum(bytAddress As Byte, strCommand As String, bytValue As Byte) As String